u
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
import { CREATE } from '../../sql/company.js';
|
||||
import { CREATE as CREATE_CATEGORY } from '../../sql/category.js';
|
||||
import {
|
||||
CREATE_WITHOUT_COMPANY as CREATE_CUSTOMERGROUP,
|
||||
SET_COMPANY as SET_CUSTOMERGROUP_COMPANY,
|
||||
} from '../../sql/customergroup.js';
|
||||
import { ADD as ADD_COMPANYUSER } from '../../sql/companyuser.js';
|
||||
import getByName from './getByName.js';
|
||||
import langEnsure from '../lang/ensure.js';
|
||||
import taxEnsure from '../tax/ensure.js';
|
||||
import request from '../request.js';
|
||||
|
||||
const POS_CUSTOMERGROUP_NAME = 'POS';
|
||||
|
||||
export default function create(pool) {
|
||||
const nameTaken = getByName(pool);
|
||||
const ensureLang = langEnsure(pool);
|
||||
@@ -33,6 +39,14 @@ export default function create(pool) {
|
||||
|
||||
const rootCategoryId = category.recordset[0].id;
|
||||
|
||||
// Circular FK: create POS group first (company_id null), company with
|
||||
// poscustomergroup_id NOT NULL, then link the group back to the company.
|
||||
const posGroup = await request(pool, tx)
|
||||
.input('name', POS_CUSTOMERGROUP_NAME)
|
||||
.query(CREATE_CUSTOMERGROUP);
|
||||
|
||||
const posCustomerGroupId = posGroup.recordset[0].id;
|
||||
|
||||
const result = await request(pool, tx)
|
||||
.input('name', name)
|
||||
.input('rootCategoryId', rootCategoryId)
|
||||
@@ -40,10 +54,16 @@ export default function create(pool) {
|
||||
.input('taxrate', taxrateId)
|
||||
.input('reducedtaxrate', reducedtaxrateId)
|
||||
.input('taxfreerate', taxfreerateId)
|
||||
.input('posCustomerGroupId', posCustomerGroupId)
|
||||
.query(CREATE);
|
||||
|
||||
const companyId = result.recordset[0].id;
|
||||
|
||||
await request(pool, tx)
|
||||
.input('id', posCustomerGroupId)
|
||||
.input('companyId', companyId)
|
||||
.query(SET_CUSTOMERGROUP_COMPANY);
|
||||
|
||||
await request(pool, tx)
|
||||
.input('companyId', companyId)
|
||||
.input('googleAuthId', googleAuthId)
|
||||
@@ -58,6 +78,7 @@ export default function create(pool) {
|
||||
taxrateId,
|
||||
reducedtaxrateId,
|
||||
taxfreerateId,
|
||||
posCustomerGroupId,
|
||||
};
|
||||
} catch (err) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user