rez_core 2.2.196 → 2.2.197

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.196",
3
+ "version": "2.2.197",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -40,10 +40,16 @@ import { TelephoneFactory } from './factories/telephone.factory';
40
40
  import { CommunicationFactory } from './factories/communication.factory';
41
41
  import { GoogleController } from './controller/calender-event.controller';
42
42
  import { GoogleService } from './service/calendar-event.service';
43
+ import { WrapperService } from './service/wrapper.service';
44
+ import { WrapperController } from './controller/wrapper.controller';
45
+ import { IcsMeetingModule } from '../ics/ics.module';
43
46
 
44
47
  @Module({
45
- imports: [TypeOrmModule.forFeature([CommunicationConfig, CommunicationHub])],
46
- controllers: [CommunicationController, GoogleController],
48
+ imports: [
49
+ TypeOrmModule.forFeature([CommunicationConfig, CommunicationHub]),
50
+ IcsMeetingModule,
51
+ ],
52
+ controllers: [CommunicationController, GoogleController, WrapperController],
47
53
  providers: [
48
54
  // Main Services
49
55
  CommunicationService,
@@ -79,11 +85,13 @@ import { GoogleService } from './service/calendar-event.service';
79
85
  CommunicationFactory,
80
86
 
81
87
  GoogleService,
88
+ WrapperService,
82
89
  ],
83
90
  exports: [
84
91
  CommunicationService,
85
92
  CommunicationFactory,
86
93
  CommunicationQueueService,
94
+ WrapperService,
87
95
  ],
88
96
  })
89
97
  export class CommunicationModule {}
@@ -0,0 +1,39 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ HttpCode,
5
+ HttpStatus,
6
+ Post,
7
+ Req,
8
+ UseGuards,
9
+ } from '@nestjs/common';
10
+ import { WrapperService } from '../service/wrapper.service';
11
+ import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
12
+
13
+ @Controller('wrapper')
14
+ @UseGuards(JwtAuthGuard)
15
+ export class WrapperController {
16
+ constructor(private readonly wrapperService: WrapperService) {}
17
+
18
+ /**
19
+ * API for sending mail (uses WrapperService.sendMailWrapper)
20
+ */
21
+ @Post('send-mail')
22
+ @HttpCode(HttpStatus.OK)
23
+ async sendMail(@Body() payload: any, @Req() req: any) {
24
+ const loggedInUser = req.user.userData;
25
+
26
+ return this.wrapperService.sendMailWrapper(payload, loggedInUser);
27
+ }
28
+
29
+ /**
30
+ * API for scheduling meeting (uses WrapperService.scheduleMeetingWrapper)
31
+ */
32
+ @Post('schedule-meeting')
33
+ @HttpCode(HttpStatus.OK)
34
+ async scheduleMeeting(@Body() payload: any, @Req() req: any) {
35
+ const loggedInUser = req.user.userData;
36
+
37
+ return this.wrapperService.scheduleMeetingWrapper(payload, loggedInUser);
38
+ }
39
+ }
@@ -23,7 +23,7 @@ export class WrapperService {
23
23
  */
24
24
  async sendMailWrapper(payload: any, loggedInUser: any) {
25
25
  try {
26
- const { level_id, level_type } = loggedInUser;
26
+ const { level_id, level_type, organization_id } = loggedInUser;
27
27
 
28
28
  // 1. Check for config at user’s level
29
29
  const configs = await this.datasource.query(
@@ -35,6 +35,34 @@ export class WrapperService {
35
35
  [level_id, level_type],
36
36
  );
37
37
 
38
+ let templateCode: string | undefined;
39
+
40
+ if (payload.templateCode) {
41
+ // Try current level first
42
+ const template = await this.datasource.query(
43
+ `SELECT code FROM cr_wf_comm_template WHERE code = ? AND level_id = ? AND level_type = ? LIMIT 1`,
44
+ [payload.templateCode, level_id, level_type],
45
+ );
46
+
47
+ if (template && template.length > 0) {
48
+ templateCode = template[0].code;
49
+ } else {
50
+ // Fallback → ORG level
51
+ const fallbackTemplate = await this.datasource.query(
52
+ `SELECT code FROM cr_wf_comm_template WHERE code = ? AND level_id = ? AND level_type = 'ORG' LIMIT 1`,
53
+ [payload.templateCode, organization_id],
54
+ );
55
+
56
+ if (!fallbackTemplate || fallbackTemplate.length === 0) {
57
+ throw new Error(
58
+ `Template with code ${payload.templateCode} not found at user or org level`,
59
+ );
60
+ }
61
+
62
+ templateCode = fallbackTemplate[0].code;
63
+ }
64
+ }
65
+
38
66
  let payloadSendMail: GenericMessageDto;
39
67
 
40
68
  if (configs && configs.length > 0) {
@@ -49,7 +77,7 @@ export class WrapperService {
49
77
  bcc: payload.bcc,
50
78
  html: payload.html,
51
79
  attachments: payload.attachments,
52
- templateId: payload.templateId,
80
+ templateId: templateCode,
53
81
  variables: payload.variables,
54
82
  };
55
83
  } else {
@@ -120,6 +148,7 @@ export class WrapperService {
120
148
  );
121
149
 
122
150
  let configCred;
151
+ let result;
123
152
 
124
153
  if (configs && configs.length > 0) {
125
154
  // only if type is gmail
@@ -136,14 +165,11 @@ export class WrapperService {
136
165
 
137
166
  configCred = configCred[0].config_json;
138
167
  // 3. Call google service
139
- const result = await this.googleService.createEvent(
140
- configCred,
141
- payload,
142
- );
168
+ result = await this.googleService.createEvent(configCred, payload);
143
169
  } else {
144
170
  const base64String = await this.icsService.generateIcs(payload);
145
171
 
146
- const result = await this.communicationService.sendGenericMessage({
172
+ result = await this.communicationService.sendGenericMessage({
147
173
  ...payload,
148
174
  attachments: [
149
175
  {
@@ -158,6 +184,7 @@ export class WrapperService {
158
184
 
159
185
  return {
160
186
  success: true,
187
+ data: result,
161
188
  };
162
189
  } catch (error: any) {
163
190
  this.logger.error('scheduleMeetingWrapper error', error.message);
@@ -32,6 +32,7 @@ export class FilterController {
32
32
  @Query() queryParams: Record<string, string>,
33
33
  @Query('level_type') levelType?: string,
34
34
  @Query('level_id') levelId?: number,
35
+ @Query('appcode') appCode?: string,
35
36
  ) {
36
37
  const loggedInUser = req.user.userData;
37
38
 
@@ -60,6 +61,7 @@ export class FilterController {
60
61
  queryParams: otherQueryParams, // only remaining query params
61
62
  customLevelType: levelType,
62
63
  customLevelId: levelId,
64
+ customAppCode: appCode,
63
65
  });
64
66
  }
65
67
 
@@ -29,4 +29,5 @@ export interface FilterRequestDto {
29
29
  queryParams?: Record<string, string>;
30
30
  customLevelType?: string;
31
31
  customLevelId?: number;
32
+ customAppCode?: string;
32
33
  }
@@ -81,6 +81,7 @@ export class FilterService {
81
81
  queryParams,
82
82
  customLevelType,
83
83
  customLevelId,
84
+ customAppCode,
84
85
  } = dto;
85
86
 
86
87
  // abstract user details
@@ -168,14 +169,15 @@ export class FilterService {
168
169
  });
169
170
  }
170
171
 
171
- if (customLevelType && customLevelId) {
172
+ if (customLevelType && customLevelId && customAppCode) {
172
173
  baseWhere.push({
173
174
  query:
174
- 'e.organization_id = :organization_id AND e.level_type = :customLevelType AND e.level_id = :customLevelId',
175
+ 'e.organization_id = :organization_id AND e.level_type = :customLevelType AND e.level_id = :customLevelId AND e.appcode = :customAppCode',
175
176
  params: {
176
177
  organization_id,
177
178
  customLevelType,
178
179
  customLevelId,
180
+ customAppCode,
179
181
  },
180
182
  });
181
183
  }
@@ -8,7 +8,7 @@ import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
8
8
  import { ActivityLogService } from './activity-log.service';
9
9
  import { ACTIVITY_CATEGORIES } from '../repository/activity-log.repository';
10
10
  import { MediaDataService } from 'src/module/meta/service/media-data.service';
11
- import { Cron, CronExpression } from '@nestjs/schedule';
11
+ // import { Cron, CronExpression } from '@nestjs/schedule';
12
12
  import { NotificationsService } from 'src/module/notification/service/notification.service';
13
13
 
14
14
  @Injectable()