mongodboperations
v1.0.9
Published
First NPM Package Created By Shivam Singh For MongoDbOperations.
Downloads
14
Readme
What is this?
First NPM Package Created By Shivam Singh For MongoDbOperations.
Installation
$ npm i mongodboperations
How to use
import { Users } from "./users.model";
import { RequestHandler } from "express";
const { Mongodboperations } = require("mongodboperations");
const allOperations = new Mongodboperations(Users);
const createUser: RequestHandler = async (req, res) => {
const item = allOperations.post(req.body);
item.then((value) => {
if (value.error) {
return res.status(400).send(value.error);
}
return res.status(200).send(value.data);
});
};
const getUser: RequestHandler = (req, res) => {
const item = allOperations.get();
item.then((value) => {
if (value.error) {
return res.status(400).send(value.error);
}
return res.status(200).send(value.data);
});
};
const getOneUser: RequestHandler = async (req, res) => {
const item = allOperations.getOne(req.params.id);
item.then((value) => {
if (value.error) {
return res.status(400).send(value.error);
}
return res.status(200).send(value.data);
});
};
const updateUser: RequestHandler = async (req, res) => {
const item = allOperations.patchOne(req.params.id, req.body);
item.then((value) => {
if (value.error) {
return res.status(400).send(value.error);
}
return res.status(200).send(value.data);
});
};
const deleteUser: RequestHandler = async (req, res) => {
const item = allOperations.deleteOne(req.params.id);
item.then((value) => {
if (value.error) {
return res.status(400).send(value.error);
}
return res.status(200).send(value.data);
});
};
export { createUser, getUser, getOneUser, updateUser, deleteUser };