@@ -56,12 +56,24 @@ export class LivechatContactsRaw extends BaseRaw<ILivechatContact> implements IL
56
56
'channels.visitor.source.type' : 1 ,
57
57
'channels.visitor.source.id' : 1 ,
58
58
} ,
59
+ name : 'visitorAssociation' ,
59
60
unique : false ,
60
61
} ,
61
62
{
62
63
key : {
63
- channels : 1 ,
64
+ 'channels.field' : 1 ,
65
+ 'channels.value' : 1 ,
66
+ 'channels.verified' : 1 ,
64
67
} ,
68
+ partialFilterExpression : { 'channels.verified' : true } ,
69
+ name : 'verificationKey' ,
70
+ unique : false ,
71
+ } ,
72
+ {
73
+ key : {
74
+ preRegistration : 1 ,
75
+ } ,
76
+ sparse : true ,
65
77
unique : false ,
66
78
} ,
67
79
] ;
@@ -73,6 +85,7 @@ export class LivechatContactsRaw extends BaseRaw<ILivechatContact> implements IL
73
85
const result = await this . insertOne ( {
74
86
createdAt : new Date ( ) ,
75
87
...data ,
88
+ preRegistration : ! data . channels . length ,
76
89
} ) ;
77
90
78
91
return result . insertedId ;
@@ -81,7 +94,7 @@ export class LivechatContactsRaw extends BaseRaw<ILivechatContact> implements IL
81
94
async updateContact ( contactId : string , data : Partial < ILivechatContact > , options ?: FindOneAndUpdateOptions ) : Promise < ILivechatContact > {
82
95
const updatedValue = await this . findOneAndUpdate (
83
96
{ _id : contactId } ,
84
- { $set : { ...data , unknown : false } } ,
97
+ { $set : { ...data , unknown : false , ... ( data . channels && { preRegistration : ! data . channels . length } ) } } ,
85
98
{ returnDocument : 'after' , ...options } ,
86
99
) ;
87
100
return updatedValue . value as ILivechatContact ;
@@ -132,7 +145,7 @@ export class LivechatContactsRaw extends BaseRaw<ILivechatContact> implements IL
132
145
] ,
133
146
} ,
134
147
{
135
- channels : [ ] ,
148
+ preRegistration : true ,
136
149
} ,
137
150
] ,
138
151
} ;
@@ -164,7 +177,7 @@ export class LivechatContactsRaw extends BaseRaw<ILivechatContact> implements IL
164
177
}
165
178
166
179
async addChannel ( contactId : string , channel : ILivechatContactChannel ) : Promise < void > {
167
- await this . updateOne ( { _id : contactId } , { $push : { channels : channel } } ) ;
180
+ await this . updateOne ( { _id : contactId } , { $push : { channels : channel } , $set : { preRegistration : false } } ) ;
168
181
}
169
182
170
183
async updateLastChatById (
0 commit comments