Add company-scoped brand and company settings API.

brand now carries a NOT NULL company_id (unique per (company_id, name))
with brand.list/upsert/delete backed by resolveCompanyAccess. Adds
companysetting key-value store (list/get/set/delete, frontend flag).
This commit is contained in:
seb
2026-08-01 06:59:27 +02:00
parent c839b2ba35
commit 787e411547
18 changed files with 1810 additions and 1192 deletions

36
src/sql/brand.js Normal file
View File

@@ -0,0 +1,36 @@
export const LIST_BY_COMPANY = `
SELECT
id,
name,
gsprpinfo
FROM brand
WHERE company_id = @companyId
ORDER BY name
`;
export const GET_BY_COMPANY_AND_NAME = `
SELECT
id,
name,
gsprpinfo
FROM brand
WHERE company_id = @companyId
AND name = @name
`;
export const CREATE = `
INSERT INTO brand (company_id, name, gsprpinfo)
OUTPUT INSERTED.id
VALUES (@companyId, @name, @gsprpinfo)
`;
export const UPDATE_BY_ID = `
UPDATE brand
SET name = @name, gsprpinfo = @gsprpinfo
WHERE id = @id AND company_id = @companyId
`;
export const DELETE_BY_COMPANY_AND_ID = `
DELETE FROM brand
WHERE id = @id AND company_id = @companyId
`;

47
src/sql/companysetting.js Normal file
View File

@@ -0,0 +1,47 @@
export const LIST_BY_COMPANY = `
SELECT
[key],
value,
CAST(frontend AS INT) AS frontend
FROM companysetting
WHERE company_id = @companyId
ORDER BY [key]
`;
export const LIST_BY_COMPANY_FRONTEND = `
SELECT
[key],
value,
CAST(frontend AS INT) AS frontend
FROM companysetting
WHERE company_id = @companyId
AND frontend = 1
ORDER BY [key]
`;
export const GET_BY_COMPANY_AND_KEY = `
SELECT
[key],
value,
CAST(frontend AS INT) AS frontend
FROM companysetting
WHERE company_id = @companyId
AND [key] = @key
`;
export const UPSERT = `
MERGE companysetting AS target
USING (SELECT @companyId AS company_id, @key AS [key]) AS src
ON target.company_id = src.company_id AND target.[key] = src.[key]
WHEN MATCHED THEN
UPDATE SET value = @value, frontend = @frontend
WHEN NOT MATCHED THEN
INSERT (company_id, [key], value, frontend)
VALUES (@companyId, @key, @value, @frontend);
`;
export const DELETE_BY_COMPANY_AND_KEY = `
DELETE FROM companysetting
WHERE company_id = @companyId
AND [key] = @key
`;

View File

@@ -2,6 +2,7 @@
export const TABLES = [
'companyuser',
'syncpos',
'companysetting',
'numbers',
'manifestarticle',
'manifest',