archetecture security fix
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.validateLicense = validateLicense;
|
||||
exports.validateAndFlagLicense = validateAndFlagLicense;
|
||||
const prisma_1 = require("../lib/prisma");
|
||||
const THREE_MONTHS_MS = 3 * 30 * 24 * 60 * 60 * 1000;
|
||||
function validateLicense(licenseExpiry) {
|
||||
if (!licenseExpiry) {
|
||||
return { status: 'VALID', daysUntilExpiry: null, requiresApproval: false, message: 'No expiry date on record' };
|
||||
}
|
||||
const now = new Date();
|
||||
const daysUntilExpiry = Math.ceil((licenseExpiry.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
|
||||
if (licenseExpiry <= now) {
|
||||
return { status: 'EXPIRED', daysUntilExpiry, requiresApproval: true, message: `License expired ${Math.abs(daysUntilExpiry)} day(s) ago` };
|
||||
}
|
||||
if (licenseExpiry.getTime() - now.getTime() < THREE_MONTHS_MS) {
|
||||
return { status: 'EXPIRING', daysUntilExpiry, requiresApproval: true, message: `License expires in ${daysUntilExpiry} day(s) — approval required` };
|
||||
}
|
||||
return { status: 'VALID', daysUntilExpiry, requiresApproval: false, message: `Valid — expires in ${daysUntilExpiry} day(s)` };
|
||||
}
|
||||
async function validateAndFlagLicense(customerId, companyId) {
|
||||
const where = companyId ? { id: customerId, companyId } : { id: customerId };
|
||||
const customer = await prisma_1.prisma.customer.findFirstOrThrow({ where });
|
||||
const result = validateLicense(customer.licenseExpiry);
|
||||
const status = result.status === 'EXPIRED' ? 'EXPIRED' :
|
||||
result.status === 'EXPIRING' ? 'EXPIRING' : 'VALID';
|
||||
if (companyId) {
|
||||
await prisma_1.prisma.customer.updateMany({
|
||||
where: { id: customerId, companyId },
|
||||
data: {
|
||||
licenseExpired: result.status === 'EXPIRED',
|
||||
licenseExpiringSoon: result.status === 'EXPIRING',
|
||||
licenseValidationStatus: status,
|
||||
flagged: result.requiresApproval ? true : customer.flagged,
|
||||
flagReason: result.requiresApproval ? result.message : customer.flagReason,
|
||||
},
|
||||
});
|
||||
}
|
||||
else {
|
||||
await prisma_1.prisma.customer.update({
|
||||
where: { id: customerId },
|
||||
data: {
|
||||
licenseExpired: result.status === 'EXPIRED',
|
||||
licenseExpiringSoon: result.status === 'EXPIRING',
|
||||
licenseValidationStatus: status,
|
||||
flagged: result.requiresApproval ? true : customer.flagged,
|
||||
flagReason: result.requiresApproval ? result.message : customer.flagReason,
|
||||
},
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
//# sourceMappingURL=licenseValidationService.js.map
|
||||
Reference in New Issue
Block a user