Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //db.ja
- const mongoose = require('mongoose');
- // async func because mongoose functions return promises
- const connectDB = async () => {
- const con = await mongoose.connect("mongodb://localhost:27017/projectmgmt");
- console.log(`MongoDB Connected: mongodb://localhost:27017/project`);
- };
- module.exports = connectDB;
- //models
- const clientSchema = new mongoose.Schema({
- name: { type: String, required: true },
- last: { type: String, required: true },
- });
- const Client = mongoose.model('Client', clientSchema);
- //insert
- const add = async (_, { name, last }) => {
- const client = new Client({ name, last });
- return await client.save();
- }
- module.exports = add;
- //update
- const update = async (_, { id, name, last }) => {
- return await Client.findByIdAndUpdate(id, { name, last }, { new: true });
- }
- module.exports = update;
- //delete
- const deleted = async (_, { id }) => {
- return await Client.findByIdAndRemove(id);
- }
- module.exports = deleted;
- //display
- const clients= async () => {
- return await Client.find({});
- }
- const client = async (_, { id }) => {
- return await Client.findById(id);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement