seed stuff

This commit is contained in:
Jake Kasper
2025-09-03 10:56:17 -04:00
parent 6dbdba0e38
commit e7cbaf844f
8 changed files with 271 additions and 28 deletions

View File

@@ -406,7 +406,7 @@ router.get('/products', async (req, res, next) => {
// @access Private (Admin)
router.post('/products', validateRequest(productSchema), async (req, res, next) => {
try {
const { name, brand, categoryId, productType, activeIngredients, description } = req.body;
const { name, brand, categoryId, productType, activeIngredients, description, seedBlend } = req.body;
// Check if category exists
const categoryCheck = await pool.query(
@@ -419,10 +419,10 @@ router.post('/products', validateRequest(productSchema), async (req, res, next)
}
const result = await pool.query(
`INSERT INTO products (name, brand, category_id, product_type, active_ingredients, description)
VALUES ($1, $2, $3, $4, $5, $6)
`INSERT INTO products (name, brand, category_id, product_type, active_ingredients, description, seed_blend)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING *`,
[name, brand, categoryId, productType, activeIngredients, description]
[name, brand, categoryId, productType, activeIngredients, description, seedBlend ? JSON.stringify(seedBlend) : null]
);
const product = result.rows[0];
@@ -439,7 +439,8 @@ router.post('/products', validateRequest(productSchema), async (req, res, next)
productType: product.product_type,
activeIngredients: product.active_ingredients,
description: product.description,
createdAt: product.created_at
createdAt: product.created_at,
seedBlend: product.seed_blend
}
}
});
@@ -454,7 +455,7 @@ router.post('/products', validateRequest(productSchema), async (req, res, next)
router.put('/products/:id', validateParams(idParamSchema), validateRequest(productSchema), async (req, res, next) => {
try {
const productId = req.params.id;
const { name, brand, categoryId, productType, activeIngredients, description } = req.body;
const { name, brand, categoryId, productType, activeIngredients, description, seedBlend } = req.body;
// Check if product exists
const productCheck = await pool.query(
@@ -479,10 +480,10 @@ router.put('/products/:id', validateParams(idParamSchema), validateRequest(produ
const result = await pool.query(
`UPDATE products
SET name = $1, brand = $2, category_id = $3, product_type = $4,
active_ingredients = $5, description = $6
WHERE id = $7
active_ingredients = $5, description = $6, seed_blend = $7
WHERE id = $8
RETURNING *`,
[name, brand, categoryId, productType, activeIngredients, description, productId]
[name, brand, categoryId, productType, activeIngredients, description, seedBlend ? JSON.stringify(seedBlend) : null, productId]
);
const product = result.rows[0];
@@ -498,6 +499,7 @@ router.put('/products/:id', validateParams(idParamSchema), validateRequest(produ
categoryId: product.category_id,
productType: product.product_type,
activeIngredients: product.active_ingredients,
seedBlend: product.seed_blend,
description: product.description,
createdAt: product.created_at
}
@@ -1120,4 +1122,4 @@ router.put('/settings', async (req, res, next) => {
}
});
module.exports = router;
module.exports = router;