Dashboard allows for manual inventory updates and shows relevant info.

This commit is contained in:
pulipakaa24
2026-03-20 00:28:45 -05:00
parent 0b4b1a6ff5
commit fc143bea5d
3 changed files with 863 additions and 733 deletions

View File

@@ -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()