u
This commit is contained in:
@@ -118,7 +118,6 @@ BEGIN
|
||||
reducedtaxrate INT NULL,
|
||||
taxfreerate INT NULL,
|
||||
poscustomergroup_id INT NOT NULL,
|
||||
CONSTRAINT UQ_company_name UNIQUE (name),
|
||||
CONSTRAINT FK_company_root_category FOREIGN KEY (root_category_id) REFERENCES category(id) ON DELETE SET NULL,
|
||||
CONSTRAINT FK_company_default_language FOREIGN KEY (default_language_id) REFERENCES language(id) ON DELETE SET NULL,
|
||||
CONSTRAINT FK_company_taxrate FOREIGN KEY (taxrate) REFERENCES tax(id) ON DELETE NO ACTION,
|
||||
|
||||
@@ -53,7 +53,7 @@ CREATE TABLE IF NOT EXISTS pic (
|
||||
export const INIT_COMPANY = `
|
||||
CREATE TABLE IF NOT EXISTS company (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL COLLATE NOCASE UNIQUE,
|
||||
name TEXT NOT NULL COLLATE NOCASE,
|
||||
root_category_id INTEGER,
|
||||
default_language_id INTEGER,
|
||||
taxrate INTEGER,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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