Sindbad~EG File Manager
import db from "../../model/index";
import AppError from "../../utils/apiError";
import catchAsync from "../../utils/catchAsync";
import { successResponse } from "../../utils/responseFormat";
const validateDuplicateEntry = async (policy_id) => {
let document = await db.BinderInfo.findOne({ policy_id });
if (document) return true;
return false;
};
const index = catchAsync(async (req, res, next) => {
const query = req.query;
let allData = await db.BinderInfo.find(query);
return successResponse(res, allData);
});
const add = catchAsync(async (req, res, next) => {
const isDuplicate = await validateDuplicateEntry(req.body.policy_id);
if (isDuplicate) {
return next(new AppError("Duplicate entry is not allowed.", 404));
}
const binderInfo = new db.BinderInfo(req.body);
await binderInfo.save();
return successResponse(res, binderInfo, "BinderInfo saved successfully");
});
const edit = catchAsync(async (req, res, next) => {
let result = await db.BinderInfo.findByIdAndUpdate(
{ _id: req.params.id },
{ $set: req.body },
{ new: true }
);
if (!result) {
return next(new AppError("No data found.", 404));
}
return successResponse(res, result, "BinderInfo updated successfully");
});
const deleteData = catchAsync(async (req, res, next) => {
let binderInfo = await db.BinderInfo.findByIdAndDelete({
_id: req.params.id,
});
if (!binderInfo) {
return next(new AppError("No data found.", 404));
}
return successResponse(res, binderInfo, "BinderInfo deleted successfully");
});
export default { index, add, edit, deleteData };
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists