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

25 lines
524 B
JavaScript
Raw Normal View History

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 }
)
}
2017-03-17 09:31:12 +00:00
export async function getContacts(userId) {
const user = await db.contacts.findOne({
user_id: new ObjectId(userId.toString()),
})
return user?.contacts
}