u
This commit is contained in:
@@ -9,7 +9,13 @@ import {
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
const DEFAULT_TYPES = ['sku', 'entity', 'delivery', 'adjustment'];
|
||||
const DEFAULT_TYPES = [
|
||||
{ type: 'sku', prefix: '' },
|
||||
{ type: 'entity', prefix: '' },
|
||||
{ type: 'delivery', prefix: '' },
|
||||
{ type: 'adjustment', prefix: '' },
|
||||
{ type: 'shipment', prefix: '-L-' },
|
||||
];
|
||||
|
||||
function shape(row) {
|
||||
return {
|
||||
@@ -30,7 +36,7 @@ export default function list(provider) {
|
||||
|
||||
/**
|
||||
* Lists the number sequences of the user's selected company.
|
||||
* Ensures that default sequences ('sku', 'entity', 'delivery') exist.
|
||||
* Ensures that default sequences ('sku', 'entity', 'delivery', 'adjustment', 'shipment') exist.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
@@ -44,8 +50,10 @@ export default function list(provider) {
|
||||
const { companyId } = await access(googleAuthId, tx);
|
||||
const runner = makeRunner(provider, tx);
|
||||
|
||||
for (const type of DEFAULT_TYPES) {
|
||||
await runner.query(ensureSql, { companyId, type });
|
||||
for (const item of DEFAULT_TYPES) {
|
||||
const type = typeof item === 'string' ? item : item.type;
|
||||
const prefix = typeof item === 'string' ? (type === 'shipment' ? '-L-' : '') : item.prefix;
|
||||
await runner.query(ensureSql, { companyId, type, prefix });
|
||||
}
|
||||
|
||||
const result = await runner.query(sql, { companyId });
|
||||
|
||||
@@ -37,7 +37,8 @@ export default function nextNumber(provider) {
|
||||
*/
|
||||
return async (companyId, type, tx) => {
|
||||
const doAlloc = async (runner) => {
|
||||
await runner.query(ensureSql, { companyId, type });
|
||||
const prefix = type === 'shipment' ? '-L-' : '';
|
||||
await runner.query(ensureSql, { companyId, type, prefix });
|
||||
const res = await runner.query(getSql, { companyId, type });
|
||||
const row = res.rows[0];
|
||||
if (!row) {
|
||||
|
||||
Reference in New Issue
Block a user