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