Dashboard allows for manual inventory updates and shows relevant info.
This commit is contained in:
@@ -45,11 +45,11 @@ router.post('/', async (req, res) => {
|
||||
req.user!.id, b.piFirstName, b.physicalState, b.chemicalName, b.bldgCode, b.lab,
|
||||
b.storageLocation, b.storageDevice, b.numberOfContainers, b.amountPerContainer,
|
||||
b.unitOfMeasure, b.casNumber,
|
||||
b.chemicalFormula ?? null, b.molecularWeight ?? null, b.vendor ?? null,
|
||||
b.catalogNumber ?? null, b.lotNumber ?? null,
|
||||
b.expirationDate ?? null, b.concentration ?? null,
|
||||
b.chemicalFormula || null, b.molecularWeight || null, b.vendor || null,
|
||||
b.catalogNumber || null, b.lotNumber || null,
|
||||
b.expirationDate || null, b.concentration || null,
|
||||
b.percentageFull ?? null, b.needsManualEntry ?? null,
|
||||
b.scannedImage ?? null, b.comments ?? null, b.barcode ?? null, b.contact ?? null,
|
||||
b.scannedImage || null, b.comments || null, b.barcode || null, b.contact || null,
|
||||
]
|
||||
);
|
||||
res.status(201).json(snakeToCamel(result.rows[0]));
|
||||
@@ -62,12 +62,13 @@ router.post('/', async (req, res) => {
|
||||
// PATCH /api/chemicals/:id
|
||||
router.patch('/:id', async (req, res) => {
|
||||
try {
|
||||
const fields = Object.keys(req.body);
|
||||
const skip = new Set(['id', 'user_id', 'created_at', 'updated_at']);
|
||||
const fields = Object.keys(req.body).filter(k => !skip.has(k) && !skip.has(camelToSnake(k)));
|
||||
if (fields.length === 0) return res.status(400).json({ error: 'No fields to update' });
|
||||
|
||||
const snakeFields = fields.map(camelToSnake);
|
||||
const setClauses = snakeFields.map((f, i) => `${f} = $${i + 3}`).join(', ');
|
||||
const values = fields.map(f => req.body[f]);
|
||||
const values = fields.map(f => req.body[f] || null);
|
||||
|
||||
const result = await pool.query(
|
||||
`UPDATE chemicals SET ${setClauses}, updated_at = NOW()
|
||||
|
||||
Reference in New Issue
Block a user