Skip to content

Commit 41cb1d1

Browse files
committed
added schema and route
added minlength for empty string validation server side validation for update
1 parent 0f6f3bb commit 41cb1d1

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

server/app/routes/parent-organization-router.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import { Router } from "express";
22
const router = Router();
33
import parentOrganizationController from "../controllers/parent-organization-controller";
4+
import { requestValidationMiddleware } from "../../middleware/request-validation-middlewares";
5+
import { ParentOrganizationPostRequestSchema } from "../validation-schema/parent-organization-schema";
6+
import { ParentOrganizationPutRequestSchema } from "../validation-schema/parent-organization-schema";
47

58
import jwtSession from "../../middleware/jwt-session";
69

710
router.get("/:tenantId", parentOrganizationController.getAllByTenantId);
11+
812
router.post(
913
"/",
1014
jwtSession.validateUserHasRequiredRoles(["admin"]),
15+
requestValidationMiddleware(ParentOrganizationPostRequestSchema),
1116
parentOrganizationController.insert
1217
);
18+
1319
router.put(
1420
"/:id",
1521
jwtSession.validateUserHasRequiredRoles(["admin"]),
22+
requestValidationMiddleware(ParentOrganizationPutRequestSchema),
1623
parentOrganizationController.update
1724
);
1825

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { JSONSchemaType } from "ajv";
2+
import { ParentOrganization } from "../../types/parent-organization-types";
3+
4+
export const ParentOrganizationPostRequestSchema: JSONSchemaType<ParentOrganization> = {
5+
type: "object",
6+
required: ["name", "code"],
7+
properties: {
8+
code: {
9+
type: "string",
10+
minLength: 1,
11+
},
12+
id: {
13+
type: "number",
14+
},
15+
name: {
16+
type: "string",
17+
minLength: 1,
18+
},
19+
tenantId: {
20+
type: "number",
21+
},
22+
},
23+
additionalProperties: false,
24+
};
25+
26+
27+
export const ParentOrganizationPutRequestSchema: JSONSchemaType<ParentOrganization> = {
28+
type: "object",
29+
required: ["id", "name", "code"],
30+
properties: {
31+
id: {
32+
type: "number"
33+
},
34+
name: {
35+
type: "string",
36+
minLength: 1
37+
},
38+
code: {
39+
type: "string",
40+
minLength: 1
41+
},
42+
tenantId: {
43+
type: "number"
44+
},
45+
},
46+
additionalProperties: false,
47+
};

0 commit comments

Comments
 (0)