fix: brand api

This commit is contained in:
2025-10-26 18:26:22 +07:00
parent 2fa263e9e4
commit 409e2d3750
6 changed files with 83 additions and 112 deletions

View File

@@ -4,7 +4,6 @@ const { createFileUploadDb } = require('../db/file_uploads.db');
const {
insertBrandSchema,
updateBrandSchema,
uploadSolutionSchema
} = require('../validate/brand.schema');
class BrandController {
@@ -23,6 +22,9 @@ class BrandController {
const { id } = req.params;
const results = await BrandService.getBrandById(id);
// console.log('Brand response structure:', JSON.stringify(results, null, 2));
const response = await setResponse(results, 'Brand found');
res.status(response.statusCode).json(response);
@@ -98,14 +100,8 @@ class BrandController {
// Soft delete brand by ID
static async delete(req, res) {
const { id } = req.params;
// Get brand by ID first to get name for deletion
const brand = await BrandService.getBrandById(id);
if (!brand) {
const response = await setResponse([], 'Brand not found', 404);
return res.status(response.statusCode).json(response);
}
const results = await BrandService.deleteBrand(brand.brand_name, req.user.user_id);
const results = await BrandService.deleteBrand(id, req.user.user_id);
const response = await setResponse(results, 'Brand deleted successfully');
res.status(response.statusCode).json(response);