Standardise semicolons
This commit is contained in:
		
							parent
							
								
									1db4973aee
								
							
						
					
					
						commit
						ddd7ccfb01
					
				
					 11 changed files with 64 additions and 115 deletions
				
			
		|  | @ -1,14 +1,14 @@ | ||||||
| import { PrismaClient } from '@prisma/client' | import { PrismaClient } from '@prisma/client'; | ||||||
| 
 | 
 | ||||||
| let prisma: PrismaClient | let prisma: PrismaClient; | ||||||
| 
 | 
 | ||||||
| if (process.env.NODE_ENV === 'production') { | if (process.env.NODE_ENV === 'production') { | ||||||
|   prisma = new PrismaClient() |   prisma = new PrismaClient(); | ||||||
| } else { | } else { | ||||||
|   if (!global.prisma) { |   if (!global.prisma) { | ||||||
|     global.prisma = new PrismaClient() |     global.prisma = new PrismaClient(); | ||||||
|   } |   } | ||||||
|   prisma = global.prisma |   prisma = global.prisma; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default prisma | export default prisma; | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import Head from 'next/head' | import Head from 'next/head'; | ||||||
| import Link from 'next/link' | import Link from 'next/link'; | ||||||
| import prisma from '../lib/prisma' | import prisma from '../lib/prisma'; | ||||||
| 
 | 
 | ||||||
| export default function User(props) { | export default function User(props) { | ||||||
|     const eventTypes = props.user.eventTypes.map(type => |     const eventTypes = props.user.eventTypes.map(type => | ||||||
|  |  | ||||||
|  | @ -1,11 +1,11 @@ | ||||||
| import {useEffect, useState} from 'react' | import {useEffect, useState} from 'react'; | ||||||
| import Head from 'next/head' | import Head from 'next/head'; | ||||||
| import Link from 'next/link' | import Link from 'next/link'; | ||||||
| import prisma from '../../lib/prisma' | import prisma from '../../lib/prisma'; | ||||||
| import { useRouter } from 'next/router' | import { useRouter } from 'next/router'; | ||||||
| const dayjs = require('dayjs') | const dayjs = require('dayjs'); | ||||||
| const isSameOrBefore = require('dayjs/plugin/isSameOrBefore') | const isSameOrBefore = require('dayjs/plugin/isSameOrBefore'); | ||||||
| dayjs.extend(isSameOrBefore) | dayjs.extend(isSameOrBefore); | ||||||
| 
 | 
 | ||||||
| export default function Type(props) { | export default function Type(props) { | ||||||
|     // Initialise state
 |     // Initialise state
 | ||||||
|  | @ -15,23 +15,23 @@ export default function Type(props) { | ||||||
|     const [busy, setBusy] = useState([]); |     const [busy, setBusy] = useState([]); | ||||||
| 
 | 
 | ||||||
|     // Get router variables
 |     // Get router variables
 | ||||||
|     const router = useRouter() |     const router = useRouter(); | ||||||
|     const { user } = router.query |     const { user } = router.query; | ||||||
| 
 | 
 | ||||||
|     // Handle month changes
 |     // Handle month changes
 | ||||||
|     const incrementMonth = () => { |     const incrementMonth = () => { | ||||||
|         setSelectedMonth(selectedMonth + 1) |         setSelectedMonth(selectedMonth + 1); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const decrementMonth = () => { |     const decrementMonth = () => { | ||||||
|         setSelectedMonth(selectedMonth - 1) |         setSelectedMonth(selectedMonth - 1); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Set up calendar
 |     // Set up calendar
 | ||||||
|     var daysInMonth = dayjs().month(selectedMonth).daysInMonth() |     var daysInMonth = dayjs().month(selectedMonth).daysInMonth(); | ||||||
|     var days = [] |     var days = []; | ||||||
|     for (let i = 1; i <= daysInMonth; i++) { |     for (let i = 1; i <= daysInMonth; i++) { | ||||||
|         days.push(i) |         days.push(i); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const calendar = days.map((day) => |     const calendar = days.map((day) => | ||||||
|  | @ -43,14 +43,14 @@ export default function Type(props) { | ||||||
|     // Handle date change
 |     // Handle date change
 | ||||||
|     useEffect(async () => { |     useEffect(async () => { | ||||||
|         setLoading(true); |         setLoading(true); | ||||||
|         const res = await fetch('/api/availability/' + user + '?date=' + dayjs(selectedDate).format("YYYY-MM-DD")) |         const res = await fetch('/api/availability/' + user + '?date=' + dayjs(selectedDate).format("YYYY-MM-DD")); | ||||||
|         const data = await res.json() |         const data = await res.json(); | ||||||
|         setBusy(data.primary.busy) |         setBusy(data.primary.busy); | ||||||
|         setLoading(false) |         setLoading(false); | ||||||
|     }, [selectedDate]); |     }, [selectedDate]); | ||||||
| 
 | 
 | ||||||
|     // Set up timeslots
 |     // Set up timeslots
 | ||||||
|     let times = [] |     let times = []; | ||||||
| 
 | 
 | ||||||
|     // If we're looking at availability throughout the current date, work out the current number of minutes elapsed throughout the day
 |     // If we're looking at availability throughout the current date, work out the current number of minutes elapsed throughout the day
 | ||||||
|     if (selectedDate == dayjs().format("YYYY-MM-DD")) { |     if (selectedDate == dayjs().format("YYYY-MM-DD")) { | ||||||
|  | @ -61,14 +61,14 @@ export default function Type(props) { | ||||||
|      |      | ||||||
|     // Until day end, push new times every x minutes
 |     // Until day end, push new times every x minutes
 | ||||||
|     for (;i < 1440; i += parseInt(props.eventType.length)) { |     for (;i < 1440; i += parseInt(props.eventType.length)) { | ||||||
|         times.push(dayjs(selectedDate).hour(Math.floor(i / 60)).minute(i % 60).startOf(props.eventType.length, 'minute').add(props.eventType.length, 'minute').format("YYYY-MM-DD HH:mm:ss")) |         times.push(dayjs(selectedDate).hour(Math.floor(i / 60)).minute(i % 60).startOf(props.eventType.length, 'minute').add(props.eventType.length, 'minute').format("YYYY-MM-DD HH:mm:ss")); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Check for conflicts
 |     // Check for conflicts
 | ||||||
|     times.forEach(time => { |     times.forEach(time => { | ||||||
|         busy.forEach(busyTime => { |         busy.forEach(busyTime => { | ||||||
|             let startTime = dayjs(busyTime.start) |             let startTime = dayjs(busyTime.start); | ||||||
|             let endTime = dayjs(busyTime.end) |             let endTime = dayjs(busyTime.end); | ||||||
| 
 | 
 | ||||||
|             // Check if start times are the same
 |             // Check if start times are the same
 | ||||||
|             if (dayjs(time).format('HH:mm') == startTime.format('HH:mm')) { |             if (dayjs(time).format('HH:mm') == startTime.format('HH:mm')) { | ||||||
|  | @ -143,7 +143,7 @@ export default function Type(props) { | ||||||
|                 </div> |                 </div> | ||||||
|             </main> |             </main> | ||||||
|         </div> |         </div> | ||||||
|     ) |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getServerSideProps(context) { | export async function getServerSideProps(context) { | ||||||
|  |  | ||||||
|  | @ -1,15 +1,15 @@ | ||||||
| import Head from 'next/head' | import Head from 'next/head'; | ||||||
| import Link from 'next/link' | import Link from 'next/link'; | ||||||
| import { useRouter } from 'next/router' | import { useRouter } from 'next/router'; | ||||||
| import prisma from '../../lib/prisma' | import prisma from '../../lib/prisma'; | ||||||
| const dayjs = require('dayjs') | const dayjs = require('dayjs'); | ||||||
| 
 | 
 | ||||||
| export default function Book(props) { | export default function Book(props) { | ||||||
|     const router = useRouter() |     const router = useRouter(); | ||||||
|     const { date, user } = router.query |     const { date, user } = router.query; | ||||||
| 
 | 
 | ||||||
|     const bookingHandler = event => { |     const bookingHandler = event => { | ||||||
|         event.preventDefault() |         event.preventDefault(); | ||||||
|         const res = fetch( |         const res = fetch( | ||||||
|             '/api/book/' + user, |             '/api/book/' + user, | ||||||
|             { |             { | ||||||
|  | @ -25,8 +25,8 @@ export default function Book(props) { | ||||||
|                 }, |                 }, | ||||||
|                 method: 'POST' |                 method: 'POST' | ||||||
|             } |             } | ||||||
|         ) |         ); | ||||||
|         router.push("/success?date=" + date + "&type=" + props.eventType.id + "&user=" + props.user.username) |         router.push("/success?date=" + date + "&type=" + props.eventType.id + "&user=" + props.user.username); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return ( |     return ( | ||||||
|  |  | ||||||
|  | @ -1,12 +1,12 @@ | ||||||
| import '../styles/globals.css' | import '../styles/globals.css'; | ||||||
| import { Provider } from 'next-auth/client' | import { Provider } from 'next-auth/client'; | ||||||
| 
 | 
 | ||||||
| function MyApp({ Component, pageProps }) { | function MyApp({ Component, pageProps }) { | ||||||
|   return ( |   return ( | ||||||
|       <Provider session={pageProps.session}> |       <Provider session={pageProps.session}> | ||||||
|         <Component {...pageProps} /> |         <Component {...pageProps} /> | ||||||
|       </Provider> |       </Provider> | ||||||
|   ) |   ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default MyApp | export default MyApp; | ||||||
|  |  | ||||||
|  | @ -1,11 +1,11 @@ | ||||||
| import type { NextApiRequest, NextApiResponse } from 'next' | import type { NextApiRequest, NextApiResponse } from 'next'; | ||||||
| import prisma from '../../../lib/prisma' | import prisma from '../../../lib/prisma'; | ||||||
| const {google} = require('googleapis'); | const {google} = require('googleapis'); | ||||||
| 
 | 
 | ||||||
| const credentials = process.env.GOOGLE_API_CREDENTIALS; | const credentials = process.env.GOOGLE_API_CREDENTIALS; | ||||||
| 
 | 
 | ||||||
| export default async function handler(req: NextApiRequest, res: NextApiResponse) { | export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||||||
|     const { user } = req.query |     const { user } = req.query; | ||||||
| 
 | 
 | ||||||
|     const currentUser = await prisma.user.findFirst({ |     const currentUser = await prisma.user.findFirst({ | ||||||
|         where: { |         where: { | ||||||
|  | @ -16,14 +16,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     authorise(bookEvent) |     authorise(bookEvent); | ||||||
| 
 | 
 | ||||||
|     // Set up Google API credentials
 |     // Set up Google API credentials
 | ||||||
|     function authorise(callback) { |     function authorise(callback) { | ||||||
|         const {client_secret, client_id, redirect_uris} = JSON.parse(credentials).web; |         const {client_secret, client_id, redirect_uris} = JSON.parse(credentials).web; | ||||||
|         const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]); |         const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]); | ||||||
|         oAuth2Client.setCredentials(currentUser.credentials[0].key); |         oAuth2Client.setCredentials(currentUser.credentials[0].key); | ||||||
|         callback(oAuth2Client) |         callback(oAuth2Client); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function bookEvent(auth) { |     function bookEvent(auth) { | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import type { NextApiRequest, NextApiResponse } from 'next' | import type { NextApiRequest, NextApiResponse } from 'next'; | ||||||
| import { getSession } from 'next-auth/client'; | import { getSession } from 'next-auth/client'; | ||||||
| import prisma from '../../../../lib/prisma'; | import prisma from '../../../../lib/prisma'; | ||||||
| const {google} = require('googleapis'); | const {google} = require('googleapis'); | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import type { NextApiRequest, NextApiResponse } from 'next' | import type { NextApiRequest, NextApiResponse } from 'next'; | ||||||
| import { getSession } from 'next-auth/client'; | import { getSession } from 'next-auth/client'; | ||||||
| import prisma from '../../../../lib/prisma'; | import prisma from '../../../../lib/prisma'; | ||||||
| const {google} = require('googleapis'); | const {google} = require('googleapis'); | ||||||
|  | @ -6,7 +6,7 @@ const {google} = require('googleapis'); | ||||||
| const credentials = process.env.GOOGLE_API_CREDENTIALS; | const credentials = process.env.GOOGLE_API_CREDENTIALS; | ||||||
| 
 | 
 | ||||||
| export default async function handler(req: NextApiRequest, res: NextApiResponse) { | export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||||||
|     const { code } = req.query |     const { code } = req.query; | ||||||
| 
 | 
 | ||||||
|     // Check that user is authenticated
 |     // Check that user is authenticated
 | ||||||
|     const session = await getSession({req: req}); |     const session = await getSession({req: req}); | ||||||
|  |  | ||||||
|  | @ -3,8 +3,8 @@ import Head from 'next/head'; | ||||||
| import Link from 'next/link'; | import Link from 'next/link'; | ||||||
| 
 | 
 | ||||||
| export default function Error() { | export default function Error() { | ||||||
|     const router = useRouter() |     const router = useRouter(); | ||||||
|     const { error } = router.query |     const { error } = router.query; | ||||||
| 
 | 
 | ||||||
|     return ( |     return ( | ||||||
|         <div className="fixed z-10 inset-0 overflow-y-auto" aria-labelledby="modal-title" role="dialog" aria-modal="true"> |         <div className="fixed z-10 inset-0 overflow-y-auto" aria-labelledby="modal-title" role="dialog" aria-modal="true"> | ||||||
|  |  | ||||||
|  | @ -1,12 +1,12 @@ | ||||||
| import Head from 'next/head' | import Head from 'next/head'; | ||||||
| import Link from 'next/link' | import Link from 'next/link'; | ||||||
| import prisma from '../lib/prisma' | import prisma from '../lib/prisma'; | ||||||
| import { useRouter } from 'next/router' | import { useRouter } from 'next/router'; | ||||||
| const dayjs = require('dayjs') | const dayjs = require('dayjs'); | ||||||
| 
 | 
 | ||||||
| export default function Success(props) { | export default function Success(props) { | ||||||
|     const router = useRouter() |     const router = useRouter(); | ||||||
|     const { date } = router.query |     const { date } = router.query; | ||||||
| 
 | 
 | ||||||
|     return( |     return( | ||||||
|         <div> |         <div> | ||||||
|  |  | ||||||
|  | @ -1,51 +0,0 @@ | ||||||
| import { useRef } from 'react'; |  | ||||||
| 
 |  | ||||||
| export default function add() { |  | ||||||
|     const usernameInputRef = useRef(); |  | ||||||
|     const emailInputRef = useRef(); |  | ||||||
|     const passwordInputRef = useRef(); |  | ||||||
| 
 |  | ||||||
|     async function createUser(username, email, password) { |  | ||||||
|         const response = await fetch('/api/auth/signup', { |  | ||||||
|             method: 'POST', |  | ||||||
|             body: JSON.stringify({username, email, password}), |  | ||||||
|             headers: { |  | ||||||
|                 'Content-Type': 'application/json' |  | ||||||
|             } |  | ||||||
|         }); |  | ||||||
| 
 |  | ||||||
|         const data = await response.json(); |  | ||||||
| 
 |  | ||||||
|         if (!response.ok) { |  | ||||||
|             throw new Error(data.message || 'Something went wrong.'); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return data; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     async function submitHandler(event) { |  | ||||||
|         event.preventDefault(); |  | ||||||
| 
 |  | ||||||
|         const enteredUsername = usernameInputRef.current.value; |  | ||||||
|         const enteredEmail = emailInputRef.current.value; |  | ||||||
|         const enteredPassword = passwordInputRef.current.value; |  | ||||||
| 
 |  | ||||||
|         // TODO: Add validation
 |  | ||||||
| 
 |  | ||||||
|         try { |  | ||||||
|             const result = await createUser(enteredUsername, enteredEmail, enteredPassword); |  | ||||||
|             console.log(result); |  | ||||||
|         } catch (error) { |  | ||||||
|             console.log(error); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return ( |  | ||||||
|         <form onSubmit={submitHandler}> |  | ||||||
|             <input type="text" id="username" name="username" placeholder="Username" ref={usernameInputRef} /> |  | ||||||
|             <input type="text" id="email" name="email" placeholder="Email Address" ref={emailInputRef}/> |  | ||||||
|             <input type="text" id="password" name="password" placeholder="Password" ref={passwordInputRef}/> |  | ||||||
|             <input type="submit" value="Sign up"/> |  | ||||||
|         </form> |  | ||||||
|     ); |  | ||||||
| } |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Bailey Pumfleet
						Bailey Pumfleet