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(
|
2023-10-23 08:21:16 +00:00
|
|
|
{ user_id: new ObjectId(userId.toString()) },
|
2022-12-16 10:42:39 +00:00
|
|
|
{
|
|
|
|
$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({
|
2023-10-23 08:21:16 +00:00
|
|
|
user_id: new ObjectId(userId.toString()),
|
2022-12-16 10:42:39 +00:00
|
|
|
})
|
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
|
|
|
}
|