Add Document CRUD, temp→bucket commit flow, SeaweedFS env aliases, and default temp bucket name to temp.
41 lines
1.6 KiB
JavaScript
41 lines
1.6 KiB
JavaScript
// /components/documents/documentController.js
|
|
|
|
const catchAsync = require('../../utils/catchAsync');
|
|
const documentService = require('./documentService');
|
|
const { successResponse, listResponse } = require('../../utils/apiResponse');
|
|
|
|
exports.create = catchAsync(async (req, res) => {
|
|
const document = await documentService.createDocument(req.body, req.user?._id);
|
|
return successResponse(res, 201, 'Document created successfully', document);
|
|
});
|
|
|
|
exports.getOne = catchAsync(async (req, res) => {
|
|
const document = await documentService.getDocumentById(req.params.id);
|
|
return successResponse(res, 200, 'Document retrieved successfully', document);
|
|
});
|
|
|
|
exports.getAll = catchAsync(async (req, res) => {
|
|
const { data, meta } = await documentService.getAllDocuments(req.query);
|
|
return listResponse(res, 200, data, meta);
|
|
});
|
|
|
|
exports.getByUser = catchAsync(async (req, res) => {
|
|
const data = await documentService.getDocumentsByUser(req.params.userId);
|
|
return successResponse(res, 200, 'User documents retrieved successfully', data);
|
|
});
|
|
|
|
exports.update = catchAsync(async (req, res) => {
|
|
const document = await documentService.updateDocument(req.params.id, req.body);
|
|
return successResponse(res, 200, 'Document updated successfully', document);
|
|
});
|
|
|
|
exports.delete = catchAsync(async (req, res) => {
|
|
await documentService.deleteDocument(req.params.id);
|
|
return successResponse(res, 200, 'Document deleted successfully');
|
|
});
|
|
|
|
exports.getMyDocuments = catchAsync(async (req, res) => {
|
|
const { data, meta } = await documentService.getMyDocuments(req.user._id, req.query);
|
|
return listResponse(res, 200, data, meta);
|
|
});
|