repair get error code by brandId
This commit is contained in:
@@ -17,7 +17,7 @@ const getSparepartsByErrorCodeIdDb = async (errorCodeId) => {
|
||||
s.sparepart_stok,
|
||||
bs.created_at,
|
||||
bs.created_by
|
||||
FROM brand_spareparts bs
|
||||
FROM brand_sparepart bs
|
||||
JOIN m_sparepart s ON bs.sparepart_id = s.sparepart_id
|
||||
WHERE bs.error_code_id = $1
|
||||
AND s.deleted_at IS NULL
|
||||
@@ -40,7 +40,7 @@ const getErrorCodesBySparepartIdDb = async (sparepartId) => {
|
||||
ec.is_active,
|
||||
ec.created_at,
|
||||
ec.updated_at
|
||||
FROM brand_spareparts bs
|
||||
FROM brand_sparepart bs
|
||||
JOIN m_error_codes ec ON bs.error_code_id = ec.error_code_id
|
||||
WHERE bs.sparepart_id = $1
|
||||
AND ec.deleted_at IS NULL
|
||||
@@ -53,7 +53,7 @@ const getErrorCodesBySparepartIdDb = async (sparepartId) => {
|
||||
// Insert error_code-spareparts relationship
|
||||
const insertErrorCodeSparepartDb = async (errorCodeId, sparepartId, createdBy) => {
|
||||
const queryText = `
|
||||
INSERT INTO brand_spareparts (error_code_id, sparepart_id, created_by, created_at)
|
||||
INSERT INTO brand_sparepart (error_code_id, sparepart_id, created_by, created_at)
|
||||
VALUES ($1, $2, $3, CURRENT_TIMESTAMP)
|
||||
`;
|
||||
const result = await pool.query(queryText, [errorCodeId, sparepartId, createdBy]);
|
||||
@@ -66,7 +66,7 @@ const insertMultipleErrorCodeSparepartsDb = async (errorCodeId, sparepartIds, cr
|
||||
|
||||
const values = sparepartIds.map((_, index) => `($1, $${index + 2}, $${sparepartIds.length + 2}, CURRENT_TIMESTAMP)`).join(', ');
|
||||
const queryText = `
|
||||
INSERT INTO brand_spareparts (error_code_id, sparepart_id, created_by, created_at)
|
||||
INSERT INTO brand_sparepart (error_code_id, sparepart_id, created_by, created_at)
|
||||
VALUES ${values}
|
||||
`;
|
||||
const params = [errorCodeId, ...sparepartIds, createdBy];
|
||||
@@ -77,7 +77,7 @@ const insertMultipleErrorCodeSparepartsDb = async (errorCodeId, sparepartIds, cr
|
||||
// Delete specific error_code-sparepart relationship
|
||||
const deleteErrorCodeSparepartDb = async (errorCodeId, sparepartId) => {
|
||||
const queryText = `
|
||||
DELETE FROM brand_spareparts
|
||||
DELETE FROM brand_sparepart
|
||||
WHERE error_code_id = $1 AND sparepart_id = $2
|
||||
`;
|
||||
const result = await pool.query(queryText, [errorCodeId, sparepartId]);
|
||||
@@ -87,7 +87,7 @@ const deleteErrorCodeSparepartDb = async (errorCodeId, sparepartId) => {
|
||||
// Delete all spareparts for an error_code
|
||||
const deleteAllErrorCodeSparepartsDb = async (errorCodeId) => {
|
||||
const queryText = `
|
||||
DELETE FROM brand_spareparts
|
||||
DELETE FROM brand_sparepart
|
||||
WHERE error_code_id = $1
|
||||
`;
|
||||
const result = await pool.query(queryText, [errorCodeId]);
|
||||
@@ -107,7 +107,6 @@ const updateErrorCodeSparepartsDb = async (errorCodeId, sparepartIds, updatedBy)
|
||||
return true;
|
||||
};
|
||||
|
||||
// Check if error_code-sparepart relationship exists
|
||||
const checkErrorCodeSparepartExistsDb = async (errorCodeId, sparepartId) => {
|
||||
const queryText = `
|
||||
SELECT 1
|
||||
@@ -118,8 +117,6 @@ const checkErrorCodeSparepartExistsDb = async (errorCodeId, sparepartId) => {
|
||||
return result.recordset.length > 0;
|
||||
};
|
||||
|
||||
// Legacy functions for backward compatibility (deprecated)
|
||||
// Get spareparts by brand_id (now using error_code_id mapping via error codes)
|
||||
const getSparepartsByBrandIdDb = async (brandId) => {
|
||||
const queryText = `
|
||||
SELECT DISTINCT
|
||||
@@ -136,7 +133,7 @@ const getSparepartsByBrandIdDb = async (brandId) => {
|
||||
s.sparepart_stok,
|
||||
s.created_at,
|
||||
s.updated_at
|
||||
FROM brand_spareparts bs
|
||||
FROM brand_sparepart bs
|
||||
JOIN m_sparepart s ON bs.sparepart_id = s.sparepart_id
|
||||
JOIN m_error_codes ec ON bs.error_code_id = ec.error_code_id
|
||||
WHERE ec.brand_id = $1
|
||||
@@ -161,7 +158,7 @@ const getBrandsBySparepartIdDb = async (sparepartId) => {
|
||||
b.is_active,
|
||||
b.created_at,
|
||||
b.updated_at
|
||||
FROM brand_spareparts bs
|
||||
FROM brand_sparepart bs
|
||||
JOIN m_sparepart s ON bs.sparepart_id = s.sparepart_id
|
||||
JOIN m_error_codes ec ON bs.error_code_id = ec.error_code_id
|
||||
JOIN m_brands b ON ec.brand_id = b.brand_id
|
||||
|
||||
Reference in New Issue
Block a user