fix(qr-custom): ikon menu + disable sampai QRIS statis siap
All checks were successful
CI / test (push) Successful in 1m43s
All checks were successful
CI / test (push) Successful in 1m43s
- icon bi-qr-code - menu disembunyikan bila QRIS belum aktif/payload kosong - form & POST ditolak, tidak membuat data tanpa QR - versi 0.6.1
This commit is contained in:
@@ -7,9 +7,19 @@ const crypto = require('crypto');
|
||||
const db = require('../config/database');
|
||||
const { isQrisAmountTaken } = require('./invoiceQrisService');
|
||||
const { logger } = require('../config/logger');
|
||||
const { getSetting } = require('../config/settingsManager');
|
||||
|
||||
const DURATION_MINUTES = 20;
|
||||
|
||||
function isReady() {
|
||||
try {
|
||||
const enabled = getSetting('qris_static_enabled', true);
|
||||
const off = enabled === false || enabled === 'false' || enabled === 0 || enabled === '0';
|
||||
const payload = String(getSetting('qris_static_payload', '') || '').trim();
|
||||
return !off && payload.length > 0;
|
||||
} catch (e) { return false; }
|
||||
}
|
||||
|
||||
function nowIso() { return new Date().toISOString(); }
|
||||
|
||||
function sweepExpired() {
|
||||
@@ -27,6 +37,7 @@ function isTaken(amount, excludeId) {
|
||||
}
|
||||
|
||||
function create({ title, category, amount, note, createdBy }) {
|
||||
if (!isReady()) throw new Error('QRIS Statis (Semi-Otomatis) belum aktif/berisi payload. Atur dulu di Pengaturan → QRIS.');
|
||||
const base = Math.max(1, Math.floor(Number(amount) || 0));
|
||||
if (!title || !String(title).trim()) throw new Error('Judul wajib diisi.');
|
||||
if (!base) throw new Error('Nominal wajib diisi.');
|
||||
@@ -161,6 +172,7 @@ function isExpired(row) {
|
||||
|
||||
module.exports = {
|
||||
DURATION_MINUTES,
|
||||
isReady,
|
||||
create,
|
||||
list,
|
||||
stats,
|
||||
|
||||
@@ -32,7 +32,7 @@ const MENU_DEFINITIONS = [
|
||||
{ key: 'map', section: 'main', href: '/admin/map', icon: 'bi bi-map', labelKey: 'admin.nav.network_map', labelDefault: 'Peta Jaringan', roles: ['admin', 'cashier'], bottomNav: true, bottomNavOrder: 4, activePages: ['map'] },
|
||||
{ key: 'whatsapp', section: 'main', href: '/admin/whatsapp', icon: 'bi bi-whatsapp', labelKey: 'admin.nav.whatsapp', labelDefault: 'WhatsApp', roles: ['admin', 'cashier'], activePages: ['whatsapp','broadcast','whatsapp_live_chat','whatsapp_templates'] },
|
||||
{ key: 'automation', section: 'main', href: '/admin/automation', icon: 'bi bi-robot', labelKey: 'admin.nav.automation', labelDefault: 'Automation', roles: ['admin'], activePages: ['automation'] },
|
||||
{ key: 'custom_qr', section: 'main', href: '/admin/custom-qr', icon: 'bi bi-qr-code-simple', labelKey: 'admin.nav.custom_qr', labelDefault: 'QR-Custom Payment', roles: ['admin'], activePages: ['custom_qr'] },
|
||||
{ key: 'custom_qr', section: 'main', href: '/admin/custom-qr', icon: 'bi bi-qr-code', labelKey: 'admin.nav.custom_qr', labelDefault: 'QR-Custom Payment', roles: ['admin'], activePages: ['custom_qr'] },
|
||||
|
||||
{ key: 'grp_customers', section: 'billing', href: '/admin/customers', icon: 'bi bi-people', labelKey: 'admin.nav.customers', labelDefault: 'Pelanggan', roles: ['admin', 'cashier'], bottomNav: true, bottomNavOrder: 2, activePages: ['customers', 'onu_stickers'], children: [
|
||||
{ key: 'customers', section: 'billing', href: '/admin/customers', icon: 'bi bi-people', labelKey: 'admin.nav.customers_data', labelDefault: 'Data Pelanggan', roles: ['admin', 'cashier'], activePages: ['customers'] },
|
||||
@@ -269,12 +269,21 @@ function enrichMenu(menu, states) {
|
||||
return out;
|
||||
}
|
||||
|
||||
function isCustomQrReady() {
|
||||
try {
|
||||
const enabled = getSetting('qris_static_enabled', true);
|
||||
const off = enabled === false || enabled === 'false' || enabled === 0 || enabled === '0';
|
||||
return !off && String(getSetting('qris_static_payload', '') || '').trim().length > 0;
|
||||
} catch (e) { return false; }
|
||||
}
|
||||
|
||||
function getSidebarSections(session) {
|
||||
const states = getStoredMenuStates();
|
||||
return SECTION_DEFINITIONS.map((section) => {
|
||||
const items = MENU_DEFINITIONS
|
||||
.filter((menu) => menu.section === section.key)
|
||||
.filter((menu) => isMenuAllowedForSession(menu, session))
|
||||
.filter((menu) => !(menu.key === 'custom_qr' && !isCustomQrReady()))
|
||||
.map((menu) => {
|
||||
const enriched = enrichMenu(menu, states);
|
||||
if (Array.isArray(enriched.children)) {
|
||||
|
||||
Reference in New Issue
Block a user