repair: get error code
This commit is contained in:
@@ -108,13 +108,8 @@ const getAllErrorCodesDb = async (searchParams = {}) => {
|
|||||||
const queryText = `
|
const queryText = `
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(*) OVER() AS total_data,
|
COUNT(*) OVER() AS total_data,
|
||||||
a.*,
|
a.*
|
||||||
b.brand_name,
|
|
||||||
b.brand_type,
|
|
||||||
b.brand_manufacture,
|
|
||||||
b.brand_model
|
|
||||||
FROM brand_code a
|
FROM brand_code a
|
||||||
LEFT JOIN m_brands b ON a.brand_id = b.brand_id
|
|
||||||
WHERE a.deleted_at IS NULL
|
WHERE a.deleted_at IS NULL
|
||||||
${whereConditions.length > 0 ? `AND ${whereConditions.join(' AND ')}` : ''}
|
${whereConditions.length > 0 ? `AND ${whereConditions.join(' AND ')}` : ''}
|
||||||
${whereOrConditions ? whereOrConditions : ''}
|
${whereOrConditions ? whereOrConditions : ''}
|
||||||
|
|||||||
@@ -25,45 +25,12 @@ const {
|
|||||||
const { getFileUploadByPathDb } = require("../db/file_uploads.db");
|
const { getFileUploadByPathDb } = require("../db/file_uploads.db");
|
||||||
|
|
||||||
class ErrorCodeService {
|
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) {
|
static async getAllErrorCodes(param) {
|
||||||
try {
|
try {
|
||||||
const results = await getAllErrorCodesDb(param);
|
const results = await getAllErrorCodesDb(param);
|
||||||
|
|
||||||
// Enhance with solutions and spareparts for each error code
|
return results;
|
||||||
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,
|
|
||||||
};
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new ErrorHandler(error.statusCode, error.message);
|
throw new ErrorHandler(error.statusCode, error.message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user