repair: brand + errorcode

This commit is contained in:
2025-12-05 18:18:50 +07:00
parent dc7712a79f
commit 555a68e90c
7 changed files with 151 additions and 359 deletions

View File

@@ -29,7 +29,7 @@ class BrandController {
res.status(response.statusCode).json(response);
}
// Create brand with nested error codes and solutions
// Create brand
static async create(req, res) {
const { error, value } = await checkValidate(insertBrandSchema, req);
@@ -39,7 +39,7 @@ class BrandController {
value.created_by = req.user?.user_id || null;
const results = await BrandService.createBrandWithFullData(value);
const results = await BrandService.createBrand(value);
const response = await setResponse(results, 'Brand created successfully');
return res.status(response.statusCode).json(response);
@@ -49,29 +49,15 @@ class BrandController {
static async update(req, res) {
const { id } = req.params;
// Debug logging untuk lihat request body
console.log('🔍 BE Raw Request Body:', req.body);
console.log('🔍 BE Request Headers:', req.headers);
console.log('🔍 BE Request Method:', req.method);
const { error, value } = await checkValidate(updateBrandSchema, req);
if (error) {
console.log('❌ BE Validation Error:', {
error,
details: error.details?.map(d => ({
field: d.path.join('.'),
message: d.message,
value: d.context?.value
})),
requestBody: req.body
});
return res.status(400).json(setResponse(error, 'Validation failed', 400));
}
value.updated_by = req.user?.user_id || null;
const results = await BrandService.updateBrandWithFullData(id, value);
const results = await BrandService.updateBrand(id, value);
const response = await setResponse(results, 'Brand updated successfully');
res.status(response.statusCode).json(response);

View File

@@ -1,5 +1,9 @@
const ErrorCodeService = require('../services/error_code.service');
const { setResponse, setResponsePaging } = require('../helpers/utils');
const { setResponse, setResponsePaging, checkValidate } = require('../helpers/utils');
const {
insertErrorCodeSchema,
updateErrorCodeSchema,
} = require('../validate/error_code.schema');
class ErrorCodeController {
static async getByBrandId(req, res) {
@@ -23,15 +27,16 @@ class ErrorCodeController {
// Create error code with solutions and spareparts
static async create(req, res) {
const { error, value } = await checkValidate(insertErrorCodeSchema, req);
if (error) {
return res.status(400).json(setResponse(error, 'Validation failed', 400));
}
const { brandId } = req.params;
const createdBy = req.user?.user_id || null;
value.created_by = req.user?.user_id || null;
const data = {
...req.body,
created_by: createdBy
};
const result = await ErrorCodeService.createErrorCodeWithFullData(brandId, data);
const result = await ErrorCodeService.createErrorCodeWithFullData(brandId, value);
const response = setResponse(result, 'Error code created successfully');
res.status(response.statusCode).json(response);
@@ -39,15 +44,16 @@ class ErrorCodeController {
// Update error code with solutions and spareparts
static async update(req, res) {
const { brandId, errorCode } = req.params;
const updatedBy = req.user?.user_id || null;
const { error, value } = await checkValidate(updateErrorCodeSchema, req);
const data = {
...req.body,
updated_by: updatedBy
};
if (error) {
return res.status(400).json(setResponse(error, 'Validation failed', 400));
}
const result = await ErrorCodeService.updateErrorCodeWithFullData(brandId, errorCode, data);
const { brandId, errorCodeId } = req.params;
value.updated_by = req.user?.user_id || null;
const result = await ErrorCodeService.updateErrorCodeWithFullData(brandId, errorCodeId, value);
const response = setResponse(result, 'Error code updated successfully');
res.status(response.statusCode).json(response);
@@ -55,10 +61,10 @@ class ErrorCodeController {
// Soft delete error code
static async delete(req, res) {
const { brandId, errorCode } = req.params;
const { brandId, errorCodeId } = req.params;
const deletedBy = req.user?.user_id || null;
const result = await ErrorCodeService.deleteErrorCode(brandId, errorCode, deletedBy);
const result = await ErrorCodeService.deleteErrorCode(brandId, errorCodeId, deletedBy);
const response = setResponse(result, 'Error code deleted successfully');
res.status(response.statusCode).json(response);