This commit is contained in:
seb
2026-07-31 05:43:41 +02:00
parent 09c7a8bc74
commit a57e81fe30
9 changed files with 204 additions and 122 deletions

View File

@@ -1,13 +1,8 @@
import companyuserGetByEmail from './store/companyuser/getByEmail.js';
import companyuserAdd from './store/companyuser/add.js';
import companyuserDelete from './store/companyuser/delete.js';
import companyGetByCompanyUserId from './store/company/getByCompanyUserId.js';
import companyGetById from './store/company/getById.js';
import companyGetByName from './store/company/getByName.js';
import companyCreate from './store/company/create.js';
import companyUpdate from './store/company/update.js';
import companySetDefaultLang from './store/company/setDefaultLang.js';
import companySetRootCategory from './store/company/setRootCategory.js';
import companyDelete from './store/company/delete.js';
import companyList from './store/company/list.js';
import categoryGetTree from './store/category/getTree.js';
@@ -43,13 +38,8 @@ export default class LibDashStore {
};
this.company = {
getByCompanyUserId: companyGetByCompanyUserId(pool),
getById: companyGetById(pool),
getByName: companyGetByName(pool),
create: companyCreate(pool),
update: companyUpdate(pool),
setDefaultLang: companySetDefaultLang(pool),
setRootCategory: companySetRootCategory(pool),
delete: companyDelete(pool),
list: companyList(pool),
};

View File

@@ -1,14 +1,3 @@
export const GET_BY_COMPANY_USER_ID = `
SELECT
c.id,
c.default_language_id,
c.root_category_id,
c.name
FROM company c
INNER JOIN companyuser cu ON cu.company_id = c.id
WHERE cu.id = @companyUserId
`;
export const GET_BY_NAME = `
SELECT id, name, root_category_id, default_language_id, taxrate, reducedtaxrate, taxfreerate
FROM company
@@ -52,22 +41,16 @@ WHERE id = @id
`;
export const LIST = `
SELECT id, name, root_category_id, default_language_id, taxrate, reducedtaxrate, taxfreerate
SELECT
id,
root_category_id,
default_language_id AS language_id,
taxrate,
reducedtaxrate,
taxfreerate
FROM company
`;
export const SET_DEFAULT_LANG = `
UPDATE company
SET default_language_id = @languageId
WHERE id = @companyId
`;
export const SET_ROOT_CATEGORY = `
UPDATE company
SET root_category_id = @categoryId
WHERE id = @companyId
`;
export const DELETE = `
DELETE FROM company
WHERE id = @companyId

View File

@@ -43,7 +43,15 @@ export default function create(pool) {
.query(CREATE);
await tx.commit();
return result.recordset[0].id;
return {
id: result.recordset[0].id,
root_category_id: rootCategoryId,
language_id: languageId,
taxrate: taxrateId,
reducedtaxrate: reducedtaxrateId,
taxfreerate: taxfreerateId,
};
} catch (err) {
try {
await tx.rollback();

View File

@@ -1,16 +0,0 @@
import sql from 'mssql';
import { GET_BY_COMPANY_USER_ID } from '../../sql/company.js';
export default function getByCompanyUserId(pool) {
return async (companyUserId) => {
const result = await pool
.request()
.input('companyUserId', sql.Int, companyUserId)
.query(GET_BY_COMPANY_USER_ID);
const row = result.recordset[0];
if (!row) return;
return [row.id, row.default_language_id, row.root_category_id, row.name];
};
}

View File

@@ -1,12 +0,0 @@
import sql from 'mssql';
import { SET_DEFAULT_LANG } from '../../sql/company.js';
export default function setDefaultLang(pool) {
return async (companyId, languageId) => {
await pool
.request()
.input('companyId', sql.Int, companyId)
.input('languageId', sql.Int, languageId)
.query(SET_DEFAULT_LANG);
};
}

View File

@@ -1,12 +0,0 @@
import sql from 'mssql';
import { SET_ROOT_CATEGORY } from '../../sql/company.js';
export default function setRootCategory(pool) {
return async (companyId, categoryId) => {
await pool
.request()
.input('companyId', sql.Int, companyId)
.input('categoryId', sql.Int, categoryId)
.query(SET_ROOT_CATEGORY);
};
}

View File

@@ -42,6 +42,15 @@ export default function update(pool) {
.query(UPDATE);
await tx.commit();
return {
id,
root_category_id: company.root_category_id,
language_id: languageId,
taxrate: taxrateId,
reducedtaxrate: reducedtaxrateId,
taxfreerate: company.taxfreerate,
};
} catch (err) {
try {
await tx.rollback();