package queries

/* ======================================================
   ROLE + DEPARTMENT PERMISSIONS
====================================================== */

// GET
const GetRoleDepartmentPermissions = `
SELECT
  rdp.module_code,
  rdp.action,
  rdp.allowed
FROM vw_role_dept_permissions rdp
WHERE rdp.role_id = $1
  AND rdp.department_code = $2
ORDER BY rdp.module_code, rdp.action
`

// UPSERT
const UpsertRoleDepartmentPermission = `
INSERT INTO mk_sys_role_department_permissions
(
  role_id,
  department_code,
  module_code,
  action,
  allowed
)
VALUES ($1,$2,$3,$4,$5)

ON CONFLICT ON CONSTRAINT uq_role_dept_module_action
DO UPDATE SET
  allowed = EXCLUDED.allowed;

`

// ======================================================
// 📦 MODULES
// ======================================================

const GetModuleLookup = `
SELECT
  code  AS value,
  name  AS label
FROM mk_sys_modules
ORDER BY id
`
