overleaf/services/contacts/app/js/ContactManager.js
Christopher Hoskin 6a118d9439 Merge pull request #15331 from overleaf/csh-issue-11625-mongo-ug-5-contacts
Upgrade mongodb module for contacts from 4.12.1 to 6.1.0

GitOrigin-RevId: 22c4544b21363d82dcf3215c660e4412bb179fe8
2023-10-24 08:03:11 +00:00

24 lines
524 B
JavaScript

import { db, ObjectId } from './mongodb.js'
export async function touchContact(userId, contactId) {
await db.contacts.updateOne(
{ user_id: new ObjectId(userId.toString()) },
{
$inc: {
[`contacts.${contactId}.n`]: 1,
},
$set: {
[`contacts.${contactId}.ts`]: new Date(),
},
},
{ upsert: true }
)
}
export async function getContacts(userId) {
const user = await db.contacts.findOne({
user_id: new ObjectId(userId.toString()),
})
return user?.contacts
}