mejoras en el modelo de clarificacion de productos
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { handleSearchProducts, handleListProducts, handleGetProduct, handleSyncProducts } from "../handlers/products.js";
|
||||
import { handleSearchProducts, handleListProducts, handleGetProduct, handleSyncProducts, handleUpdateProductUnit, handleBulkUpdateProductUnit, handleUpdateProduct } from "../handlers/products.js";
|
||||
|
||||
export const makeSearchProducts = (tenantIdOrFn) => async (req, res) => {
|
||||
try {
|
||||
@@ -54,3 +54,60 @@ export const makeSyncProducts = (tenantIdOrFn) => async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const makeUpdateProductUnit = (tenantIdOrFn) => async (req, res) => {
|
||||
try {
|
||||
const tenantId = typeof tenantIdOrFn === "function" ? tenantIdOrFn() : tenantIdOrFn;
|
||||
const wooProductId = req.params.id;
|
||||
const { sell_unit } = req.body || {};
|
||||
|
||||
if (!sell_unit || !["kg", "unit"].includes(sell_unit)) {
|
||||
return res.status(400).json({ ok: false, error: "invalid_sell_unit" });
|
||||
}
|
||||
|
||||
const result = await handleUpdateProductUnit({ tenantId, wooProductId, sell_unit });
|
||||
res.json(result);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).json({ ok: false, error: "internal_error" });
|
||||
}
|
||||
};
|
||||
|
||||
export const makeBulkUpdateProductUnit = (tenantIdOrFn) => async (req, res) => {
|
||||
try {
|
||||
const tenantId = typeof tenantIdOrFn === "function" ? tenantIdOrFn() : tenantIdOrFn;
|
||||
const { woo_product_ids, sell_unit } = req.body || {};
|
||||
|
||||
if (!sell_unit || !["kg", "unit"].includes(sell_unit)) {
|
||||
return res.status(400).json({ ok: false, error: "invalid_sell_unit" });
|
||||
}
|
||||
|
||||
if (!Array.isArray(woo_product_ids) || !woo_product_ids.length) {
|
||||
return res.status(400).json({ ok: false, error: "invalid_woo_product_ids" });
|
||||
}
|
||||
|
||||
const result = await handleBulkUpdateProductUnit({ tenantId, wooProductIds: woo_product_ids, sell_unit });
|
||||
res.json(result);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).json({ ok: false, error: "internal_error" });
|
||||
}
|
||||
};
|
||||
|
||||
export const makeUpdateProduct = (tenantIdOrFn) => async (req, res) => {
|
||||
try {
|
||||
const tenantId = typeof tenantIdOrFn === "function" ? tenantIdOrFn() : tenantIdOrFn;
|
||||
const wooProductId = req.params.id;
|
||||
const { sell_unit, categories } = req.body || {};
|
||||
|
||||
if (sell_unit && !["kg", "unit"].includes(sell_unit)) {
|
||||
return res.status(400).json({ ok: false, error: "invalid_sell_unit" });
|
||||
}
|
||||
|
||||
const result = await handleUpdateProduct({ tenantId, wooProductId, sell_unit, categories });
|
||||
res.json(result);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).json({ ok: false, error: "internal_error" });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user