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:
47
src/sql/companysetting.js
Normal file
47
src/sql/companysetting.js
Normal 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
|
||||
`;
|
||||
Reference in New Issue
Block a user