Skip to content
Open

update #5551

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions models/contact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { Schema, model } = require("mongoose");

const contactSchema = new Schema({
name: {
type: String,
required: [true, "Set name for contact"],
},
email: {
type: String,
},
phone: {
type: String,
},
favorite: {
type: Boolean,
default: false,
},
});

const Contact = model("Contact", contactSchema);

module.exports = Contact;
36 changes: 29 additions & 7 deletions models/contacts.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
// const fs = require('fs/promises')
const Contact = require("./contact");
const listContacts = async () => {
return await Contact.find({});
};

const listContacts = async () => {}
const getContactById = async (contactId) => {
return await Contact.findById(contactId);
};

const getContactById = async (contactId) => {}
const removeContact = async (contactId) => {
return await Contact.findByIdAndRemove(contactId);
};

const removeContact = async (contactId) => {}
const addContact = async (body) => {
return await Contact.create(body);
};

const addContact = async (body) => {}
const updateContact = async (contactId, body) => {
return await Contact.findByIdAndUpdate(
contactId,
{ $set: body },
{ new: true }
);
};

const updateContact = async (contactId, body) => {}
const updateStatusContact = async (contactId, body) => {
return await Contact.findByIdAndUpdate(
contactId,
{ $set: body },
{ new: true }
);
};

module.exports = {
listContacts,
getContactById,
removeContact,
addContact,
updateContact,
}
updateStatusContact,
};
Loading