ADD: Bucket and Upload System ADD: New errors ADD: Virtuals for categories ADD: Features system ADD: File management system
104 lines
2.5 KiB
JavaScript
104 lines
2.5 KiB
JavaScript
const catchAsync = require('../../globalErrorHandler/catchAsync')
|
|
const fileService = require('./fileService')
|
|
|
|
exports.bucketSingleUpload = catchAsync(async (req, res, next) => {
|
|
const fileData = await fileService.bucketSingleUpload(req.file, req.params.bucketName)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
data: fileData,
|
|
})
|
|
})
|
|
|
|
exports.userUploadOrderDocument = catchAsync(async (req, res, next) => {
|
|
const files = await fileService.userUploadOrderDocument(req.files)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
results: files.length,
|
|
data: files,
|
|
})
|
|
})
|
|
|
|
exports.bucketMultiUpload = catchAsync(async (req, res, next) => {
|
|
const files = await fileService.bucketMultiUpload(req.files, req.params.bucketName)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
results: files.length,
|
|
data: files,
|
|
})
|
|
})
|
|
|
|
exports.bucketGetFiles = catchAsync(async (req, res, next) => {
|
|
const files = await fileService.bucketGetFiles()
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
results: files.length,
|
|
data: files,
|
|
})
|
|
})
|
|
|
|
exports.getSignedUrl = catchAsync(async (req, res, next) => {
|
|
const url = await fileService.getSignedUrl(req.body.fileName)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
data: url,
|
|
})
|
|
})
|
|
|
|
exports.bucketDeleteFile = catchAsync(async (req, res, next) => {
|
|
await fileService.bucketDeleteFile(req.body, req.params.bucketName)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
})
|
|
})
|
|
|
|
exports.getAllFiles = catchAsync(async (req, res, next) => {
|
|
const files = await fileService.getAllFiles()
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
results: files.length,
|
|
data: files,
|
|
})
|
|
})
|
|
|
|
exports.getFile = catchAsync(async (req, res, next) => {
|
|
const file = await fileService.getFile(req.body.id)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
data: file,
|
|
})
|
|
})
|
|
|
|
exports.createFile = catchAsync(async (req, res, next) => {
|
|
const file = await fileService.createFile(req.body)
|
|
|
|
res.status(201).json({
|
|
status: 'success',
|
|
data: file,
|
|
})
|
|
})
|
|
|
|
exports.updateFile = catchAsync(async (req, res, next) => {
|
|
const file = await fileService.updateFile(req.body)
|
|
res.status(200).json({
|
|
status: 'success',
|
|
data: file,
|
|
})
|
|
})
|
|
|
|
exports.deleteFile = catchAsync(async (req, res, next) => {
|
|
await fileService.deleteFile(req.body.id)
|
|
|
|
res.status(204).json({
|
|
status: 'success',
|
|
data: null,
|
|
})
|
|
})
|