- fixed item creation, which was broken by last update

This commit is contained in:
Sören Oesterwind 2023-07-07 15:13:17 +02:00
parent 185d563ac0
commit 57513da827
2 changed files with 7 additions and 4 deletions

View File

@ -66,13 +66,16 @@ function returnAllModelFieldData() {
* @param {string} [relation_name='id'] * @param {string} [relation_name='id']
* @returns {undefined || object} undefined or prisma connect object * @returns {undefined || object} undefined or prisma connect object
*/ */
export function parseIntRelation(data: string, relation_name: string = 'id') { export function parseIntRelation(data: string, relation_name: string = 'id', doNotDisconnect: boolean = false) {
// This function is perfect. If data is not a valid number, return `undefined` // This function is perfect. If data is not a valid number, return `undefined`
// If it is a valid number return `{connect: {relation_name: yourNumber}}}` // If it is a valid number return `{connect: {relation_name: yourNumber}}}`
// This can be used by prisma to connect relations // 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 the incoming data is null or empty, return a prisma disconnect object instead of a connect one
if (data === null || data === '') { if (data === null || data === '') {
if (doNotDisconnect) {
return undefined;
}
return JSON.parse(`{ return JSON.parse(`{
"disconnect": true "disconnect": true
}`); }`);

View File

@ -102,9 +102,9 @@ function post(req: Request, res: Response) {
comment: req.body.comment, comment: req.body.comment,
status: req.body.status, // Only enum(itemStatus) values are valid status: req.body.status, // Only enum(itemStatus) values are valid
// Relations // Relations
contactInfo: parseIntRelation(req.body.contactInfoId), contactInfo: parseIntRelation(req.body.contactInfoId, undefined, true),
category: parseIntRelation(req.body.categoryId), category: parseIntRelation(req.body.categoryId, undefined, true),
storageLocation: parseIntRelation(req.body.storageLocationId), storageLocation: parseIntRelation(req.body.storageLocationId, undefined, true),
manufacturer: req.body.manufacturer, manufacturer: req.body.manufacturer,