Add POS terminal category visibility system
Add posterminal and posterminalcategory tables to control which categories are visible on each POS terminal. The existence of a row in posterminalcategory means the category is visible on that terminal. Store methods: - posterminal.list/upsert/delete - CRUD for terminals - posterminal.setOn/setOff - toggle single category on a terminal - posterminal.setOnAll/setOffAll - toggle all categories on a terminal - posterminal.getCategoryPosterminalIds - internal, used by category tree The category tree (getTreeForCompany) now includes a posterminalIds array on each node listing which terminals have that category enabled.
This commit is contained in:
@@ -10,6 +10,10 @@ FROM company
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
export const GET_COMPANY_ROOT_CATEGORY = `
|
||||
SELECT root_category_id AS rootCategoryId FROM company WHERE id = @companyId
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO company (
|
||||
name,
|
||||
|
||||
89
src/sql/posterminal.js
Normal file
89
src/sql/posterminal.js
Normal file
@@ -0,0 +1,89 @@
|
||||
export const LIST_BY_COMPANY = `
|
||||
SELECT
|
||||
id,
|
||||
token,
|
||||
pairingpin
|
||||
FROM posterminal
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY id
|
||||
`;
|
||||
|
||||
export const GET_BY_ID = `
|
||||
SELECT
|
||||
id,
|
||||
company_id AS companyId,
|
||||
token,
|
||||
pairingpin
|
||||
FROM posterminal
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO posterminal (company_id, token, pairingpin)
|
||||
OUTPUT INSERTED.id, INSERTED.token, INSERTED.pairingpin
|
||||
VALUES (@companyId, @token, @pairingpin)
|
||||
`;
|
||||
|
||||
export const UPDATE = `
|
||||
UPDATE posterminal
|
||||
SET token = @token, pairingpin = @pairingpin
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const DELETE_BY_COMPANY_AND_ID = `
|
||||
DELETE FROM posterminal
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const LIST_CATEGORY_IDS = `
|
||||
SELECT category_id AS categoryId
|
||||
FROM posterminalcategory
|
||||
WHERE posterminal_id = @posterminalId
|
||||
`;
|
||||
|
||||
/** setOn: insert if not exists (single terminal + single category). */
|
||||
export const SET_ON = `
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM posterminalcategory
|
||||
WHERE posterminal_id = @posterminalId AND category_id = @categoryId
|
||||
)
|
||||
INSERT INTO posterminalcategory (posterminal_id, category_id)
|
||||
VALUES (@posterminalId, @categoryId)
|
||||
`;
|
||||
|
||||
/** setOff: remove a single category from a single terminal. */
|
||||
export const SET_OFF = `
|
||||
DELETE FROM posterminalcategory
|
||||
WHERE posterminal_id = @posterminalId AND category_id = @categoryId
|
||||
`;
|
||||
|
||||
/** setOnAll: enable ALL company categories on one terminal. */
|
||||
export const SET_ON_ALL = `
|
||||
;WITH cats AS (
|
||||
SELECT id FROM category WHERE id = @rootCategoryId
|
||||
UNION ALL
|
||||
SELECT c.id FROM category c INNER JOIN cats ON c.parent_id = cats.id
|
||||
)
|
||||
INSERT INTO posterminalcategory (posterminal_id, category_id)
|
||||
SELECT @posterminalId, cats.id
|
||||
FROM cats
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM posterminalcategory pc
|
||||
WHERE pc.posterminal_id = @posterminalId AND pc.category_id = cats.id
|
||||
)
|
||||
`;
|
||||
|
||||
/** setOffAll: remove ALL category links from one terminal. */
|
||||
export const SET_OFF_ALL = `
|
||||
DELETE FROM posterminalcategory WHERE posterminal_id = @posterminalId
|
||||
`;
|
||||
|
||||
/** For category tree: map category -> posterminal ids (company-scoped). */
|
||||
export const POSTERMINAL_IDS_BY_COMPANY = `
|
||||
SELECT
|
||||
pc.category_id AS categoryId,
|
||||
pc.posterminal_id AS posterminalId
|
||||
FROM posterminalcategory pc
|
||||
INNER JOIN posterminal pt ON pt.id = pc.posterminal_id
|
||||
WHERE pt.company_id = @companyId
|
||||
`;
|
||||
@@ -3,6 +3,8 @@ export const TABLES = [
|
||||
'companyuser',
|
||||
'syncpos',
|
||||
'companysetting',
|
||||
'posterminalcategory',
|
||||
'posterminal',
|
||||
'numbers',
|
||||
'manifestarticle',
|
||||
'manifest',
|
||||
|
||||
Reference in New Issue
Block a user