Compare commits

..

No commits in common. "57513da827fa5dec5f1e87fd20d578aaf90b2b77" and "e0ac50900724da2ab9f6e1b3c81fabef007abc6b" have entirely different histories.

3 changed files with 6 additions and 8 deletions

View File

@ -66,16 +66,13 @@ 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', doNotDisconnect: boolean = false) { export function parseIntRelation(data: string, relation_name: string = 'id') {
// 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, undefined, true), contactInfo: parseIntRelation(req.body.contactInfoId),
category: parseIntRelation(req.body.categoryId, undefined, true), category: parseIntRelation(req.body.categoryId),
storageLocation: parseIntRelation(req.body.storageLocationId, undefined, true), storageLocation: parseIntRelation(req.body.storageLocationId),
manufacturer: req.body.manufacturer, manufacturer: req.body.manufacturer,

View File

@ -23,11 +23,12 @@ async function get(req: Request, res: Response) {
return; return;
} }
prisma.item prisma.item
.findMany({ skip: (page - 1) * takeSize, take: takeSize, orderBy: { SKU: "asc" } }) // Skip the amount of items per page times the page number minus 1; skip has to be (page-1)*takeSize because skip is 0 indexed .findMany({ skip: (page - 1) * takeSize, take: takeSize }) // Skip the amount of items per page times the page number minus 1; skip has to be (page-1)*takeSize because skip is 0 indexed
.then((items) => { .then((items) => {
prisma.storageLocation.findMany({}).then((locations) => { prisma.storageLocation.findMany({}).then((locations) => {
prisma.itemCategory.findMany({}).then((categories) => { prisma.itemCategory.findMany({}).then((categories) => {
prisma.contactInfo.findMany({}).then((contactInfo) => { prisma.contactInfo.findMany({}).then((contactInfo) => {
res.render(__path + '/src/frontend/items.eta.html', { items: items, currentPage: page, maxPages: pageSize, storeLocs: locations, categories: categories, contactInfo: contactInfo }); res.render(__path + '/src/frontend/items.eta.html', { items: items, currentPage: page, maxPages: pageSize, storeLocs: locations, categories: categories, contactInfo: contactInfo });
}) })
}); });