overleaf/services/contacts/app/js/ContactManager.js

25 lines
516 B
JavaScript
Raw Normal View History

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