repair: get error code

This commit is contained in:
2025-12-02 15:58:06 +07:00
parent 790b949302
commit 867976030a
2 changed files with 3 additions and 41 deletions

View File

@@ -25,45 +25,12 @@ const {
const { getFileUploadByPathDb } = require("../db/file_uploads.db");
class ErrorCodeService {
// Get all error codes with pagination and search
// Get all error codes with pagination and search (without solutions and spareparts)
static async getAllErrorCodes(param) {
try {
const results = await getAllErrorCodesDb(param);
// Enhance with solutions and spareparts for each error code
const errorCodesWithDetails = await Promise.all(
results.data.map(async (errorCode) => {
const solutions = await getSolutionsByErrorCodeIdDb(errorCode.error_code_id);
const spareparts = await getSparepartsByErrorCodeIdDb(errorCode.error_code_id);
const solutionsWithFiles = await Promise.all(
solutions.map(async (solution) => {
let fileData = null;
if (solution.path_solution && solution.type_solution !== "text") {
fileData = await getFileUploadByPathDb(solution.path_solution);
}
return {
...solution,
file_upload_name: fileData?.file_upload_name || null,
path_document: fileData?.path_document || null,
};
})
);
return {
...errorCode,
solution: solutionsWithFiles,
spareparts: spareparts,
};
})
);
return {
...results,
data: errorCodesWithDetails,
};
return results;
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
}