Skip to content

Instantly share code, notes, and snippets.

@popeating
Created November 3, 2023 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save popeating/f0cca28ae91cccdf4b9481edec544577 to your computer and use it in GitHub Desktop.
Save popeating/f0cca28ae91cccdf4b9481edec544577 to your computer and use it in GitHub Desktop.
export async function contactView(id) {
try {
const contact = await Contact.findById(id);
const newContact = { ...contact._doc, _id: contact._doc._id.toString() };
return newContact;
} catch (e) {
return { error: e.message };
}
}
export async function contactUpdate(contact) {
try {
const contactupd = await Contact.findByIdAndUpdate(
contact._id,
{ name: contact.name, email: contact.email },
{ new: true }
);
const newContact = {
...contactupd._doc,
_id: contactupd._doc._id.toString(),
};
revalidatePath('/');
return newContact;
} catch (e) {
return { error: e.message };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment