Compare commits
No commits in common. "534cc3055fb720de0ad9c7fb4c86b26a2a97748b" and "09e74f9eb6ad2c11f382d759d507a3a20828d51d" have entirely different histories.
534cc3055f
...
09e74f9eb6
@ -32,13 +32,12 @@ 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? @db.VarChar(2048)
|
comment String?
|
||||||
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])
|
||||||
@ -82,7 +81,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? @db.VarChar(2048)
|
description String?
|
||||||
Item Item[]
|
Item Item[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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" maxlength="128" required />
|
<input type="text" class="form-control" id="itemModifyModalName" name="name" 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" maxlength="2048" name="comment" />
|
<input type="text" class="form-control" id="itemModifyModalComment" 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" maxlength="64" name="sku" />
|
<input type="text" class="form-control" id="itemModifyModalSKU" 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" maxlength="190" name="manufacturer" />
|
<input type="text" class="form-control" id="itemModifyModalManuf" 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" data-width="80">Comment</th>
|
<th scope="col" data-field="comment" data-sortable="true">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>
|
||||||
|
@ -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" maxlength="128" name="name" required />
|
<input type="text" class="form-control" id="editCategoryModalName" 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" maxlength="2048" name="description" />
|
<input type="text" class="form-control" id="editCategoryModalDescription" 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 />
|
||||||
|
@ -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" maxlength="128" required />
|
<input type="text" class="form-control" id="storageLocationModalName" name="name" 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">
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
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({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more required fields are missing' });
|
res.status(400).json({ errorcode: 'VALIDATION_ERROR', error: 'One or more required fields are missing' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
prisma.storageLocation
|
prisma.storageLocation
|
||||||
@ -24,12 +23,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({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageLocation does not exist' });
|
res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageLocation does not exist' });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
log.db.error(err);
|
log.db.error(err);
|
||||||
res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
|
res.status(500).json({ errorcode: 'DB_ERROR', error: err });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
prisma.storageLocation
|
prisma.storageLocation
|
||||||
@ -43,12 +42,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({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageLocation does not exist' });
|
res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageLocation does not exist' });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
log.db.error(err);
|
log.db.error(err);
|
||||||
res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
|
res.status(500).json({ errorcode: 'DB_ERROR', error: err });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,7 +56,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({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more required fields are missing' });
|
res.status(400).json({ errorcode: 'VALIDATION_ERROR', error: 'One or more required fields are missing' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Create storageLocation with existing storageUnit.
|
// Create storageLocation with existing storageUnit.
|
||||||
@ -72,22 +71,22 @@ function post(req: Request, res: Response) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(201).json({ status: 'CREATED', message: 'Successfully created storageLocation', id: data.id });
|
res.status(201).json({ status: 'created', 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({ status: 'ERROR', errorcode: 'EXISTING', message: 'storageLocation already exists' });
|
res.status(409).json({ errorcode: 'EXISTING', error: '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({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageUnitId does not exist' });
|
res.status(404).json({ error: 'specified storageUnitId does not exist' });
|
||||||
} else {
|
} else {
|
||||||
log.db.error(err);
|
log.db.error(err);
|
||||||
res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
|
res.status(500).json({ errorcode: 'DB_ERROR', error: err });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -96,7 +95,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({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more required fields are missing' });
|
res.status(400).json({ errorcode: 'VALIDATION_ERROR', error: 'One or more required fields are missing' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,12 +108,12 @@ async function patch(req: Request, res: Response) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (result === null) {
|
if (result === null) {
|
||||||
res.status(404).json({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageLocation does not exist' });
|
res.status(404).json({ error: 'storageLocation does not exist.' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.db.error(err);
|
log.db.error(err);
|
||||||
res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
|
res.status(500).json({ errorcode: 'DB_ERROR', error: err });
|
||||||
}
|
}
|
||||||
|
|
||||||
prisma.storageLocation
|
prisma.storageLocation
|
||||||
@ -124,29 +123,26 @@ async function patch(req: Request, res: Response) {
|
|||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
name: req.body.name,
|
name: req.body.name,
|
||||||
storageUnitId: parseIntOrUndefined(req.body.storageUnitId)
|
storageUnitId: parseInt(req.body.storageUnitId) || undefined
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then(() => {
|
||||||
res.status(201).json({ status: 'UPDATED', message: 'Successfully updated storageLocation', id: data.id });
|
res.status(201).json({ status: 'updated' });
|
||||||
})
|
})
|
||||||
.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({ status: 'ERROR', errorcode: 'EXISTING', message: 'storageLocation already exists' });
|
res.status(409).json({ errorcode: 'EXISTING', error: '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({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageUnitId does not exist' });
|
res.status(404).json({ error: 'specified storageUnitId does not exist' });
|
||||||
} else {
|
} else {
|
||||||
log.db.error(err);
|
log.db.error(err);
|
||||||
res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
|
res.status(500).json({ errorcode: 'DB_ERROR', error: err });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -155,7 +151,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({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more required fields are missing' });
|
res.status(400).json({ errorcode: 'VALIDATION_ERROR', error: 'One or more required fields are missing' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,12 +164,12 @@ async function del(req: Request, res: Response) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (result === null) {
|
if (result === null) {
|
||||||
res.status(410).json({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageLocation does not exist' });
|
res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageLocation does not exist' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.db.error(err);
|
log.db.error(err);
|
||||||
res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
|
res.status(500).json({ errorcode: 'DB_ERROR', error: err });
|
||||||
}
|
}
|
||||||
|
|
||||||
prisma.storageLocation
|
prisma.storageLocation
|
||||||
@ -183,11 +179,11 @@ async function del(req: Request, res: Response) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
res.status(200).json({ status: 'DELETED', message: 'Successfully deleted storageLocation' });
|
res.status(200).json({ errorcode: 'DELETED', error: 'Sucessfully deleted entry' });
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
log.db.error(err);
|
log.db.error(err);
|
||||||
res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });
|
res.status(500).json({ errorcode: 'DB_ERROR', error: err });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user