/
home
/
infinitibizsol
/
.trash
/
controllers.8
/
common
/
File Upload :
llllll
Current File: /home/infinitibizsol/.trash/controllers.8/common/tasks.js
import db from "../../model/index"; import AppError from "../../utils/apiError"; import catchAsync from "../../utils/catchAsync"; import { successResponse, failedResponse } from "../../utils/responseFormat"; 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."); }); export default { index, add, view, edit, deleteData };
Copyright ©2k19 -
Hexid
|
Tex7ure