wisdom #19

Merged
bragaz_rexita merged 38 commits from wisdom into main 2025-12-22 09:18:18 +00:00
2 changed files with 3 additions and 41 deletions
Showing only changes of commit 867976030a - Show all commits

View File

@@ -108,13 +108,8 @@ const getAllErrorCodesDb = async (searchParams = {}) => {
const queryText = `
SELECT
COUNT(*) OVER() AS total_data,
a.*,
b.brand_name,
b.brand_type,
b.brand_manufacture,
b.brand_model
a.*
FROM brand_code a
LEFT JOIN m_brands b ON a.brand_id = b.brand_id
WHERE a.deleted_at IS NULL
${whereConditions.length > 0 ? `AND ${whereConditions.join(' AND ')}` : ''}
${whereOrConditions ? whereOrConditions : ''}

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);
}