tango-app-api-trax 1.0.0-alpha-task.132 → 1.0.0-alpha-task.134

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": "1.0.0-alpha-task.132",
3
+ "version": "1.0.0-alpha-task.134",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  "mongodb": "^6.8.0",
27
27
  "nodemon": "^3.1.4",
28
28
  "path": "^0.12.7",
29
- "tango-api-schema": "^2.1.97",
29
+ "tango-api-schema": "^2.1.99",
30
30
  "tango-app-api-middleware": "^3.1.43-alpha.10",
31
31
  "url": "^0.11.4",
32
32
  "winston": "^3.13.1",
@@ -279,6 +279,7 @@ export const downloadList = async ( req, res ) => {
279
279
  findAndQuery.push(
280
280
  { client_id: requestData.clientId },
281
281
  { createdBy: new mongoose.Types.ObjectId( requestData.createdBy ) },
282
+ { status: { $ne: 'canceled' } },
282
283
  );
283
284
 
284
285
  findQuery.push( { $match: { $and: findAndQuery } } );
@@ -418,6 +419,8 @@ export const getChecklistFromZipId = async ( req, res ) => {
418
419
  resultData.previewType = getzipdata.previewType || '';
419
420
  resultData.answerType = getzipdata.answerType || '';
420
421
  resultData.insertType = getzipdata.insertType;
422
+ resultData.status = getzipdata.status;
423
+
421
424
  return res.sendSuccess( resultData );
422
425
  } else {
423
426
  let getchecklistsQuery = {};
@@ -440,6 +443,7 @@ export const getChecklistFromZipId = async ( req, res ) => {
440
443
  resultData.fileType = getzipdata.fileType;
441
444
  resultData.questions = getzipdata.questions;
442
445
  resultData.insertType = getzipdata.insertType;
446
+ resultData.status = getzipdata.status;
443
447
  return res.sendSuccess( resultData );
444
448
  }
445
449
  } else {
@@ -566,3 +570,14 @@ export const getPDFCSVChecklistDetails = async ( req, res ) => {
566
570
  };
567
571
 
568
572
 
573
+ export async function cancelDownload( req, res ) {
574
+ try {
575
+ let update = await downloadService.updateOne( { _id: req.params.id }, { status: 'canceled' } );
576
+ if ( update ) {
577
+ return res.sendSuccess( 'Canceled Successfully' );
578
+ }
579
+ } catch ( error ) {
580
+ logger.error( { error: error, function: 'cancelDownload' } );
581
+ return res.sendError( error, 500 );
582
+ }
583
+ }
@@ -158,7 +158,7 @@ export const checklistDropdown = async ( req, res ) => {
158
158
  { client_id: requestData.clientId },
159
159
  // { date_iso: { $gte: fromDate } },
160
160
  // { date_iso: { $lte: toDate } },
161
- { checkListType: { $eq: 'custom' } },
161
+ // { checkListType: { $eq: 'custom' } },
162
162
  );
163
163
 
164
164
  findQuery.push( { $match: { $and: findAndQuery } } );
@@ -242,7 +242,17 @@ export const checklistDropdown = async ( req, res ) => {
242
242
  }
243
243
 
244
244
  let getChecklistData = await processedchecklistconfigService.aggregate( findQuery );
245
- result.checklistData = getChecklistData;
245
+
246
+ let AiCheklist = getChecklistData.filter( ( data ) => data.checkListType!='custom'&& data.publish== true );
247
+ let CustomCheklist = getChecklistData.filter( ( data ) => data.checkListType=='custom' );
248
+
249
+
250
+ AiCheklist.forEach( ( data ) => {
251
+ data.sourceCheckList_id = data.checkListType;
252
+ data.checkListType = 'AI';
253
+ } );
254
+
255
+ result.checklistData = [ ...CustomCheklist, ...AiCheklist ];
246
256
  return res.sendSuccess( result );
247
257
  } catch ( error ) {
248
258
  logger.error( { error: error, message: req.query, function: 'checklistDropdown' } );
@@ -435,11 +445,11 @@ export async function approvalstatus( req, res ) {
435
445
  try {
436
446
  let Approver = await ApproverModel.find( { checkListId: req.body.checklistId } );
437
447
  if ( Approver.length === 0 ) {
438
- return res.sendError( 'No Content', 204 );
448
+ return res.sendSuccess( 'suceess' );
439
449
  }
440
450
  let filterApprover = Approver.filter( ( data ) => data.userEmail=== req.user.email );
441
451
  if ( filterApprover.length === 0 ) {
442
- return res.sendError( 'No Content', 204 );
452
+ return res.sendSuccess( 'suceess' );
443
453
  }
444
454
 
445
455
 
@@ -200,9 +200,10 @@ export async function startChecklist( req, res ) {
200
200
  store_id: getBeforeChecklist[0].store_id,
201
201
  storeName: getBeforeChecklist[0].storeName,
202
202
  action: 'started',
203
- checklistId: getBeforeChecklist[0].checkListId,
203
+ checklistId: getBeforeChecklist[0].sourceCheckList_id,
204
+ processedChecklistId: getBeforeChecklist[0]._id,
204
205
  checkListName: getBeforeChecklist[0].checkListName,
205
- checkListType: getBeforeChecklist[0].checkListType,
206
+ type: getBeforeChecklist[0].checkListType,
206
207
  client_id: req.user.clientId,
207
208
  };
208
209
  await checklistLogs.create( logInsertData );
@@ -1006,7 +1007,10 @@ export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
1006
1007
  } else {
1007
1008
  let des = [];
1008
1009
  if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
1009
- let validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
1010
+ let validationAnswer = '';
1011
+ if ( requestSection[i].answer.split( '?' ).length > 1 ) {
1012
+ validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
1013
+ }
1010
1014
  if ( validationAnswer.length ) {
1011
1015
  let splitImgUrl = validationAnswer.split( '/' );
1012
1016
  if ( splitImgUrl.length > 1 ) {
@@ -1176,8 +1180,9 @@ export async function submitChecklist( req, res ) {
1176
1180
  checklistId: getchecklist[0].sourceCheckList_id,
1177
1181
  processedChecklistId: getchecklist[0]._id,
1178
1182
  checkListName: getchecklist[0].checkListName,
1179
- checkListType: getchecklist[0].checkListType,
1183
+ type: getchecklist[0].checkListType,
1180
1184
  client_id: req.user.clientId,
1185
+ redoStatus: requestData?.redoStatus ? true : false,
1181
1186
  };
1182
1187
 
1183
1188
  await checklistLogs.create( logInsertData );
@@ -1230,7 +1235,6 @@ export async function submitTask( req, res ) {
1230
1235
  const { body: requestData, user } = req;
1231
1236
  const { processedcheckListId, date, submittype, currentTime, questionAnswers } = requestData;
1232
1237
 
1233
-
1234
1238
  const findQuery = [
1235
1239
  {
1236
1240
  $match: {
@@ -1310,9 +1314,10 @@ export async function submitTask( req, res ) {
1310
1314
  action: submittype === 'draft' ? 'saved' : 'submitted',
1311
1315
  checklistId: checklist.sourceCheckList_id,
1312
1316
  processedChecklistId: checklist._id,
1313
- checkListType: checklist.checkListType,
1317
+ type: checklist.checkListType,
1314
1318
  checkListName,
1315
1319
  client_id: user.clientId,
1320
+ redoStatus: requestData?.redoStatus ? true : false,
1316
1321
  };
1317
1322
  await checklistLogs.create( logInsertData );
1318
1323
 
@@ -1346,9 +1351,10 @@ async function updateOpenSearch( user, data ) {
1346
1351
  store_id: getchecklist[0].store_id,
1347
1352
  storeName: getchecklist[0].storeName,
1348
1353
  action: 'OpenSearch insert Triggered',
1349
- checklistId: getchecklist[0].checkListId,
1354
+ checklistId: getchecklist[0].sourceCheckList_id,
1355
+ processedChecklistId: getchecklist[0]._id,
1350
1356
  checkListName: getchecklist[0].checkListName,
1351
- checkListType: getchecklist[0].checkListType,
1357
+ type: getchecklist[0].checkListType,
1352
1358
  client_id: user.clientId,
1353
1359
  };
1354
1360
  await checklistLogs.create( logInsertData );
@@ -1366,9 +1372,10 @@ async function updateOpenSearch( user, data ) {
1366
1372
  store_id: getchecklist[0].store_id,
1367
1373
  storeName: getchecklist[0].storeName,
1368
1374
  action: 'OpenSearch inserted Successfully',
1369
- checklistId: getchecklist[0].checkListId,
1375
+ checklistId: getchecklist[0].sourceCheckList_id,
1376
+ processedChecklistId: getchecklist[0]._id,
1370
1377
  checkListName: getchecklist[0].checkListName,
1371
- checkListType: getchecklist[0].checkListType,
1378
+ type: getchecklist[0].checkListType,
1372
1379
  client_id: user.clientId,
1373
1380
  };
1374
1381
  await checklistLogs.create( logInsertData );
@@ -1393,9 +1400,10 @@ async function updateOpenSearchTask( user, data ) {
1393
1400
  store_id: getchecklist[0].store_id,
1394
1401
  storeName: getchecklist[0].storeName,
1395
1402
  action: 'OpenSearch insert Triggered',
1396
- checklistId: getchecklist[0].checkListId,
1403
+ checklistId: getchecklist[0].sourceCheckList_id,
1404
+ processedChecklistId: getchecklist[0]._id,
1397
1405
  checkListName: getchecklist[0].checkListName,
1398
- checkListType: getchecklist[0].checkListType,
1406
+ type: getchecklist[0].checkListType,
1399
1407
  client_id: user.clientId,
1400
1408
  };
1401
1409
  await checklistLogs.create( logInsertData );
@@ -1413,9 +1421,10 @@ async function updateOpenSearchTask( user, data ) {
1413
1421
  store_id: getchecklist[0].store_id,
1414
1422
  storeName: getchecklist[0].storeName,
1415
1423
  action: 'OpenSearch inserted Successfully',
1416
- checklistId: getchecklist[0].checkListId,
1424
+ checklistId: getchecklist[0].sourceCheckList_id,
1425
+ processedChecklistId: getchecklist[0]._id,
1417
1426
  checkListName: getchecklist[0].checkListName,
1418
- checkListType: getchecklist[0].checkListType,
1427
+ type: getchecklist[0].checkListType,
1419
1428
  client_id: user.clientId,
1420
1429
  };
1421
1430
  await checklistLogs.create( logInsertData );
@@ -2182,15 +2191,15 @@ export async function login( req, res ) {
2182
2191
  return res.sendError( 'The user has been unauthorized to login', 401 );
2183
2192
  }
2184
2193
  if ( inputData.otp ) {
2185
- const otpMatching = await findOTP( { email: inputData.email, type: 'login', otp: inputData.otp } );
2194
+ const otpMatching = await findOTP( { email: result.email, type: 'login', otp: inputData.otp } );
2186
2195
  if ( !otpMatching?.length ) {
2187
2196
  return res.sendError( `Invalid OTP`, 401 );
2188
2197
  }
2189
2198
  } else {
2190
2199
  const otp = getOtp();
2191
- await updateOneOTP( { email: inputData.email, type: 'login' }, { email: inputData.email, otp: otp, type: 'login' } );
2200
+ await updateOneOTP( { email: result.email, type: 'login' }, { email: result.email, otp: otp, type: 'login' } );
2192
2201
  const emailVars = {
2193
- email: inputData.email,
2202
+ email: result.email,
2194
2203
  otp: otp,
2195
2204
  name: result.userName,
2196
2205
  };
@@ -2199,7 +2208,7 @@ export async function login( req, res ) {
2199
2208
  }
2200
2209
  const token = {
2201
2210
  authenticationToken: await getUuid(),
2202
- refreshToken: await getUuid(),
2211
+ ...( !result?.refreshToken ) ? { refreshToken: await getUuid() } : { refreshToken: result.refreshToken },
2203
2212
  };
2204
2213
  const record = {
2205
2214
  user: result?._id,
@@ -2215,7 +2224,9 @@ export async function login( req, res ) {
2215
2224
  }
2216
2225
 
2217
2226
  const auth = await create( record );
2218
- await userService.updateOne( { _id: result?._id }, { refreshToken: token?.refreshToken, fcmToken: inputData.fcmToken } );
2227
+ if ( !result?.refreshToken ) {
2228
+ await userService.updateOne( { _id: result?._id }, { refreshToken: token?.refreshToken } );
2229
+ }
2219
2230
 
2220
2231
  if ( auth ) {
2221
2232
  return res.sendSuccess( { result: token } );
@@ -400,8 +400,9 @@ export const userlist = async ( req, res ) => {
400
400
  try {
401
401
  let users = [];
402
402
  let query = {
403
- clientId: req.query.clientId || '11',
403
+ clientId: req.query.clientId,
404
404
  isActive: true,
405
+ role: { $ne: 'user' },
405
406
  };
406
407
 
407
408
  let userDetails = await userService.find( query );
@@ -415,6 +416,7 @@ export const userlist = async ( req, res ) => {
415
416
  id: item._id,
416
417
  userName: item.userName,
417
418
  email: item.email,
419
+ role: item.role,
418
420
  } );
419
421
  } );
420
422
  return res.sendSuccess( users );
@@ -535,6 +537,7 @@ export const duplicateChecklist = async ( req, res ) => {
535
537
  dupDetails.publish = false;
536
538
  dupDetails.createdAt = new Date();
537
539
  dupDetails.updatedAt = new Date();
540
+ dupDetails.publishDate = '';
538
541
  delete dupDetails._id;
539
542
  let logInsertData = {
540
543
  action: 'duplicateChecklist',
@@ -896,6 +899,11 @@ export const updateConfigure =async ( req, res ) => {
896
899
  return res.sendError( { message: 'Please Assigned a user' }, 400 );
897
900
  }
898
901
 
902
+ if ( !inputBody?.checkListDetails?.approver.length && inputBody.submitType == 'publish' ) {
903
+ return res.sendError( { message: 'Please assign approver' }, 400 );
904
+ }
905
+
906
+
899
907
  let logInsertData = {
900
908
  action: inputBody.submitType == 'publish' ? 'checklistPublishUsingConfigPage' : 'checklistConfigDraft',
901
909
  checklistId: inputBody.checkListDetails._id,
@@ -946,7 +954,9 @@ export const updateConfigure =async ( req, res ) => {
946
954
  configEndDate: inputBody?.checkListDetails?.configEndDate || '',
947
955
  specificDate: inputBody?.checkListDetails?.specificDate || [],
948
956
  allowOnce: inputBody?.checkListDetails?.allowOnce || false,
949
- approver: inputBody?.checkListDetails?.approver || [],
957
+ approver: inputBody?.checkListDetails?.approver.length ? inputBody?.checkListDetails?.approver.map( ( item ) => {
958
+ return { name: item.name, value: item.value };
959
+ } ) : [],
950
960
  remainder: inputBody?.checkListDetails?.remainder || [],
951
961
  owner: inputBody?.checkListDetails?.owner || [],
952
962
  };
@@ -10,6 +10,7 @@ import {
10
10
  downloadUpdate,
11
11
  getChecklistFromZipId,
12
12
  getPDFCSVChecklistDetails,
13
+ cancelDownload,
13
14
  } from '../controllers/download.controller.js';
14
15
 
15
16
  downloadRouter
@@ -17,7 +18,8 @@ downloadRouter
17
18
  .post( '/downloadList', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [] } ] } ), validate( downloadValidationDtos.validateDownloadListParams ), downloadList )
18
19
  .post( '/downloadUpdate', downloadUpdate ) // isAllowedInternalAPIHandler,
19
20
  .get( '/getChecklistFromZipId', getChecklistFromZipId ) // isAllowedInternalAPIHandler,
20
- .post( '/getChecklistDetails', getPDFCSVChecklistDetails );
21
+ .post( '/getChecklistDetails', getPDFCSVChecklistDetails )
22
+ .put( '/cancelDownload/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [] } ] } ), cancelDownload );
21
23
 
22
24
 
23
25
  export default downloadRouter;
@@ -1,11 +1,11 @@
1
1
  import model from 'tango-api-schema';
2
2
 
3
3
  export const findOne = async ( query={}, field={} ) => {
4
- return model.userModel.findOne( query, field );
4
+ return model.userModel.findOne( query, field ).sort( { userName: 1 } );
5
5
  };
6
6
 
7
7
  export const find = async ( query={}, field={} ) => {
8
- return model.userModel.find( query, field );
8
+ return model.userModel.find( query, field ).sort( { userName: 1 } );
9
9
  };
10
10
 
11
11
  export const create = async ( document = {} ) => {