u
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
import { UPDATE as MSSQL_UPDATE } from '../../providers/mssql/queries/company.js';
|
||||
import { UPDATE as SQLITE_UPDATE } from '../../providers/sqlite3/queries/company.js';
|
||||
import getById from './getById.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 update(provider) {
|
||||
const byId = getById(provider);
|
||||
const byName = getByName(provider);
|
||||
const ensureLang = langEnsure(provider);
|
||||
const ensureTax = taxEnsure(provider);
|
||||
const isSqlite = provider?.dialect === 'sqlite3';
|
||||
@@ -20,12 +18,12 @@ export default function update(provider) {
|
||||
* @param {number} id - The id of the company to update.
|
||||
* @param {object} input - The update input.
|
||||
* @param {string} input.iso639 - The ISO 639 language code.
|
||||
* @param {string} input.name - The new company name (must be unique).
|
||||
* @param {string} input.name - The new company name.
|
||||
* @param {number} input.taxrate - The standard tax rate in percent.
|
||||
* @param {number} input.reducedtaxrate - The reduced tax rate in percent.
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<{id: number, rootCategoryId: number, languageId: number, taxrateId: number, reducedtaxrateId: number, taxfreerateId: number}>} The updated company ids.
|
||||
* @throws {Error} If the company is not found or the name is taken.
|
||||
* @throws {Error} If the company is not found.
|
||||
*
|
||||
* @example
|
||||
* const result = await store.company.update(1, { iso639: 'de', name: 'Acme', taxrate: 19, reducedtaxrate: 7 });
|
||||
@@ -38,13 +36,6 @@ export default function update(provider) {
|
||||
throw new Error('Company not found');
|
||||
}
|
||||
|
||||
if (name !== company.name) {
|
||||
const taken = await byName(name, runner);
|
||||
if (taken) {
|
||||
throw new Error('Company name not available');
|
||||
}
|
||||
}
|
||||
|
||||
const languageId = await ensureLang(iso639, runner);
|
||||
const taxrateId = await ensureTax(taxrate, runner);
|
||||
const reducedtaxrateId = await ensureTax(reducedtaxrate, runner);
|
||||
|
||||
Reference in New Issue
Block a user