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/34fbfb98ed259791.js

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





const index = catchAsync(async (req, res, next) => {
  const query = req.query;
  let allData = await db.Employee.find(query)
    .populate("contact_id", ["_id", "first_name"])
    .exec();
  return successResponse(res, allData);
});

const add = catchAsync(async (req, res, next) => {
  const employee = req.body;
  const result = new db.Employee(employee);
  await result.save();
  return successResponse(res, result, "Employee saved successfully.");
});

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

const view = catchAsync(async (req, res, next) => {
  let Contacts = await db.Employee.aggregate([
    {
      $match: {
        _id: mongoose.Types.ObjectId(req.params.id),
      },
    },
  ]);

  let contact = await db.Employee.findByIdAndUpdate({ _id: req.params.id });
  if (!contact) {
    return next(new AppError("No data found.", 404));
  }
  return successResponse(res, Contacts);
});

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

  if (!deletedEmployer) {
    return next(new AppError("No data found.", 404));
  }
  return successResponse(
    res,
    deletedEmployer,
    "Employee and related data deleted successfully."
  );
});

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

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