diff --git a/db/brand_code.db.js b/db/brand_code.db.js index 1a0e3e3..7220adc 100644 --- a/db/brand_code.db.js +++ b/db/brand_code.db.js @@ -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 : ''} diff --git a/services/error_code.service.js b/services/error_code.service.js index c8f03ba..4197d32 100644 --- a/services/error_code.service.js +++ b/services/error_code.service.js @@ -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); }