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

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
`;