tango-app-api-trax 3.3.1-hotfix-21 → 3.3.1-hotfix-22

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": "tango-app-api-trax",
3
- "version": "3.3.1-hotfix-21",
3
+ "version": "3.3.1-hotfix-22",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -5,7 +5,7 @@ import * as processedchecklistService from '../services/processedchecklist.servi
5
5
  import * as processedTaskService from '../services/processedTaskList.service.js';
6
6
  import * as taskConfigService from '../services/taskConfig.service.js';
7
7
  import * as checklistService from '../services/checklist.service.js';
8
- // import * as processedTaskconfigService from '../services/processedTaskConfig.service.js';
8
+ import * as processedcheklistconfigService from '../services/processedchecklistconfig.services.js';
9
9
  import * as clientService from '../services/clients.services.js';
10
10
  import * as storeService from '../services/store.service.js';
11
11
 
@@ -143,8 +143,9 @@ export const downloadInsert = async ( req, res ) => {
143
143
  'viewRedo': requestData.viewRedo || false,
144
144
  'userEmailList': requestData.userEmailList || [],
145
145
  'filtertype': requestData.filtertype || 'Clusters',
146
-
146
+ 'checkListType': requestData.checkListType,
147
147
  };
148
+ console.log( insertData );
148
149
  let resultData = await downloadService.insert( insertData );
149
150
  if ( resultData ) {
150
151
  let sqsMessageRequestData = {
@@ -171,6 +172,101 @@ export const downloadInsert = async ( req, res ) => {
171
172
  return res.sendError( e, 500 );
172
173
  }
173
174
  };
175
+ export const downloadInsertAI = async ( req, res ) => {
176
+ try {
177
+ let requestData = req.body;
178
+ let name;
179
+ let fileType = requestData?.fileType || 'pdfzip';
180
+
181
+
182
+ if ( requestData.fileType == 'pdf' ) {
183
+ if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id != '' ) {
184
+ fileType = 'pdfzip';
185
+ }
186
+ if ( requestData?.checklistId && requestData?.checklistId.length > 1 ) {
187
+ fileType = 'pdfzip';
188
+ }
189
+ }
190
+
191
+ if ( requestData.checklistName != '' ) {
192
+ name = requestData.checklistName + '_' + dayjs( requestData.fromDate ).format( 'DD/MM/YYYY' );
193
+ if ( requestData?.toDate ) {
194
+ name = name + '-' + dayjs( requestData?.toDate ).format( 'DD/MM/YYYY' );
195
+ }
196
+ let regexName = new RegExp( `^${name.split( '(' )[0]} \\(.*\\)$`, 'i' );
197
+ let type = requestData.fileType || 'pdfzip';
198
+ let downloadDetails = await downloadService.getCount( { $and: [ { $or: [ { name: { $regex: regexName } }, { name: name } ] }, { fileType: type } ] } );
199
+ if ( downloadDetails ) {
200
+ name = name + ' (' + downloadDetails + ')';
201
+ }
202
+ } else {
203
+ name = requestData?.checklistName;
204
+ }
205
+
206
+
207
+ let findchecklist = await processedcheklistconfigService.findOne( { 'checkListType': requestData.checkListType, 'client_id': requestData.clientId } ).sort( { _id: -1 } );
208
+
209
+ console.log( findchecklist );
210
+ name = name + '-' + requestData.fileType;
211
+ let insertData = {
212
+ 'date_string': requestData.fromDate || '',
213
+ 'sourceCheckList_id': requestData?.sourceCheckList_id || '',
214
+ 'checklistIdList': requestData?.checklistId || [],
215
+ 'status': 'inprogress',
216
+ 'client_id': requestData.clientId || '',
217
+ 'date_iso': new Date( requestData.fromDate ) || '',
218
+ 'createdBy': req.user._id || '',
219
+ 'name': name,
220
+ 'fileType': fileType,
221
+ 'storeIds': requestData.storeIds || [],
222
+ 'questions': requestData.questions || [],
223
+ 'fromDate': requestData.fromDate || '',
224
+ 'toDate': requestData.toDate || '',
225
+ 'previewType': requestData.previewType || '',
226
+ 'viewFlag': requestData.viewFlag || false,
227
+ 'userEmail': req.user.email || '',
228
+ 'createdBy': req.user._id || '',
229
+ 'downloadInsertFrom': requestData.downloadInsertFrom || '',
230
+ 'answerType': requestData.answerType || '',
231
+ 'searchValue': requestData.searchValue || '',
232
+ 'insertType': requestData.insertType || '',
233
+ 'viewRedo': requestData.viewRedo || false,
234
+ 'userEmailList': requestData.userEmailList || [],
235
+ 'filtertype': requestData.filtertype || 'Clusters',
236
+ 'checkListType': requestData.checkListType,
237
+ 'checkListName': findchecklist.checkListName,
238
+ 'checkListDescription': findchecklist.checkListDescription,
239
+
240
+ };
241
+ console.log( requestData );
242
+ console.log( insertData );
243
+
244
+ let resultData = await downloadService.insert( insertData );
245
+ if ( resultData ) {
246
+ let sqsMessageRequestData = {
247
+ 'zipId': resultData._id,
248
+ 'fileType': fileType || 'zip',
249
+ 'storeId': requestData.storeIds || [],
250
+ };
251
+ if ( fileType === 'csv' || fileType === 'pdf' || fileType === 'csvzip' || fileType === 'pdfzip' || fileType === 'zipfiles' ) {
252
+ const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
253
+ console.log( 'Send SQS Message CSV/PDF=>', msg );
254
+ }
255
+
256
+ if ( fileType === 'ppt' || fileType === 'pptzip' ) {
257
+ const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
258
+ console.log( 'Send SQS Message PPT=>', msg );
259
+ }
260
+
261
+ res.sendSuccess( 'Success' );
262
+ } else {
263
+ return res.sendError( 'something went wrong, please try again', 500 );
264
+ }
265
+ } catch ( e ) {
266
+ console.log( 'insertdownloadRequest =>', e );
267
+ return res.sendError( e, 500 );
268
+ }
269
+ };
174
270
 
175
271
  export const downloadInsertOld = async ( req, res ) => {
176
272
  try {
@@ -1454,6 +1454,37 @@ export async function getPDFCSVChecklistDetails( req, res ) {
1454
1454
  }
1455
1455
 
1456
1456
 
1457
+ export async function AiPushNotificationAlert( req, res ) {
1458
+ try {
1459
+ console.log( req.body );
1460
+ let findAichecklist = await PCLconfig.findOne( { checkListType: req.body.checkListType, client_id: req.body.clientId, date_string: req.body.Date }, { aiConfig: 1 } );
1461
+ if ( findAichecklist.aiConfig&&findAichecklist.aiConfig.alerts&&findAichecklist.aiConfig.alerts.users&&findAichecklist.aiConfig.alerts.users.length>0 ) {
1462
+ console.log( findAichecklist.aiConfig.alerts.users );
1463
+ for ( let user of findAichecklist.aiConfig.alerts.users ) {
1464
+ let findOneUser = await userService.findOne( { email: user }, { fcmToken: 1 } );
1465
+ console.log( findOneUser );
1466
+ if ( findOneUser&&findOneUser.fcmToken&&findOneUser.fcmToken!='' ) {
1467
+ console.log( findOneUser.fcmToken );
1468
+ try {
1469
+ await sendPushNotification( req.body.title, req.body.description, findOneUser.fcmToken );
1470
+ } catch ( e ) {
1471
+ logger.error( {
1472
+ message: 'push notification',
1473
+ error: e,
1474
+ details: data,
1475
+ } );
1476
+ }
1477
+ } ;
1478
+ }
1479
+ return res.sendSuccess( 'Push notification send successfully' );
1480
+ }
1481
+ } catch ( e ) {
1482
+ logger.error( { function: 'AiPushNotificationAlert', error: e } );
1483
+ return res.sendError( e, 500 );
1484
+ }
1485
+ }
1486
+
1487
+
1457
1488
  export async function taskPushNotification( req, res ) {
1458
1489
  try {
1459
1490
  let query = [ {
@@ -25,7 +25,7 @@ export const validateDownloadInsertSchema = joi.object( {
25
25
  insertType: joi.string().optional().allow( '' ),
26
26
  filter: joi.string().optional().allow( '' ),
27
27
  filtertype: joi.string().optional().allow( '' ),
28
-
28
+ checkListType: joi.string().required(),
29
29
  } );
30
30
 
31
31
  export const validateDownloadInsertParams = {