Files
dashlibstorage/src/store/supplier/ensureLieferantenGroup.js
seb c290fe8f4b Add customergroup sort with bulk order and locked implicit names.
Reorder via customergroup.order (exact id list → sort 0…n-1); block renaming POS/Lieferanten while still allowing create/update of other groups by name.
2026-08-07 03:38:01 +02:00

34 lines
884 B
JavaScript

import {
CREATE,
GET_BY_COMPANY_AND_NAME,
GET_NEXT_SORT,
} from '../../sql/customergroup.js';
import { SUPPLIER_GROUP_NAME } from '../../sql/entity.js';
/** Ensure company has customergroup "Lieferanten"; return its id. */
export default async function ensureLieferantenGroup(pool, companyId, tx) {
const req = () => (tx ?? pool).request();
const existing = await req()
.input('companyId', companyId)
.input('name', SUPPLIER_GROUP_NAME)
.query(GET_BY_COMPANY_AND_NAME);
if (existing.recordset[0]) {
return existing.recordset[0].id;
}
const next = await req()
.input('companyId', companyId)
.query(GET_NEXT_SORT);
const sort = next.recordset[0].sort;
const created = await req()
.input('companyId', companyId)
.input('name', SUPPLIER_GROUP_NAME)
.input('sort', sort)
.query(CREATE);
return created.recordset[0].id;
}