Skip to content

Commit

Permalink
Merge pull request #13 from ambarltd/parsing
Browse files Browse the repository at this point in the history
Simplify request parsing
  • Loading branch information
lazamar authored Jan 7, 2025
2 parents 4cc093d + 471a7ce commit acf29e2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 36 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { PostgresTransactionalEventStore } from '../../../common/eventStore/Post
import { MongoTransactionalProjectionOperator } from '../../../common/projection/MongoTransactionalProjectionOperator';
import { RequestEnrollmentCommandHandler } from './RequestEnrollmentCommandHandler';
import { RequestEnrollmentCommand } from './RequestEnrollmentCommand';
import {requestEnrollmentHttpRequestSchema} from './RequestEnrollmentHttpRequest';
import {inject, injectable} from "tsyringe";
import {parseWithValidation} from "../../../common/util/ParseWithValidation";
import { z } from 'zod';

@injectable()
export class EnrollmentCommandController extends CommandController {
Expand All @@ -32,7 +31,7 @@ export class EnrollmentCommandController extends CommandController {
return;
}

const requestBody = parseWithValidation(req.body, requestEnrollmentHttpRequestSchema);
const requestBody = requestSchema.parse(req.body);
const command = new RequestEnrollmentCommand(
sessionToken,
requestBody.productId,
Expand All @@ -43,3 +42,8 @@ export class EnrollmentCommandController extends CommandController {
res.status(200).json({});
}
}

const requestSchema = z.object({
productId: z.string(),
annualIncomeInCents: z.number().min(0, "Annual income cannot be negative").max(1_000_000_000, "Annual income is too high")
});

This file was deleted.

0 comments on commit acf29e2

Please sign in to comment.