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