Implemented api validation and item route patch
- Implemented api field validation in item api routes - Implemented PATCH api route for item endpoint
This commit is contained in:
@ -70,9 +70,21 @@ export function parseIntRelation(data: string, relation_name: string = 'id') {
|
||||
// This function is perfect. If data is not a valid number, return `undefined`
|
||||
// If it is a valid number return `{connect: {relation_name: yourNumber}}}`
|
||||
// This can be used by prisma to connect relations
|
||||
|
||||
// If the incoming data is null or empty, return a prisma disconnect object instead of a connect one
|
||||
if (data === null || data === '') {
|
||||
return JSON.parse(`{
|
||||
"disconnect": true
|
||||
}`);
|
||||
}
|
||||
|
||||
return isNaN(parseInt(data)) ? undefined : JSON.parse(`{
|
||||
"connect": {
|
||||
"${relation_name}": ${parseInt(data)}
|
||||
}
|
||||
}`);
|
||||
}
|
||||
|
||||
export function parseIntOrUndefined(data: string) {
|
||||
return isNaN(parseInt(data)) ? undefined : parseInt(data);
|
||||
}
|
||||
|
Reference in New Issue
Block a user