This commit is contained in:
seb
2026-10-19 23:56:56 +02:00
parent a5eee3f3d0
commit 4b34902b92
8 changed files with 15 additions and 37 deletions

View File

@@ -13,13 +13,11 @@ import {
} from '../../providers/sqlite3/queries/customergroup.js';
import { ADD as MSSQL_ADD_COMPANYUSER } from '../../providers/mssql/queries/companyuser.js';
import { ADD as SQLITE_ADD_COMPANYUSER } from '../../providers/sqlite3/queries/companyuser.js';
import getByName from './getByName.js';
import langEnsure from '../lang/ensure.js';
import taxEnsure from '../tax/ensure.js';
import makeRunner from '../runner.js';
export default function create(provider) {
const nameTaken = getByName(provider);
const ensureLang = langEnsure(provider);
const ensureTax = taxEnsure(provider);
@@ -36,13 +34,12 @@ export default function create(provider) {
*
* @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 {string} input.name - The company name.
* @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.
* @param {object} [tx] - Optional transaction to run within.
* @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({
@@ -56,10 +53,6 @@ export default function create(provider) {
*/
return async ({ iso639, name, taxrate, reducedtaxrate, googleAuthId }, tx) => {
const runCreate = async (runner) => {
const existing = await nameTaken(name, runner);
if (existing) {
throw new Error('Company name not available');
}
const languageId = await ensureLang(iso639, runner);
const taxrateId = await ensureTax(taxrate, runner);