Initial commit: teaching institution management API.
Express/MongoDB backend with JWT auth, RBAC, S3 uploads, notifications, and scheduled jobs.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// /components/files/fileController.js
|
||||
|
||||
const catchAsync = require('../../utils/catchAsync');
|
||||
const fileService = require('./fileService');
|
||||
const { successResponse } = require('../../utils/apiResponse');
|
||||
const AppError = require('../../utils/AppError');
|
||||
|
||||
exports.uploadTemp = catchAsync(async (req, res, next) => {
|
||||
if (!req.file) {
|
||||
return next(new AppError('FILE_REQUIRED'));
|
||||
}
|
||||
|
||||
const result = await fileService.uploadTempFile(
|
||||
req.file.buffer,
|
||||
req.file.originalname,
|
||||
req.file.mimetype
|
||||
);
|
||||
|
||||
return successResponse(res, 201, 'File uploaded to temp bucket successfully', result);
|
||||
});
|
||||
|
||||
exports.getSignedUrl = catchAsync(async (req, res, next) => {
|
||||
const { filename } = req.params;
|
||||
const { bucket } = req.query;
|
||||
|
||||
const result = await fileService.getPresignedUrl(filename, bucket);
|
||||
return successResponse(res, 200, 'Temporary presigned URL generated successfully', result);
|
||||
});
|
||||
|
||||
exports.deleteFile = catchAsync(async (req, res, next) => {
|
||||
const { filename } = req.params;
|
||||
const { bucket } = req.query;
|
||||
|
||||
await fileService.deleteFile(filename, bucket);
|
||||
return successResponse(res, 200, 'File deleted successfully');
|
||||
});
|
||||
Reference in New Issue
Block a user