Add entity customer numbers and scope APIs via selected company.

Entity gets an optional unique-per-company number with allocate/peek/isNumberFree helpers. Company-scoped store methods no longer take companyId and resolve google_auth.selected_company instead.
This commit is contained in:
seb
2026-08-07 04:29:35 +02:00
parent 1e89e19863
commit 70e0a9ddc4
78 changed files with 940 additions and 772 deletions

View File

@@ -1,5 +1,5 @@
import { GET_ARTICLE_EXPORT, GET_CATEGORY_TREE_FLAT } from '../../sql/article.js';
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
const ROOT_CATEGORY_NAME = 'Home';
@@ -19,18 +19,16 @@ function parseJsonArray(raw) {
*
* @example
* const fn = listExport(pool);
* const articles = await fn(42, 1, null);
* const articles = await fn(42, null);
* // => [{ id, sku, name, slug, unitSi, net, taxRate, eans, categoryBreadcrumbs, fullHashes, ... }]
*/
export default function listExport(pool) {
const companyAccess = resolveCompanyAccess(pool);
const companyAccess = resolveSelectedCompanyAccess(pool);
const categoryAccess = resolveCategoryAccess(pool);
return async (googleAuthId, companyId, categoryId) => {
const { languageId, posCustomerGroupId, rootCategoryId } = await companyAccess(
googleAuthId,
companyId,
);
return async (googleAuthId, categoryId) => {
const { languageId, posCustomerGroupId, rootCategoryId } =
await companyAccess(googleAuthId);
// Default to the company's root category when no specific category is given.
let exportCategoryId = rootCategoryId;

View File

@@ -1,5 +1,5 @@
import { SEARCH_ARTICLES } from '../../sql/article.js';
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
/**
* Returns a lightweight search index of all articles for a company.
@@ -9,14 +9,14 @@ import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
*
* @example
* const fn = listSearchIndex(pool);
* const articles = await fn(42, 1);
* const articles = await fn(42);
* // => [{ id, sku, name, eans, categoryIds }]
*/
export default function listSearchIndex(pool) {
const access = resolveCompanyAccess(pool);
const access = resolveSelectedCompanyAccess(pool);
return async (googleAuthId, companyId) => {
const { rootCategoryId, languageId } = await access(googleAuthId, companyId);
return async (googleAuthId) => {
const { companyId, rootCategoryId, languageId } = await access(googleAuthId);
const result = await pool
.request()