The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/server/startup/migrations/v332.ts

53 lines
1.0 KiB

import { CallHistory, Users } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
addMigration({
version: 332,
name: 'Fill contact information on older call history entries',
async up() {
const cursor = CallHistory.col.aggregate([
{
$match: {
external: false,
contactId: { $exists: true },
contactName: { $exists: false },
contactUsername: { $exists: false },
},
},
{
$lookup: {
from: Users.col.collectionName,
localField: 'contactId',
foreignField: '_id',
as: 'contactDetails',
},
},
{
$addFields: {
contactName: { $first: '$contactDetails.name' },
contactUsername: { $first: '$contactDetails.username' },
},
},
{
$project: {
contactName: 1,
contactUsername: 1,
},
},
{
$merge: {
into: CallHistory.col.collectionName,
on: '_id',
whenMatched: 'merge',
},
},
]);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
for await (const _item of cursor) {
//
}
},
});