Compare commits

...

2 Commits

5 changed files with 39 additions and 34 deletions

View File

@ -32,12 +32,13 @@ enum itemStatus {
lost lost
} }
// comments and descriptions -> @db.VarChar(2048)
model Item { model Item {
id Int @id @unique @default(autoincrement()) id Int @id @unique @default(autoincrement())
SKU String? @unique SKU String? @unique
amount Int @default(1) amount Int @default(1)
name String name String
comment String? comment String? @db.VarChar(2048)
status itemStatus @default(normal) /// TODO: Would it be better to create a separate model for this as well instead of providing several static statuses to choose from(enum)? status itemStatus @default(normal) /// TODO: Would it be better to create a separate model for this as well instead of providing several static statuses to choose from(enum)?
contactInfo contactInfo? @relation(fields: [contactInfoId], references: [id]) contactInfo contactInfo? @relation(fields: [contactInfoId], references: [id])
@ -81,7 +82,7 @@ model StorageUnit {
model itemCategory { model itemCategory {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
name String @unique name String @unique
description String? description String? @db.VarChar(2048)
Item Item[] Item Item[]
} }

View File

@ -11,12 +11,12 @@
<div class="modal-body"> <div class="modal-body">
<div class="mb-3"> <div class="mb-3">
<label for="itemModifyModalName" class="form-label">Name</label> <label for="itemModifyModalName" class="form-label">Name</label>
<input type="text" class="form-control" id="itemModifyModalName" name="name" required /> <input type="text" class="form-control" id="itemModifyModalName" name="name" maxlength="128" required />
<div id="itemModifyModalNameText" class="form-text">This name should be unqiue.</div> <div id="itemModifyModalNameText" class="form-text">This name should be unqiue.</div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="itemModifyModalComment" class="form-label">Comment</label> <label for="itemModifyModalComment" class="form-label">Comment</label>
<input type="text" class="form-control" id="itemModifyModalComment" name="comment" /> <input type="text" class="form-control" id="itemModifyModalComment" maxlength="2048" name="comment" />
<div id="itemModifyModalDescText" class="form-text">Optional</div> <div id="itemModifyModalDescText" class="form-text">Optional</div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
@ -36,12 +36,12 @@
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="itemModifyModalSKU" class="form-label">SKU</label> <label for="itemModifyModalSKU" class="form-label">SKU</label>
<input type="text" class="form-control" id="itemModifyModalSKU" name="sku" /> <input type="text" class="form-control" id="itemModifyModalSKU" maxlength="64" name="sku" />
<div id="itemModifyModalSKUText" class="form-text">Optional</div> <div id="itemModifyModalSKUText" class="form-text">Optional</div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="itemModifyModalManuf" class="form-label">Manufacturer</label> <label for="itemModifyModalManuf" class="form-label">Manufacturer</label>
<input type="text" class="form-control" id="itemModifyModalManuf" name="manufacturer" /> <input type="text" class="form-control" id="itemModifyModalManuf" maxlength="190" name="manufacturer" />
<div id="itemModifyModalSKUText" class="form-text">Optional</div> <div id="itemModifyModalSKUText" class="form-text">Optional</div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
@ -98,7 +98,7 @@
<tr> <tr>
<th scope="col" data-field="SKU" class="sku" data-sortable="true">SKU</th> <th scope="col" data-field="SKU" class="sku" data-sortable="true">SKU</th>
<th scope="col" data-field="name" data-sortable="true">Name</th> <th scope="col" data-field="name" data-sortable="true">Name</th>
<th scope="col" data-field="comment" data-sortable="true">Comment</th> <th scope="col" data-field="comment" data-sortable="true" data-width="80">Comment</th>
<th scope="col" data-field="status" data-sortable="true">Status</th> <th scope="col" data-field="status" data-sortable="true">Status</th>
<th scope="col" data-field="actions" data-searchable="false">Actions</th> <th scope="col" data-field="actions" data-searchable="false">Actions</th>
</tr> </tr>

View File

@ -20,12 +20,12 @@
<div class="modal-body"> <div class="modal-body">
<div class="mb-3"> <div class="mb-3">
<label for="editCategoryModalName" class="form-label">Name</label> <label for="editCategoryModalName" class="form-label">Name</label>
<input type="text" class="form-control" id="editCategoryModalName" name="name" required /> <input type="text" class="form-control" id="editCategoryModalName" maxlength="128" name="name" required />
<div id="editCategoryModalNameText" class="form-text">This name should be unqiue.</div> <div id="editCategoryModalNameText" class="form-text">This name should be unqiue.</div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="editCategoryModalDescription" class="form-label">Description</label> <label for="editCategoryModalDescription" class="form-label">Description</label>
<input type="text" class="form-control" id="editCategoryModalDescription" name="description" /> <input type="text" class="form-control" id="editCategoryModalDescription" maxlength="2048" name="description" />
<div id="editCategoryModalDescText" class="form-text">Optional</div> <div id="editCategoryModalDescText" class="form-text">Optional</div>
</div> </div>
<input type="text" id="editCategoryModalId" name="id" hidden /> <input type="text" id="editCategoryModalId" name="id" hidden />

View File

@ -13,7 +13,7 @@
<div class="modal-body"> <div class="modal-body">
<div class="mb-3"> <div class="mb-3">
<label for="storageLocationModalName" class="form-label">Name</label> <label for="storageLocationModalName" class="form-label">Name</label>
<input type="text" class="form-control" id="storageLocationModalName" name="name" required /> <input type="text" class="form-control" id="storageLocationModalName" name="name" maxlength="128" required />
<div id="storageLocationModalNameText" class="form-text">This name should be unqiue.</div> <div id="storageLocationModalNameText" class="form-text">This name should be unqiue.</div>
</div> </div>
<div class="mb-3"> <div class="mb-3">

View File

@ -1,12 +1,13 @@
import { Request, Response } from 'express'; import { Request, Response } from 'express';
import { prisma, __path, log } from '../../../index.js'; import { prisma, __path, log } from '../../../index.js';
import { parseIntOrUndefined } from '../../../assets/helper.js';
// Get storageLocation. // Get storageLocation.
function get(req: Request, res: Response) { function get(req: Request, res: Response) {
if (req.query.getAll === undefined) { if (req.query.getAll === undefined) {
// Check if required fields are present. // Check if required fields are present.
if (!req.query.id) { if (!req.query.id) {
res.status(400).json({ errorcode: 'VALIDATION_ERROR', error: 'One or more required fields are missing' }); res.status(400).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more required fields are missing' });
return; return;
} }
prisma.storageLocation prisma.storageLocation
@ -23,12 +24,12 @@ function get(req: Request, res: Response) {
if (items) { if (items) {
res.status(200).json(items); res.status(200).json(items);
} else { } else {
res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageLocation does not exist' }); res.status(410).json({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageLocation does not exist' });
} }
}) })
.catch((err) => { .catch((err) => {
log.db.error(err); log.db.error(err);
res.status(500).json({ errorcode: 'DB_ERROR', error: err }); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
}); });
} else { } else {
prisma.storageLocation prisma.storageLocation
@ -42,12 +43,12 @@ function get(req: Request, res: Response) {
if (items) { if (items) {
res.status(200).json(items); res.status(200).json(items);
} else { } else {
res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageLocation does not exist' }); res.status(410).json({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageLocation does not exist' });
} }
}) })
.catch((err) => { .catch((err) => {
log.db.error(err); log.db.error(err);
res.status(500).json({ errorcode: 'DB_ERROR', error: err }); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
}); });
} }
} }
@ -56,7 +57,7 @@ function get(req: Request, res: Response) {
function post(req: Request, res: Response) { function post(req: Request, res: Response) {
// Check if required fields are present. // Check if required fields are present.
if (!req.body.name) { if (!req.body.name) {
res.status(400).json({ errorcode: 'VALIDATION_ERROR', error: 'One or more required fields are missing' }); res.status(400).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more required fields are missing' });
return; return;
} }
// Create storageLocation with existing storageUnit. // Create storageLocation with existing storageUnit.
@ -71,22 +72,22 @@ function post(req: Request, res: Response) {
} }
}) })
.then((data) => { .then((data) => {
res.status(201).json({ status: 'created', id: data.id }); res.status(201).json({ status: 'CREATED', message: 'Successfully created storageLocation', id: data.id });
}) })
.catch((err) => { .catch((err) => {
// Check if an entry already exists. // Check if an entry already exists.
if (err.code === 'P2002') { if (err.code === 'P2002') {
// P2002 -> "Unique constraint failed on the {constraint}" // P2002 -> "Unique constraint failed on the {constraint}"
// https://www.prisma.io/docs/reference/api-reference/error-reference // https://www.prisma.io/docs/reference/api-reference/error-reference
res.status(409).json({ errorcode: 'EXISTING', error: 'storageLocation already exists' }); res.status(409).json({ status: 'ERROR', errorcode: 'EXISTING', message: 'storageLocation already exists' });
} else if (err.code == 'P2003') { } else if (err.code == 'P2003') {
// P2003 -> "Foreign key constraint failed on the field: {field_name}" // P2003 -> "Foreign key constraint failed on the field: {field_name}"
// https://www.prisma.io/docs/reference/api-reference/error-reference // https://www.prisma.io/docs/reference/api-reference/error-reference
// FIXME: Is this errormessage right? // FIXME: Is this errormessage right?
res.status(404).json({ error: 'specified storageUnitId does not exist' }); res.status(404).json({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageUnitId does not exist' });
} else { } else {
log.db.error(err); log.db.error(err);
res.status(500).json({ errorcode: 'DB_ERROR', error: err }); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
} }
}); });
} }
@ -95,7 +96,7 @@ function post(req: Request, res: Response) {
async function patch(req: Request, res: Response) { async function patch(req: Request, res: Response) {
// Check if required fields are present. // Check if required fields are present.
if (!req.body.id || !req.body.name || !req.body.storageUnitId) { if (!req.body.id || !req.body.name || !req.body.storageUnitId) {
res.status(400).json({ errorcode: 'VALIDATION_ERROR', error: 'One or more required fields are missing' }); res.status(400).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more required fields are missing' });
return; return;
} }
@ -108,12 +109,12 @@ async function patch(req: Request, res: Response) {
}); });
if (result === null) { if (result === null) {
res.status(404).json({ error: 'storageLocation does not exist.' }); res.status(404).json({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageLocation does not exist' });
return; return;
} }
} catch (err) { } catch (err) {
log.db.error(err); log.db.error(err);
res.status(500).json({ errorcode: 'DB_ERROR', error: err }); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
} }
prisma.storageLocation prisma.storageLocation
@ -123,26 +124,29 @@ async function patch(req: Request, res: Response) {
}, },
data: { data: {
name: req.body.name, name: req.body.name,
storageUnitId: parseInt(req.body.storageUnitId) || undefined storageUnitId: parseIntOrUndefined(req.body.storageUnitId)
},
select: {
id: true
} }
}) })
.then(() => { .then((data) => {
res.status(201).json({ status: 'updated' }); res.status(201).json({ status: 'UPDATED', message: 'Successfully updated storageLocation', id: data.id });
}) })
.catch((err) => { .catch((err) => {
// Check if an entry already exists. // Check if an entry already exists.
if (err.code === 'P2002') { if (err.code === 'P2002') {
// P2002 -> "Unique constraint failed on the {constraint}" // P2002 -> "Unique constraint failed on the {constraint}"
// https://www.prisma.io/docs/reference/api-reference/error-reference // https://www.prisma.io/docs/reference/api-reference/error-reference
res.status(409).json({ errorcode: 'EXISTING', error: 'storageLocation already exists' }); res.status(409).json({ status: 'ERROR', errorcode: 'EXISTING', message: 'storageLocation already exists' });
} else if (err.code == 'P2003') { } else if (err.code == 'P2003') {
// P2003 -> "Foreign key constraint failed on the field: {field_name}" // P2003 -> "Foreign key constraint failed on the field: {field_name}"
// https://www.prisma.io/docs/reference/api-reference/error-reference // https://www.prisma.io/docs/reference/api-reference/error-reference
// FIXME: Is this errormessage right? // FIXME: Is this errormessage right?
res.status(404).json({ error: 'specified storageUnitId does not exist' }); res.status(404).json({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageUnitId does not exist' });
} else { } else {
log.db.error(err); log.db.error(err);
res.status(500).json({ errorcode: 'DB_ERROR', error: err }); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
} }
}); });
} }
@ -151,7 +155,7 @@ async function patch(req: Request, res: Response) {
async function del(req: Request, res: Response) { async function del(req: Request, res: Response) {
// Check if required fields are present. // Check if required fields are present.
if (!req.body.id) { if (!req.body.id) {
res.status(400).json({ errorcode: 'VALIDATION_ERROR', error: 'One or more required fields are missing' }); res.status(400).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more required fields are missing' });
return; return;
} }
@ -164,12 +168,12 @@ async function del(req: Request, res: Response) {
}); });
if (result === null) { if (result === null) {
res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageLocation does not exist' }); res.status(410).json({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageLocation does not exist' });
return; return;
} }
} catch (err) { } catch (err) {
log.db.error(err); log.db.error(err);
res.status(500).json({ errorcode: 'DB_ERROR', error: err }); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
} }
prisma.storageLocation prisma.storageLocation
@ -179,11 +183,11 @@ async function del(req: Request, res: Response) {
} }
}) })
.then(() => { .then(() => {
res.status(200).json({ errorcode: 'DELETED', error: 'Sucessfully deleted entry' }); res.status(200).json({ status: 'DELETED', message: 'Successfully deleted storageLocation' });
}) })
.catch((err) => { .catch((err) => {
log.db.error(err); log.db.error(err);
res.status(500).json({ errorcode: 'DB_ERROR', error: err }); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
}); });
} }