This commit is contained in:
seb
2026-07-31 07:22:34 +02:00
parent 02bca8e236
commit bbd69e8c7c
29 changed files with 144 additions and 87 deletions

View File

@@ -1,6 +1,6 @@
import sql from 'mssql';
import { CREATE } from '../../sql/company.js';
import { CREATE as CREATE_CATEGORY } from '../../sql/category.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';
@@ -11,8 +11,8 @@ export default function create(pool) {
const ensureLang = langEnsure(pool);
const ensureTax = taxEnsure(pool);
return async ({ iso639, name, taxrate, reducedtaxrate }) => {
const tx = new sql.Transaction(pool);
return async ({ iso639, name, taxrate, reducedtaxrate, authId }) => {
const tx = pool.transaction();
await tx.begin();
try {
@@ -27,25 +27,32 @@ export default function create(pool) {
const taxfreerateId = await ensureTax(0, tx);
const category = await request(pool, tx)
.input('parentId', sql.Int, null)
.input('sort', sql.Int, 0)
.input('parentId', null)
.input('sort', 0)
.query(CREATE_CATEGORY);
const rootCategoryId = category.recordset[0].id;
const result = await request(pool, tx)
.input('name', sql.NVarChar(255), name)
.input('rootCategoryId', sql.Int, rootCategoryId)
.input('languageId', sql.Int, languageId)
.input('taxrate', sql.Int, taxrateId)
.input('reducedtaxrate', sql.Int, reducedtaxrateId)
.input('taxfreerate', sql.Int, taxfreerateId)
.input('name', name)
.input('rootCategoryId', rootCategoryId)
.input('languageId', languageId)
.input('taxrate', taxrateId)
.input('reducedtaxrate', reducedtaxrateId)
.input('taxfreerate', taxfreerateId)
.query(CREATE);
const companyId = result.recordset[0].id;
await request(pool, tx)
.input('companyId', companyId)
.input('authId', authId)
.query(ADD_COMPANYUSER);
await tx.commit();
return {
id: result.recordset[0].id,
id: companyId,
rootCategoryId,
languageId,
taxrateId,