-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from sinamics/api
Implemented Zod schemas for improved API input validation
- Loading branch information
Showing
23 changed files
with
373 additions
and
145 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
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
40 changes: 40 additions & 0 deletions
40
src/pages/api/v1/network/[id]/member/[memberId]/_schema.ts
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { z } from "zod"; | ||
|
||
// Schema for updateable fields metadata | ||
export const updateableFieldsMetaSchema = z | ||
.object({ | ||
name: z.string().optional(), | ||
authorized: z.boolean().optional(), | ||
}) | ||
.strict(); | ||
|
||
// Schema for the context passed to the handler | ||
export const handlerContextSchema = z.object({ | ||
body: z.record(z.unknown()), | ||
userId: z.string(), | ||
networkId: z.string(), | ||
memberId: z.string(), | ||
ctx: z.object({ | ||
prisma: z.any(), | ||
session: z.object({ | ||
user: z.object({ | ||
id: z.string(), | ||
}), | ||
}), | ||
}), | ||
}); | ||
|
||
// Schema for the context passed to the DELETE handler | ||
export const deleteHandlerContextSchema = z.object({ | ||
userId: z.string(), | ||
networkId: z.string(), | ||
memberId: z.string(), | ||
ctx: z.object({ | ||
prisma: z.any(), | ||
session: z.object({ | ||
user: z.object({ | ||
id: z.string(), | ||
}), | ||
}), | ||
}), | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { z } from "zod"; | ||
|
||
// Schema for the request body when creating a new network | ||
export const createNetworkBodySchema = z | ||
.object({ | ||
name: z.string().optional(), | ||
}) | ||
.strict(); | ||
|
||
// Schema for the context passed to the handler | ||
export const createNetworkContextSchema = z.object({ | ||
body: createNetworkBodySchema, | ||
ctx: z.object({ | ||
prisma: z.any(), | ||
session: z.object({ | ||
user: z.object({ | ||
id: z.string(), | ||
}), | ||
}), | ||
}), | ||
}); |
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.