-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added API Endpoints to get Students and Classes from ID Added Indication of No Results for Search Query Added Indication of Invalid ID for Direct Navigation Added RenovateBot
- Loading branch information
1 parent
f02fbd9
commit 8e112ca
Showing
13 changed files
with
271 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
## NPM | ||
npm-shrinkwrap.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {NextApiRequest} from "next"; | ||
|
||
export type NextStudentApiRequest = NextApiRequest & { | ||
query: { | ||
student_id: string | ||
} | ||
}; | ||
|
||
export type NextClassApiRequest = NextApiRequest & { | ||
query: { | ||
class_id: string | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,22 @@ | ||
import {NextApiRequest, NextApiResponse} from "next"; | ||
import {NextApiResponse} from "next"; | ||
|
||
import {updateStudentOnDates} from "../../../src/database/update/attendance"; | ||
import {NextClassApiRequest} from "../../../interfaces"; | ||
|
||
async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
if (req.method !== "PUT") { | ||
res.setHeader("Allow", "PUT"); | ||
res.status(405).end(); | ||
return; | ||
} | ||
import {classById} from "../../../src/database/read/classes"; | ||
|
||
if (!req.query.class_id || isNaN(parseInt(req.query.class_id as string))) { | ||
res.status(400).end(); | ||
async function handler(req: NextClassApiRequest, res: NextApiResponse) { | ||
if (req.method !== "GET") { | ||
res.setHeader("Allow", "GET"); | ||
res.status(405).end(); | ||
return; | ||
} | ||
|
||
// let user = supabase.auth.api.getUserByCookie(req); | ||
|
||
const students = Object.keys(req.body); | ||
|
||
for (const student of students) { | ||
const dates: Date[] = []; | ||
const attendances: boolean[] = []; | ||
|
||
const keys = Object.keys(req.body[student]); | ||
|
||
for (const date of keys) { | ||
dates.push(new Date(date)); | ||
attendances.push(req.body[student][date]); | ||
} | ||
|
||
await updateStudentOnDates(student, dates, attendances); | ||
} | ||
const class_ = await classById(parseInt(req.query.class_id)); | ||
|
||
res.status(200).end(); | ||
res.setHeader("Content-Type", "application/json"); | ||
res.status(class_ !== null ? 200 : 404).json({class: class_}); | ||
} | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {NextApiRequest, NextApiResponse} from "next"; | ||
|
||
import {updateStudentOnDates} from "../../../../src/database/update/attendance"; | ||
|
||
async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
if (req.method !== "PUT") { | ||
res.setHeader("Allow", "PUT"); | ||
res.status(405).end(); | ||
return; | ||
} | ||
|
||
if (!req.query.class_id || isNaN(parseInt(req.query.class_id as string))) { | ||
res.status(400).end(); | ||
return; | ||
} | ||
|
||
// let user = supabase.auth.api.getUserByCookie(req); | ||
|
||
const students = Object.keys(req.body); | ||
|
||
for (const student of students) { | ||
const dates: Date[] = []; | ||
const attendances: boolean[] = []; | ||
|
||
const keys = Object.keys(req.body[student]); | ||
|
||
for (const date of keys) { | ||
dates.push(new Date(date)); | ||
attendances.push(req.body[student][date]); | ||
} | ||
|
||
await updateStudentOnDates(student, dates, attendances); | ||
} | ||
|
||
res.status(200).end(); | ||
} | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,22 @@ | ||
import {NextApiRequest, NextApiResponse} from "next"; | ||
import {NextApiResponse} from "next"; | ||
|
||
import {updateStudentOnDates} from "../../../src/database/update/attendance"; | ||
import {NextStudentApiRequest} from "../../../interfaces"; | ||
|
||
async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
if (req.method !== "PUT") { | ||
res.setHeader("Allow", "PUT"); | ||
res.status(405).end(); | ||
return; | ||
} | ||
import {studentById} from "../../../src/database/read/students"; | ||
|
||
if (!req.query.student_id) { | ||
res.status(400).end(); | ||
async function handler(req: NextStudentApiRequest, res: NextApiResponse) { | ||
if (req.method !== "GET") { | ||
res.setHeader("Allow", "GET"); | ||
res.status(405).end(); | ||
return; | ||
} | ||
|
||
// let user = supabase.auth.api.getUserByCookie(req); | ||
|
||
let dates: Date[] = []; | ||
let attendances: boolean[] = []; | ||
|
||
let keys = Object.keys(req.body); | ||
|
||
for (const date of keys) { | ||
dates.push(new Date(date)); | ||
attendances.push(req.body[date]); | ||
} | ||
|
||
await updateStudentOnDates(req.query.student_id as string, dates, attendances); | ||
const student = await studentById(req.query.student_id); | ||
|
||
res.statusCode = 200; | ||
res.end(); | ||
res.setHeader("Content-Type", "application/json"); | ||
res.status(student !== null ? 200 : 404).json({student}); | ||
} | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {NextApiRequest, NextApiResponse} from "next"; | ||
|
||
import {updateStudentOnDates} from "../../../../src/database/update/attendance"; | ||
|
||
async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
if (req.method !== "PUT") { | ||
res.setHeader("Allow", "PUT"); | ||
res.status(405).end(); | ||
return; | ||
} | ||
|
||
if (!req.query.student_id) { | ||
res.status(400).end(); | ||
return; | ||
} | ||
|
||
// let user = supabase.auth.api.getUserByCookie(req); | ||
|
||
let dates: Date[] = []; | ||
let attendances: boolean[] = []; | ||
|
||
let keys = Object.keys(req.body); | ||
|
||
for (const date of keys) { | ||
dates.push(new Date(date)); | ||
attendances.push(req.body[date]); | ||
} | ||
|
||
await updateStudentOnDates(req.query.student_id as string, dates, attendances); | ||
|
||
res.status(200).end(); | ||
} | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.