part1
This commit is contained in:
@@ -5,23 +5,28 @@ import langEnsure from '../lang/ensure.js';
|
||||
import taxEnsure from '../tax/ensure.js';
|
||||
import request from '../request.js';
|
||||
|
||||
/**
|
||||
* Updates an existing company's name, language and tax rates.
|
||||
*
|
||||
* @param {object} pool - The mssql connection pool.
|
||||
* @returns {Function} An async function that updates a company.
|
||||
*
|
||||
* @example
|
||||
* const fn = update(pool);
|
||||
* const result = await fn(1, { iso639: 'de', name: 'Acme', taxrate: 19, reducedtaxrate: 7 });
|
||||
* // => { id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId }
|
||||
*/
|
||||
export default function update(pool) {
|
||||
const byId = getById(pool);
|
||||
const byName = getByName(pool);
|
||||
const ensureLang = langEnsure(pool);
|
||||
const ensureTax = taxEnsure(pool);
|
||||
|
||||
/**
|
||||
* Updates an existing company's name, language and tax rates.
|
||||
*
|
||||
* @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 {number} input.taxrate - The standard tax rate in percent.
|
||||
* @param {number} input.reducedtaxrate - The reduced tax rate in percent.
|
||||
* @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.
|
||||
*
|
||||
* @example
|
||||
* const result = await store.company.update(1, { iso639: 'de', name: 'Acme', taxrate: 19, reducedtaxrate: 7 });
|
||||
* // => { id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId }
|
||||
*/
|
||||
return async (id, { iso639, name, taxrate, reducedtaxrate }) => {
|
||||
const tx = pool.transaction();
|
||||
await tx.begin();
|
||||
|
||||
Reference in New Issue
Block a user