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