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:
39
src/store/posterminal/setOffAll.js
Normal file
39
src/store/posterminal/setOffAll.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { GET_BY_ID, SET_OFF_ALL, LIST_CATEGORY_IDS } from '../../sql/posterminal.js';
|
||||
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
|
||||
|
||||
export default function setOffAll(pool) {
|
||||
const access = resolveCompanyAccess(pool);
|
||||
|
||||
return async (googleAuthId, companyId, posterminalId) => {
|
||||
if (!Number.isFinite(posterminalId)) {
|
||||
throw new Error('Invalid posterminal');
|
||||
}
|
||||
|
||||
await access(googleAuthId, companyId);
|
||||
|
||||
// Verify posterminal belongs to company
|
||||
const pt = await pool
|
||||
.request()
|
||||
.input('id', posterminalId)
|
||||
.query(GET_BY_ID);
|
||||
|
||||
if (!pt.recordset[0] || pt.recordset[0].companyId !== companyId) {
|
||||
throw new Error('Posterminal not found');
|
||||
}
|
||||
|
||||
await pool
|
||||
.request()
|
||||
.input('posterminalId', posterminalId)
|
||||
.query(SET_OFF_ALL);
|
||||
|
||||
const result = await pool
|
||||
.request()
|
||||
.input('posterminalId', posterminalId)
|
||||
.query(LIST_CATEGORY_IDS);
|
||||
|
||||
return {
|
||||
id: posterminalId,
|
||||
categoryIds: result.recordset.map((r) => r.categoryId),
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user