Delet Subcategory Function

This commit is contained in:
NW
2024-12-13 16:41:41 +00:00
parent 3e78e231f3
commit 95d5fe644d
4 changed files with 121 additions and 140 deletions

View File

@@ -12,26 +12,36 @@ class ProductService {
static async getDetailedProductById(productId) {
return await db.getAsync(
`SELECT p.*, c.name as category_name, s.name as subcategory_name
FROM products p
JOIN categories c ON p.category_id = c.id
JOIN subcategories s ON p.subcategory_id = s.id
WHERE p.id = ?`,
`SELECT p.*, c.name as category_name
FROM products p
JOIN categories c ON p.category_id = c.id
WHERE p.id = ?`,
[productId]
);
}
static async getProductsByLocationAndCategory(locationId, categoryId, subcategoryId) {
static async getProductsByLocationAndCategory(locationId, categoryId) {
return await db.allAsync(
`SELECT id, name, price, description, quantity_in_stock, photo_url
FROM products
WHERE location_id = ? AND category_id = ? AND subcategory_id = ?
AND quantity_in_stock > 0
ORDER BY name`,
[locationId, categoryId, subcategoryId]
FROM products
WHERE location_id = ? AND category_id = ?
AND quantity_in_stock > 0
ORDER BY name`,
[locationId, categoryId]
);
}
static async getProductsByCategoryId(categoryId) {
return await db.allAsync(
`SELECT id, name, price, description, quantity_in_stock, photo_url
FROM products
WHERE category_id = ?
AND quantity_in_stock > 0
ORDER BY name`,
[categoryId]
);
}
}
export default ProductService