|
5 | 5 | const Validator = require('../utils/Validator'); |
6 | 6 | const PermissionManager = require('../utils/PermissionManager'); |
7 | 7 |
|
| 8 | +const VALID_LICENSE_STATUS_MAP = { |
| 9 | + active: 'ACTIVE', |
| 10 | + revoked: 'REVOKED', |
| 11 | + suspended: 'SUSPENDED', |
| 12 | + expired: 'EXPIRED', |
| 13 | +}; |
| 14 | + |
8 | 15 | module.exports = { |
9 | 16 | name: 'update', |
10 | 17 | description: 'Update a license or ticket status (Admin only)', |
@@ -36,6 +43,7 @@ module.exports = { |
36 | 43 | ' `/update TKT-1234567890-ABC123 pending`\n' + |
37 | 44 | ' `/update TKT-1234567890-ABC123 closed`\n\n' + |
38 | 45 | 'License Fields: status, plan, expiresAt, issuedTo, issuedEmail\n' + |
| 46 | + 'License Statuses: ACTIVE, REVOKED, SUSPENDED, EXPIRED\n' + |
39 | 47 | 'Ticket Statuses: open, pending, closed', |
40 | 48 | { parse_mode: 'Markdown' } |
41 | 49 | ); |
@@ -114,7 +122,13 @@ module.exports = { |
114 | 122 |
|
115 | 123 | // Map field names |
116 | 124 | if (field === 'status') { |
117 | | - updateData.status = value.toUpperCase(); |
| 125 | + const normalizedStatus = VALID_LICENSE_STATUS_MAP[String(value).trim().toLowerCase()]; |
| 126 | + if (!normalizedStatus) { |
| 127 | + throw new Error( |
| 128 | + 'Invalid license status. Use one of: ACTIVE, REVOKED, SUSPENDED, EXPIRED.' |
| 129 | + ); |
| 130 | + } |
| 131 | + updateData.status = normalizedStatus; |
118 | 132 | } else if (field === 'plan') { |
119 | 133 | updateData.plan = value.toUpperCase(); |
120 | 134 | } else if (field === 'expiresat') { |
|
0 commit comments