This commit is contained in:
seb
2026-08-07 05:21:56 +02:00
parent 70e0a9ddc4
commit 396389457f
22 changed files with 225 additions and 242 deletions

View File

@@ -11,29 +11,34 @@ import langEnsure from '../lang/ensure.js';
import taxEnsure from '../tax/ensure.js';
import request from '../request.js';
/**
* Creates a new company together with its root category, POS customer group,
* default language and tax rates, and links it to the given Google auth user.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that creates a company.
*
* @example
* const fn = create(pool);
* const company = await fn({
* iso639: 'de',
* name: 'Acme',
* taxrate: 19,
* reducedtaxrate: 7,
* googleAuthId: 42,
* });
* // => { id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId, posCustomerGroupId }
*/
export default function create(pool) {
const nameTaken = getByName(pool);
const ensureLang = langEnsure(pool);
const ensureTax = taxEnsure(pool);
/**
* Creates a new company together with its root category, POS customer group,
* default language and tax rates, and links it to the given Google auth user.
*
* @param {object} input - The company creation input.
* @param {string} input.iso639 - The ISO 639 language code for the company.
* @param {string} input.name - The company name (must be unique).
* @param {number} input.taxrate - The standard tax rate in percent.
* @param {number} input.reducedtaxrate - The reduced tax rate in percent.
* @param {number} input.googleAuthId - The id of the Google auth user to link.
* @returns {Promise<{id: number, rootCategoryId: number, languageId: number, taxrateId: number, reducedtaxrateId: number, taxfreerateId: number, posCustomerGroupId: number}>} The created company ids.
* @throws {Error} If the company name is already taken.
*
* @example
* const company = await store.company.create({
* iso639: 'de',
* name: 'Acme',
* taxrate: 19,
* reducedtaxrate: 7,
* googleAuthId: 42,
* });
* // => { id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId, posCustomerGroupId }
*/
return async ({ iso639, name, taxrate, reducedtaxrate, googleAuthId }) => {
const tx = pool.transaction();
await tx.begin();