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 index = catchAsync(async (req, res, next) => {
const query = req.query;
let allData = await db.LocationSchedule.find(query);
return successResponse(res, allData);
});
const add = catchAsync(async (req, res, next) => {
const locationSchedule = new db.LocationSchedule(req.body);
await locationSchedule.save();
return successResponse(
res,
locationSchedule,
"LocationSchedule saved successfully"
);
});
const edit = catchAsync(async (req, res, next) => {
let result = await db.LocationSchedule.findByIdAndUpdate(
{ _id: req.params.id },
{ $set: req.body },
{ new: true }
);
if (!result) {
return next(new AppError("No data found.", 404));
}
return successResponse(res, result, "LocationSchedule updated successfully");
});
const deleteData = catchAsync(async (req, res, next) => {
let locationSchedule = await db.LocationSchedule.findByIdAndDelete({
_id: req.params.id,
});
if (!locationSchedule) {
return next(new AppError("No data found.", 404));
}
return successResponse(
res,
locationSchedule,
"LocationSchedule deleted successfully"
);
});
export default { index, add, edit, deleteData };
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists