This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: 🔧 merge 'main' into enrollment-history
- Loading branch information
Showing
19 changed files
with
247 additions
and
248 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,37 @@ | ||
import { PrismaClient } from "@libs/db"; | ||
import { createErrorResult, createOKResult } from "@libs/lambda"; | ||
import type { APIGatewayProxyHandler } from "aws-lambda"; | ||
import { createHandler } from "@libs/lambda"; | ||
import { ZodError } from "zod"; | ||
|
||
import { constructPrismaQuery, normalizeCourse } from "./lib"; | ||
import { QuerySchema } from "./schema"; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
export const GET: APIGatewayProxyHandler = async (event, context) => { | ||
async function onWarm() { | ||
await prisma.$connect(); | ||
} | ||
|
||
export const GET = createHandler(async (event, context, res) => { | ||
const headers = event.headers; | ||
const query = event.queryStringParameters; | ||
const requestId = context.awsRequestId; | ||
|
||
/** | ||
* TODO: handle warmer requests. | ||
*/ | ||
|
||
// if (request.isWarmerRequest) { | ||
// try { | ||
// await prisma.$connect(); | ||
// return createOKResult("Warmed", headers, requestId); | ||
// } catch (e) { | ||
// createErrorResult(500, e, requestId); | ||
// } | ||
// } | ||
|
||
try { | ||
const parsedQuery = QuerySchema.parse(query); | ||
|
||
// The query object being empty shouldn't return all courses, since there's /courses/all for that. | ||
if (!Object.keys(parsedQuery).length) { | ||
return createErrorResult(400, "Course number not provided", requestId); | ||
return res.createErrorResult(400, "Course number not provided", requestId); | ||
} | ||
|
||
const courses = await prisma.course.findMany({ where: constructPrismaQuery(parsedQuery) }); | ||
|
||
return createOKResult(courses.map(normalizeCourse), headers, requestId); | ||
return res.createOKResult(courses.map(normalizeCourse), headers, requestId); | ||
} catch (error) { | ||
if (error instanceof ZodError) { | ||
const messages = error.issues.map((issue) => issue.message); | ||
return createErrorResult(400, messages.join("; "), requestId); | ||
return res.createErrorResult(400, messages.join("; "), requestId); | ||
} | ||
return createErrorResult(400, error, requestId); | ||
return res.createErrorResult(400, error, requestId); | ||
} | ||
}; | ||
}, onWarm); |
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.