Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
feat: ✨ use createHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
ecxyzzy committed Nov 15, 2023
1 parent 9462d93 commit f601760
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions apps/api/src/routes/v1/rest/enrollmentHistory/+endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { PrismaClient } from "@libs/db";
import { createErrorResult, createOKResult } from "@libs/lambda";
import { createHandler } from "@libs/lambda";
import type { EnrollmentHistory } from "@peterportal-api/types";
import type { APIGatewayProxyHandler } from "aws-lambda";

import { QuerySchema } from "./schema";

const prisma = new PrismaClient();

export const GET: APIGatewayProxyHandler = async (event, context) => {
export const GET = createHandler(async (event, context, res) => {
const { headers, queryStringParameters: query } = event;
const { awsRequestId: requestId } = context;

const maybeParsed = QuerySchema.safeParse(query);
if (!maybeParsed.success) {
return createErrorResult(400, maybeParsed.error, requestId);
return res.createErrorResult(400, maybeParsed.error, requestId);
}
const {
data: { instructor, ...data },
} = maybeParsed;

return createOKResult<EnrollmentHistory[]>(
return res.createOKResult<EnrollmentHistory[]>(
(
await prisma.websocEnrollmentHistory.findMany({
where: { ...data, instructors: { array_contains: instructor } },
Expand All @@ -31,4 +30,4 @@ export const GET: APIGatewayProxyHandler = async (event, context) => {
headers,
requestId,
);
};
});

0 comments on commit f601760

Please sign in to comment.