2022-12-16 05:42:39 -05:00
|
|
|
import { db, ObjectId } from './mongodb.js'
|
2015-10-06 11:41:35 -04:00
|
|
|
|
2022-12-16 05:42:39 -05:00
|
|
|
export async function touchContact(userId, contactId) {
|
|
|
|
await db.contacts.updateOne(
|
|
|
|
{ user_id: ObjectId(userId.toString()) },
|
|
|
|
{
|
|
|
|
$inc: {
|
|
|
|
[`contacts.${contactId}.n`]: 1,
|
2020-02-17 02:38:00 -05:00
|
|
|
},
|
2022-12-16 05:42:39 -05:00
|
|
|
$set: {
|
|
|
|
[`contacts.${contactId}.ts`]: new Date(),
|
2020-02-17 02:38:00 -05:00
|
|
|
},
|
2022-12-16 05:42:39 -05:00
|
|
|
},
|
|
|
|
{ upsert: true }
|
|
|
|
)
|
|
|
|
}
|
2017-03-17 05:31:12 -04:00
|
|
|
|
2022-12-16 05:42:39 -05:00
|
|
|
export async function getContacts(userId) {
|
|
|
|
const user = await db.contacts.findOne({
|
|
|
|
user_id: ObjectId(userId.toString()),
|
|
|
|
})
|
2020-02-17 02:38:00 -05:00
|
|
|
|
2022-12-16 05:42:39 -05:00
|
|
|
return user?.contacts
|
2020-02-17 02:38:00 -05:00
|
|
|
}
|