Skip to content
Open
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
25 changes: 25 additions & 0 deletions helpers/contactsService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const Contact = require("../models/contacts");

const updateStatusContact = async (contactId, body) => {
const { favorite } = body;

if (favorite === undefined) {
throw new Error("missing field favorite");
}

const updatedContact = await Contact.findByIdAndUpdate(
contactId,
{ favorite },
{ new: true }
);

if (!updatedContact) {
throw new Error("Not found");
}

return updatedContact;
};

module.exports = {
updateStatusContact,
};
37 changes: 20 additions & 17 deletions models/contacts.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// const fs = require('fs/promises')
const { Schema, model } = require("mongoose");

const listContacts = async () => {}
const contactSchema = new Schema({
name: {
type: String,
required: [true, "Set name for contact"],
},
email: {
type: String,
},
phone: {
type: String,
},
favorite: {
type: Boolean,
default: false,
},
});
// schema -> model -> export
const Contact = model("Contact", contactSchema);

const getContactById = async (contactId) => {}

const removeContact = async (contactId) => {}

const addContact = async (body) => {}

const updateContact = async (contactId, body) => {}

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