Sindbad~EG File Manager

Current Path : /home/infinitibizsol/.trash/node_modules.8/.cache/esm/
Upload File :
Current File : /home/infinitibizsol/.trash/node_modules.8/.cache/esm/81de77941e7ae940.js

let db,successResponse,catchAsync,AppError;_1e7‍.x([["default",()=>_1e7‍.o]]);_1e7‍.w("../../model/index",[["default",["db"],function(v){db=v}]]);_1e7‍.w("../../utils/responseFormat",[["successResponse",["successResponse"],function(v){successResponse=v}]]);_1e7‍.w("../../utils/catchAsync",[["default",["catchAsync"],function(v){catchAsync=v}]]);_1e7‍.w("../../utils/apiError",[["default",["AppError"],function(v){AppError=v}]]);




const index = catchAsync(async (req, res, next) => {
  const query = req.query;
  let allData = await db.Goal.find({ user_id: req.user._id });
  return successResponse(res, allData);
});

const add = catchAsync(async (req, res, next) => {
  if (!req.body.user_id) {
    req.body.user_id = req.user._id;
  }
  const goals = new db.Goal(req.body);
  await goals.save();
  return successResponse(res, goals, "Goals saved successfully", 201);
});

const edit = catchAsync(async (req, res, next) => {
  const goals = req.body;
  const goal_id = req.params.id;
  const result = await db.Goal.findByIdAndUpdate(
    { _id: goal_id },
    {
      $set: goals,
    },
    {
      new: true,
    }
  );
  if (!result) {
    return next(new AppError("No data,found.", 404));
  }
  return successResponse(res, result, "Goals updated successfully.");
});

const view = catchAsync(async (req, res, next) => {
  let goals = await db.Goal.findOne({ _id: req.params.id });
  if (!goals) {
    return next(new AppError("No data found.", 404));
  }
  return successResponse(res, goals);
});

const deleteData = catchAsync(async (req, res, next) => {
  const goal_id = req.params.id;
  // Delete the contact itself
  const deletedGoal = await db.Goal.findByIdAndDelete({ _id: goal_id });

  if (!deletedGoal) {
    return next(new AppError("No data found.", 404));
  }

  return successResponse(
    res,
    deletedGoal,
    "Goal and related data deleted successfully."
  );
});

_1e7‍.d({ index, add, edit, view, deleteData });

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists