Add supplier CRUD on entity with Lieferanten group and entityhistory
This commit is contained in:
26
src/store/supplier/ensureLieferantenGroup.js
Normal file
26
src/store/supplier/ensureLieferantenGroup.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import {
|
||||
CREATE,
|
||||
GET_BY_COMPANY_AND_NAME,
|
||||
} 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 created = await req()
|
||||
.input('companyId', companyId)
|
||||
.input('name', SUPPLIER_GROUP_NAME)
|
||||
.query(CREATE);
|
||||
|
||||
return created.recordset[0].id;
|
||||
}
|
||||
Reference in New Issue
Block a user