Add Document CRUD, temp→bucket commit flow, SeaweedFS env aliases, and default temp bucket name to temp.
51 lines
2.1 KiB
JavaScript
51 lines
2.1 KiB
JavaScript
// /components/certificates/certificateController.js
|
|
|
|
const catchAsync = require('../../utils/catchAsync');
|
|
const certificateService = require('./certificateService');
|
|
const { successResponse, listResponse } = require('../../utils/apiResponse');
|
|
|
|
exports.create = catchAsync(async (req, res, next) => {
|
|
const certificate = await certificateService.createCertificate(req.body);
|
|
return successResponse(res, 201, 'Certificate created successfully', certificate);
|
|
});
|
|
|
|
exports.getOne = catchAsync(async (req, res, next) => {
|
|
const certificate = await certificateService.getCertificateById(req.params.id);
|
|
return successResponse(res, 200, 'Certificate retrieved successfully', certificate);
|
|
});
|
|
|
|
exports.getAll = catchAsync(async (req, res, next) => {
|
|
const { data, meta } = await certificateService.getAllCertificates(req.query);
|
|
return listResponse(res, 200, data, meta);
|
|
});
|
|
|
|
exports.getByUser = catchAsync(async (req, res) => {
|
|
const data = await certificateService.getCertificatesByUser(req.params.userId);
|
|
return successResponse(res, 200, 'User certificates retrieved successfully', data);
|
|
});
|
|
|
|
exports.update = catchAsync(async (req, res, next) => {
|
|
const certificate = await certificateService.updateCertificate(req.params.id, req.body);
|
|
return successResponse(res, 200, 'Certificate updated successfully', certificate);
|
|
});
|
|
|
|
exports.delete = catchAsync(async (req, res, next) => {
|
|
await certificateService.deleteCertificate(req.params.id);
|
|
return successResponse(res, 200, 'Certificate deleted successfully');
|
|
});
|
|
|
|
exports.search = catchAsync(async (req, res, next) => {
|
|
const { data, meta } = await certificateService.searchCertificates(req.query);
|
|
return listResponse(res, 200, data, meta);
|
|
});
|
|
|
|
exports.upload = catchAsync(async (req, res, next) => {
|
|
const certificate = await certificateService.uploadUserCertificate(req.user._id, req.body);
|
|
return successResponse(res, 201, 'Certificate uploaded and committed successfully', certificate);
|
|
});
|
|
|
|
exports.getMyCertificates = catchAsync(async (req, res, next) => {
|
|
const { data, meta } = await certificateService.getMyCertificates(req.user._id, req.query);
|
|
return listResponse(res, 200, data, meta);
|
|
});
|