@@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';
2
2
import { InjectRepository } from '@nestjs/typeorm' ;
3
3
import {
4
4
batchCreateMailchimpProfiles ,
5
+ batchUpdateMailchimpProfiles ,
5
6
createMailchimpMergeField ,
6
7
createMailchimpProfile ,
7
8
updateMailchimpProfile ,
@@ -234,7 +235,6 @@ export class ServiceUserProfilesService {
234
235
}
235
236
236
237
// Static bulk upload function to be used in specific cases e.g. bug prevented a subset of new users from being created
237
- // Currently no endpoint for this function
238
238
// UPDATE THE FILTERS to the current requirements
239
239
public async bulkUploadMailchimpProfiles ( ) {
240
240
try {
@@ -265,6 +265,40 @@ export class ServiceUserProfilesService {
265
265
throw new Error ( `Bulk upload mailchimp profiles API call failed: ${ error } ` ) ;
266
266
}
267
267
}
268
+ // Static bulk update function to be used in specific cases e.g. bug prevented a subset of users from being updated
269
+ // UPDATE THE FILTERS to the current requirements
270
+ public async bulkUpdateMailchimpProfiles ( ) {
271
+ try {
272
+ const filterStartDate = '2024-10-29' ; // UPDATE
273
+ const filterEndDate = '2025-01-06' ; // UPDATE
274
+ const users = await this . userRepository . find ( {
275
+ where : {
276
+ // UPDATE TO ANY FILTERS
277
+ updatedAt : And (
278
+ Raw ( ( alias ) => `${ alias } >= :filterStartDate` , { filterStartDate : filterStartDate } ) ,
279
+ Raw ( ( alias ) => `${ alias } < :filterEndDate` , { filterEndDate : filterEndDate } ) ,
280
+ ) ,
281
+ createdAt : Raw ( ( alias ) => `${ alias } < :filterStartDate` , {
282
+ filterStartDate : filterStartDate ,
283
+ } ) ,
284
+ } ,
285
+ relations : {
286
+ partnerAccess : { partner : true , therapySession : true } ,
287
+ courseUser : { course : true , sessionUser : { session : true } } ,
288
+ } ,
289
+ } ) ;
290
+ const mailchimpUserProfiles = users . map ( ( user ) =>
291
+ this . createCompleteMailchimpUserProfile ( user ) ,
292
+ ) ;
293
+
294
+ await batchUpdateMailchimpProfiles ( mailchimpUserProfiles ) ;
295
+ logger . log (
296
+ `Updated batch mailchimp profiles for ${ users . length } users, updated before ${ filterStartDate } ` ,
297
+ ) ;
298
+ } catch ( error ) {
299
+ throw new Error ( `Bulk update mailchimp profiles API call failed: ${ error } ` ) ;
300
+ }
301
+ }
268
302
269
303
serializePartnersString ( partnerAccesses : PartnerAccessEntity [ ] ) {
270
304
const partnersNames = partnerAccesses ?. map ( ( pa ) => pa . partner . name . toLowerCase ( ) ) ;
0 commit comments