u
This commit is contained in:
@@ -7,6 +7,7 @@ function shape(row) {
|
||||
return {
|
||||
id: row.id,
|
||||
manifestarticle_id: row.manifestarticle_id,
|
||||
warehouse_id: row.warehouse_id ?? null,
|
||||
sku: row.sku ?? null,
|
||||
transaction_type: row.transaction_type,
|
||||
amount: row.amount,
|
||||
@@ -21,18 +22,18 @@ function shape(row) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists ledger entries for a given article SKU, optionally filtered by transaction type.
|
||||
* Lists ledger entries for a given article SKU, optionally filtered by transaction type and/or warehouse.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {string} sku - The article SKU.
|
||||
* @param {string|object} [optionsOrType] - Transaction type string or options object { transaction_type?: string, transactionType?: string }.
|
||||
* @param {string|object} [optionsOrType] - Transaction type string or options object { transaction_type?: string, transactionType?: string, warehouse_id?: number, warehouseId?: number }.
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<Array<{id: number, manifestarticle_id: number, sku: string|null, transaction_type: string, amount: number, transaction_text: string, hash_version: number, prev_hash: string, created_at: string}>>}
|
||||
* @returns {Promise<Array<{id: number, manifestarticle_id: number, warehouse_id: number|null, sku: string|null, transaction_type: string, amount: number, transaction_text: string, hash_version: number, prev_hash: string, created_at: string}>>}
|
||||
* @throws {Error} If user not authorized, company not selected, or SKU invalid.
|
||||
*
|
||||
* @example
|
||||
* const entries = await store.ledger.listBySku(googleAuthId, 'SKU-001', 'DELIVERY');
|
||||
* // => [{ id, manifestarticle_id, sku, transaction_type, amount, transaction_text, hash_version, prev_hash, created_at }]
|
||||
* // => [{ id, manifestarticle_id, warehouse_id, sku, transaction_type, amount, transaction_text, hash_version, prev_hash, created_at }]
|
||||
*/
|
||||
export default function listBySku(provider) {
|
||||
const access = resolveSelectedCompanyAccess(provider);
|
||||
@@ -41,6 +42,7 @@ export default function listBySku(provider) {
|
||||
|
||||
return async (googleAuthId, sku, optionsOrType, tx) => {
|
||||
let transactionType = null;
|
||||
let warehouseId = null;
|
||||
let explicitTx = tx;
|
||||
|
||||
if (typeof optionsOrType === 'string') {
|
||||
@@ -54,6 +56,11 @@ export default function listBySku(provider) {
|
||||
if (typeof rawType === 'string') {
|
||||
transactionType = rawType.trim() || null;
|
||||
}
|
||||
const rawWarehouse =
|
||||
optionsOrType.warehouse_id ?? optionsOrType.warehouseId;
|
||||
if (rawWarehouse != null) {
|
||||
warehouseId = Number(rawWarehouse) || null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +76,7 @@ export default function listBySku(provider) {
|
||||
sku: trimmedSku,
|
||||
companyId,
|
||||
transactionType: transactionType || null,
|
||||
warehouseId: warehouseId || null,
|
||||
});
|
||||
|
||||
return res.rows.map(shape);
|
||||
|
||||
Reference in New Issue
Block a user