rez_core 2.2.263 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.2.263",
3
+ "version": "2.3.1",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -456,4 +456,41 @@ export class IntegrationController {
456
456
  }
457
457
  }
458
458
  }
459
+
460
+ @Get('active-config')
461
+ async getActiveConfig(
462
+ @Query('level_id', ParseIntPipe) levelId: number,
463
+ @Query('level_type') levelType: string,
464
+ @Query('app_code') appCode: string,
465
+ @Query('integration_type') integrationType: 'EMAIL' | 'SMS' | 'WA' | 'TELEPHONE',
466
+ ) {
467
+ try {
468
+ const config = await this.integrationService.getSingleActiveConfig(
469
+ levelId,
470
+ levelType,
471
+ appCode,
472
+ integrationType,
473
+ );
474
+
475
+ if (!config) {
476
+ return {
477
+ success: false,
478
+ message: 'No active configuration found',
479
+ data: null,
480
+ };
481
+ }
482
+
483
+ return {
484
+ success: true,
485
+ data: config,
486
+ };
487
+ } catch (error) {
488
+ throw new BadRequestException({
489
+ success: false,
490
+ error: 'GET_ACTIVE_CONFIG_ERROR',
491
+ message: error.message || 'Failed to fetch active configuration',
492
+ code: 'FETCH_ERROR',
493
+ });
494
+ }
495
+ }
459
496
  }
@@ -170,6 +170,27 @@ export class IntegrationService {
170
170
  return await queryBuilder.getMany();
171
171
  }
172
172
 
173
+ async getSingleActiveConfig(
174
+ levelId: number,
175
+ levelType: string,
176
+ app_code: string,
177
+ integration_type: 'EMAIL' | 'SMS' | 'WA' | 'TELEPHONE',
178
+ ): Promise<IntegrationConfig | null> {
179
+ const configs = await this.configRepository
180
+ .createQueryBuilder('config')
181
+ .where('config.level_id = :levelId', { levelId })
182
+ .andWhere('config.level_type = :levelType', { levelType })
183
+ .andWhere('config.app_code = :app_code', { app_code })
184
+ .andWhere('config.integration_type = :integration_type', { integration_type })
185
+ .andWhere('config.status = 1')
186
+ .orderBy('config.is_default', 'DESC')
187
+ .addOrderBy('config.priority', 'ASC')
188
+ .addOrderBy('config.created_at', 'DESC')
189
+ .getMany();
190
+
191
+ return configs.length > 0 ? configs[0] : null;
192
+ }
193
+
173
194
  async getAllIntegrationData(
174
195
  loggedInUser,
175
196
  integration_type?: string,
@@ -23,12 +23,19 @@ export class NotificationsController {
23
23
 
24
24
  @Post('send')
25
25
  async sendNotification(
26
- @Body() body: { token: string; title: string; message: string },
26
+ @Body()
27
+ body: {
28
+ token: string;
29
+ title: string;
30
+ message: string;
31
+ data?: Record<string, any>;
32
+ },
27
33
  ) {
28
34
  return this.notificationsService.sendToDevice(
29
35
  body.token,
30
36
  body.title,
31
37
  body.message,
38
+ body.data,
32
39
  );
33
40
  }
34
41
 
@@ -20,13 +20,28 @@ export class NotificationsService {
20
20
  return { success: true, token };
21
21
  }
22
22
 
23
- async sendToDevice(token: string, title: string, body: string) {
24
- const message = {
23
+ async sendToDevice(
24
+ token: string,
25
+ title: string,
26
+ body: string,
27
+ data?: Record<string, any>,
28
+ ) {
29
+ const message: admin.messaging.Message = {
25
30
  token,
26
- notification: { title, body },
31
+ notification: { title, body }, // system notification
32
+ data: data
33
+ ? Object.fromEntries(
34
+ Object.entries(data).map(([k, v]) => [k, v.toString()]),
35
+ )
36
+ : undefined, // FCM requires all values to be strings
27
37
  };
28
38
 
29
- return this.firebaseAdmin.messaging().send(message);
39
+ try {
40
+ return await this.firebaseAdmin.messaging().send(message);
41
+ } catch (error) {
42
+ console.error(error);
43
+ throw error;
44
+ }
30
45
  }
31
46
 
32
47
  // Helper: send to a registered user by userId