Sindbad~EG File Manager
let db,AppError,catchAsync,successResponse,failedResponse;_ed2.x([["default",()=>_ed2.o]]);_ed2.w("../../model/index",[["default",["db"],function(v){db=v}]]);_ed2.w("../../utils/apiError",[["default",["AppError"],function(v){AppError=v}]]);_ed2.w("../../utils/catchAsync",[["default",["catchAsync"],function(v){catchAsync=v}]]);_ed2.w("../../utils/responseFormat",[["successResponse",["successResponse"],function(v){successResponse=v}],["failedResponse",["failedResponse"],function(v){failedResponse=v}]]);
const index = catchAsync(async (req, res, next) => {
let allData = await db.Task.find()
.populate("contact_id", ["_id", "first_name", "last_name"])
.populate("created_by", ["_id", "first_name", "last_name"]);
return successResponse(res, allData);
});
const add = catchAsync(async (req, res, next) => {
const tasks = new db.Task(req.body);
await tasks.save();
return successResponse(res, tasks, "Task saved successfully");
});
const view = catchAsync(async (req, res, next) => {
let tasks = await db.Task.findOne({ _id: req.params.id })
.populate("created_by", ["_id", "first_name", "last_name"])
.populate("assigned_to", ["_id", "first_name", "last_name"])
.populate("contact_id", ["_id", "first_name", "last_name"]);
if (!tasks) {
return next(new AppError("No data found.", 404));
}
return successResponse(res, tasks);
});
const edit = catchAsync(async (req, res, next) => {
let result = await db.Task.findByIdAndUpdate(
{ _id: req.params.id },
{ $set: req.body },
{ new: true }
);
if (!result) {
return next(new AppError("No data found.", 404));
}
return successResponse(res, result, "Task updated successfully.");
});
const deleteData = catchAsync(async (req, res, next) => {
let tasks = await db.Task.findByIdAndDelete({ _id: req.params.id });
if (!tasks) {
return next(new AppError("No data found.", 404));
}
return successResponse(res, tasks, "Task deleted successfully.");
});
_ed2.d({ index, add, view, edit, deleteData });
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists