u
This commit is contained in:
63
src/store/shipment/helpers.js
Normal file
63
src/store/shipment/helpers.js
Normal file
@@ -0,0 +1,63 @@
|
||||
import * as mssqlShipmentQueries from '../../providers/mssql/queries/shipment.js';
|
||||
import * as sqliteShipmentQueries from '../../providers/sqlite3/queries/shipment.js';
|
||||
import * as mssqlDocQueries from '../../providers/mssql/queries/manifestDoc.js';
|
||||
import * as sqliteDocQueries from '../../providers/sqlite3/queries/manifestDoc.js';
|
||||
import * as mssqlLogisticsQueries from '../../providers/mssql/queries/logistics.js';
|
||||
import * as sqliteLogisticsQueries from '../../providers/sqlite3/queries/logistics.js';
|
||||
import { shapeLine } from '../manifestLines.js';
|
||||
|
||||
export function queriesFor(provider) {
|
||||
const isSqlite = provider?.dialect === 'sqlite3';
|
||||
return {
|
||||
...(isSqlite ? sqliteShipmentQueries : mssqlShipmentQueries),
|
||||
CREATE_MANIFEST: isSqlite
|
||||
? sqliteDocQueries.CREATE_MANIFEST
|
||||
: mssqlDocQueries.CREATE_MANIFEST,
|
||||
GET_MANIFEST_LINES: isSqlite
|
||||
? sqliteDocQueries.GET_MANIFEST_LINES
|
||||
: mssqlDocQueries.GET_MANIFEST_LINES,
|
||||
SHIPPING_LIST_BY_MANIFEST: isSqlite
|
||||
? sqliteLogisticsQueries.SHIPPING_LIST_BY_MANIFEST
|
||||
: mssqlLogisticsQueries.SHIPPING_LIST_BY_MANIFEST,
|
||||
};
|
||||
}
|
||||
|
||||
export function shapeShipping(row) {
|
||||
return {
|
||||
id: row.id,
|
||||
manifestId: row.manifest_id ?? row.manifestId,
|
||||
number: row.number,
|
||||
trackingCode: row.tracking_code ?? row.trackingCode ?? null,
|
||||
carrier: row.carrier ?? null,
|
||||
type: row.type,
|
||||
state: row.state,
|
||||
};
|
||||
}
|
||||
|
||||
export async function loadShipment(runner, q, companyId, id) {
|
||||
const headerRes = await runner.query(q.GET_SHIPMENT_HEADER, { id, companyId });
|
||||
const row = headerRes.rows[0];
|
||||
if (!row) return null;
|
||||
|
||||
const [linesRes, shippingsRes] = await Promise.all([
|
||||
runner.query(q.GET_MANIFEST_LINES, { manifestId: id }),
|
||||
runner.query(q.SHIPPING_LIST_BY_MANIFEST, { manifestId: id }),
|
||||
]);
|
||||
|
||||
const lines = linesRes.rows.map(shapeLine);
|
||||
const shippings = shippingsRes.rows.map(shapeShipping);
|
||||
|
||||
return {
|
||||
id: row.id,
|
||||
number: row.number,
|
||||
type: 'shipment',
|
||||
entityId: row.entityId ?? null,
|
||||
externalNumber: row.externalNumber ?? null,
|
||||
date: row.date,
|
||||
createdAt: row.createdAt ?? null,
|
||||
lineCount: lines.length,
|
||||
packageCount: shippings.length,
|
||||
lines,
|
||||
shippings,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user