Skip to content

Commit

Permalink
dp/fix-date-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 6, 2023
1 parent 65f2218 commit 262a35b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ScheduledEventResponse } from "../../../../hasura/metadata";

export const createSessionEventSchema = z.object({
body: z.object({
createdAt: z.string().transform((val) => new Date(val)),
createdAt: z.string().pipe(z.coerce.date()),
payload: z.object({
sessionId: z.string(),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ScheduledEventResponse } from "../../../../hasura/metadata";

export const createPaymentEventSchema = z.object({
body: z.object({
createdAt: z.string().transform((val) => new Date(val)),
createdAt: z.string().pipe(z.coerce.date()),
payload: z.object({
paymentRequestId: z.string(),
}),
Expand Down
9 changes: 8 additions & 1 deletion api.planx.uk/shared/middleware/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ export const validate =
next: NextFunction,
) => {
try {
schema.parse({
const parsedReq = schema.parse({
params: req.params,
body: req.body,
query: req.query,
});

// Assign parsed values to the request object
// Required for schemas to transform or coerce raw requests
req.params = parsedReq.params;
req.body = parsedReq.body;
req.query = parsedReq.query;

return next();
} catch (error) {
console.error(error);
Expand Down

0 comments on commit 262a35b

Please sign in to comment.