Add product composition export
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m16s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m16s
This commit is contained in:
@@ -699,9 +699,8 @@ const mapProductCompositionRow = (row) => ({
|
||||
})) : []
|
||||
});
|
||||
|
||||
const getProductComposition = async (productId, client = pool) => {
|
||||
const findProductCompositions = async (productId, client = pool) => {
|
||||
const identity = normalizeText(productId);
|
||||
if (!identity) return null;
|
||||
|
||||
const result = await client.query(`
|
||||
SELECT
|
||||
@@ -751,15 +750,22 @@ const getProductComposition = async (productId, client = pool) => {
|
||||
FROM product_compositions composition
|
||||
WHERE composition.source = $1
|
||||
AND (
|
||||
composition.finished_tiny_product_id = $2
|
||||
$2 = ''
|
||||
OR composition.finished_tiny_product_id = $2
|
||||
OR composition.finished_product_sku = UPPER($2)
|
||||
)
|
||||
LIMIT 1;
|
||||
ORDER BY composition.finished_product_sku, composition.finished_product_description;
|
||||
`, [TINY_OLIST_V3_COMPOSITION_SOURCE, identity]);
|
||||
|
||||
return result.rows[0] ? mapProductCompositionRow(result.rows[0]) : null;
|
||||
return result.rows.map(mapProductCompositionRow);
|
||||
};
|
||||
|
||||
const getProductComposition = async (productId, client = pool) => (
|
||||
(await findProductCompositions(productId, client))[0] || null
|
||||
);
|
||||
|
||||
const listProductCompositions = async (client = pool) => findProductCompositions('', client);
|
||||
|
||||
const upsertTinyProductComposition = async (order, components) => {
|
||||
const finishedTinyProductId = getTinyProductIdFromCompositionReference(order.tinyId);
|
||||
const finishedProductSku = normalizeSku(order.productSku);
|
||||
@@ -1051,6 +1057,7 @@ const updateProductionOrderStatus = async (id, status) => {
|
||||
module.exports = {
|
||||
createProductionOrders,
|
||||
getProductComposition,
|
||||
listProductCompositions,
|
||||
listProductionOrders,
|
||||
normalizeStatus,
|
||||
upsertTinyProductionOrderDetail,
|
||||
|
||||
Reference in New Issue
Block a user