upload pdf

This commit is contained in:
2026-04-15 16:55:32 +07:00
parent 50332f2548
commit 43bfc117bf
9 changed files with 65 additions and 37 deletions

View File

@@ -57,8 +57,8 @@ exports.createForm = async (req, res) => {
exports.create = async (req, res) => {
try {
const data = { ...req.body };
const imgPath = req.files?.certificate_image?.[0]?.path;
if (imgPath) data.certificate_image = normalizePath(imgPath);
const imgFiles = req.files?.certificate_image;
if (imgFiles?.length) data.certificate_image = imgFiles.map(f => normalizePath(f.path));
const cert = new Certificate(data);
await cert.save();
@@ -104,8 +104,8 @@ exports.update = async (req, res) => {
'issued_date','status','passport_number','address'];
fields.forEach(f => { if (req.body[f] !== undefined) cert[f] = req.body[f]; });
const imgPath = req.files?.certificate_image?.[0]?.path;
if (imgPath) cert.certificate_image = normalizePath(imgPath);
const imgFiles = req.files?.certificate_image;
if (imgFiles?.length) cert.certificate_image = imgFiles.map(f => normalizePath(f.path));
await cert.save();
await writeAuditLog({ model: 'Certificate', documentId: cert._id, action: AUDIT_ACTIONS.UPDATE_CERTIFICATE, before, after: cert.toObject(), req });
@@ -142,7 +142,10 @@ exports.apiVerify = async (req, res) => {
if (cert.status === 'revoked') return res.status(404).json({ error: 'Certificate has been revoked' });
const baseUrl = process.env.BACKEND_URL ?? `${req.protocol}://${req.get('host')}`;
const buildUrl = (f) => f ? [generateSignedUrl(baseUrl, path.basename(f))] : undefined;
const buildUrl = (files) => {
if (!files?.length) return undefined;
return files.map(f => generateSignedUrl(baseUrl, path.basename(f)));
};
const response = {
full_name: cert.student_name,