feat: Nambahin template certificate endpoint

This commit is contained in:
Rafi Athallah
2026-06-25 18:47:40 +07:00
parent 955545876f
commit d86164f8df
8 changed files with 474 additions and 1 deletions
+82
View File
@@ -2,6 +2,9 @@ const express = require('express');
const { certificateController } = require('../modules/certificate');
const { verifyJWT } = require('../middleware/verifyJWT');
const isAdmin = require('../middleware/isAdmin');
const isMentorOrAdmin = require('../middleware/isMentorOrAdmin');
const multer = require('../middleware/multer');
const { multerErrorHandler, checkFileSizes } = require('../middleware/multer');
const router = express.Router();
@@ -366,4 +369,83 @@ router.get('/verify', certificateController.verifyCertificate);
*/
router.get('/verify-uuid/:uuid', certificateController.verifyCertificateByUuid);
/**
* @swagger
* /certificate-api/projects/{id_project}/template:
* post:
* summary: Upload certificate template for a project
* description: Admin or Mentor can upload a certificate template file (image/pdf) for a specific project. Mentors can only upload to projects they own.
* tags: [Certificate]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: id_project
* schema:
* type: integer
* required: true
* description: The ID of the project to associate the template with
* example: 1
* requestBody:
* required: true
* content:
* multipart/form-data:
* schema:
* type: object
* required:
* - template
* properties:
* template:
* type: string
* format: binary
* description: The certificate template file (JPEG, JPG, PNG, or PDF). Max size 5MB.
* responses:
* 200:
* description: Certificate template uploaded successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: boolean
* example: true
* data:
* type: object
* properties:
* id_project:
* type: integer
* example: 1
* certificate_template:
* type: string
* example: "/uploads/1718000000000-987654321.png"
* message:
* type: string
* example: "Certificate template uploaded successfully"
* code:
* type: integer
* example: 200
* 400:
* description: Bad request (missing file or invalid input)
* 401:
* description: Unauthorized
* 403:
* description: Forbidden (Mentor does not own the project, or unauthorized role)
* 404:
* description: Project not found
* 413:
* description: File size too large (max 5MB)
* 500:
* description: Internal server error
*/
router.post(
'/projects/:id_project/template',
verifyJWT,
isMentorOrAdmin,
multer.single('template'),
checkFileSizes,
multerErrorHandler,
certificateController.uploadCertificateTemplate
);
module.exports = router;