add: error_code api

This commit is contained in:
2025-12-02 15:22:20 +07:00
parent feff905d8f
commit f797685a4f
6 changed files with 488 additions and 55 deletions

View File

@@ -51,66 +51,13 @@ class BrandService {
}
}
// Get brand by ID with complete data
// Get brand by ID (without error codes)
static async getBrandById(id) {
try {
const brand = await getBrandByIdDb(id);
if (!brand) throw new ErrorHandler(404, "Brand not found");
const errorCodes = await getErrorCodesByBrandIdDb(brand.brand_id);
const errorCodesWithSolutionsAndSpareparts = await Promise.all(
errorCodes.map(async (errorCode) => {
const solutions = await getSolutionsByErrorCodeIdDb(
errorCode.error_code_id
);
// Get spareparts for this error code
const errorCodeSpareparts = await getSparepartsByErrorCodeIdDb(errorCode.error_code_id);
const solutionsWithFiles = await Promise.all(
solutions.map(async (solution) => {
let fileData = null;
// console.log('Processing solution:', {
// solution_id: solution.brand_code_solution_id,
// path_solution: solution.path_solution,
// type_solution: solution.type_solution
// });
if (solution.path_solution && solution.type_solution !== "text") {
fileData = await getFileUploadByPathDb(solution.path_solution);
console.log("File data found:", fileData);
}
const enhancedSolution = {
...solution,
file_upload_name: fileData?.file_upload_name || null,
path_document: fileData?.path_document || null,
};
// console.log('Enhanced solution:', {
// solution_id: enhancedSolution.brand_code_solution_id,
// original_path_solution: enhancedSolution.path_solution,
// path_document: enhancedSolution.path_document,
// file_upload_name: enhancedSolution.file_upload_name
// });
return enhancedSolution;
})
);
return {
...errorCode,
solution: solutionsWithFiles,
spareparts: errorCodeSpareparts,
};
})
);
return {
...brand,
error_code: errorCodesWithSolutionsAndSpareparts,
};
return brand;
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
}