tango-app-api-trax 3.3.1-beta-10 → 3.3.1-beta-12

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-beta-10",
3
+ "version": "3.3.1-beta-12",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  "nodemon": "^3.1.4",
28
28
  "path": "^0.12.7",
29
29
  "tango-api-schema": "^2.2.41",
30
- "tango-app-api-middleware": "^3.1.50",
30
+ "tango-app-api-middleware": "^3.1.55",
31
31
  "url": "^0.11.4",
32
32
  "winston": "^3.13.1",
33
33
  "winston-daily-rotate-file": "^5.0.0"
@@ -113,7 +113,7 @@ export async function startChecklist( req, res ) {
113
113
  return res.sendError( 'already check list started', 400 );
114
114
  }
115
115
 
116
- logger.info( `v5 => Checklist Started => store Name: ${getBeforeChecklist[0].storeName}, User Email: ${getBeforeChecklist[0].userEmail}, Checklist Name: ${getBeforeChecklist[0].checkListName}` );
116
+ logger.info( `v5 => Checklist Started => store Name: ${getBeforeChecklist[0].storeName || ''}, User Email: ${getBeforeChecklist[0].userEmail}, Checklist Name: ${getBeforeChecklist[0].checkListName}` );
117
117
  let PCLQusestion = await PCLconfig.findOne( { _id: new ObjectId( getBeforeChecklist[0].checkListId ) } );
118
118
  let updateQuery = {};
119
119
  updateQuery._id = new ObjectId( requestData.processedcheckListId );
@@ -149,10 +149,14 @@ export async function startChecklist( req, res ) {
149
149
  }
150
150
 
151
151
  let updateData = {};
152
- let storeTimeZone = await storeService.findOne( { storeName: { $regex: getBeforeChecklist[0].storeName, $options: 'i' }, clientId: getBeforeChecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
153
152
  let currentDateTime;
154
- if ( storeTimeZone?.storeProfile?.timeZone ) {
155
- currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
153
+ if ( getBeforeChecklist[0].storeName && getBeforeChecklist[0].storeName!='' ) {
154
+ let storeTimeZone = await storeService.findOne( { storeName: { $regex: getBeforeChecklist[0].storeName, $options: 'i' }, clientId: getBeforeChecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
155
+ if ( storeTimeZone?.storeProfile?.timeZone ) {
156
+ currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
157
+ } else {
158
+ currentDateTime = dayjs();
159
+ }
156
160
  } else {
157
161
  currentDateTime = dayjs();
158
162
  }
@@ -171,6 +175,8 @@ export async function startChecklist( req, res ) {
171
175
  findQuery.push( {
172
176
  $project: {
173
177
  checkListName: { $ifNull: [ '$checkListName', '' ] },
178
+ coverage: { $ifNull: [ '$coverage', '' ] },
179
+ client_id: { $ifNull: [ '$client_id', '' ] },
174
180
  scheduleStartTime: { $ifNull: [ '$scheduleStartTime', '' ] },
175
181
  scheduleStartTime_iso: { $ifNull: [ '$scheduleStartTime_iso', '' ] },
176
182
  scheduleEndTime: { $ifNull: [ '$scheduleEndTime', '' ] },
@@ -185,7 +191,13 @@ export async function startChecklist( req, res ) {
185
191
  $cond: {
186
192
  if: { $eq: [ '$client_id', '11' ] },
187
193
  then: false,
188
- else: { $ifNull: [ '$allowedStoreLocation', false ] },
194
+ else: {
195
+ '$cond': {
196
+ 'if': { '$eq': [ '$coverage', 'user' ] },
197
+ 'then': false,
198
+ 'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
199
+ },
200
+ },
189
201
  },
190
202
  },
191
203
  questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
@@ -207,8 +219,8 @@ export async function startChecklist( req, res ) {
207
219
  } );
208
220
  } );
209
221
  let logInsertData = {
210
- store_id: getBeforeChecklist[0].store_id,
211
- storeName: getBeforeChecklist[0].storeName,
222
+ store_id: getBeforeChecklist[0]?.store_id || '',
223
+ storeName: getBeforeChecklist[0]?.storeName || '',
212
224
  action: 'started',
213
225
  checklistId: getBeforeChecklist[0].sourceCheckList_id,
214
226
  processedChecklistId: getBeforeChecklist[0]._id,
@@ -217,7 +229,6 @@ export async function startChecklist( req, res ) {
217
229
  client_id: req.user.clientId,
218
230
  };
219
231
  await checklistLogs.create( logInsertData );
220
-
221
232
  let getchecklist = getupdatedchecklist;
222
233
  let questions = [];
223
234
  // function processQuestion( question, section, questions, nested=false ) {
@@ -263,6 +274,7 @@ export async function startChecklist( req, res ) {
263
274
  return res.sendError( 'something went wrong please try again', 500 );
264
275
  }
265
276
  } catch ( e ) {
277
+ console.log( 'e =>', e );
266
278
  logger.error( { function: 'startChecklist', error: e, body: req.body } );
267
279
  return res.sendError( e, 500 );
268
280
  }
@@ -366,7 +378,13 @@ export async function startTask( req, res ) {
366
378
  $cond: {
367
379
  if: { $eq: [ '$client_id', '11' ] },
368
380
  then: false,
369
- else: { $ifNull: [ '$allowedStoreLocation', false ] },
381
+ else: {
382
+ '$cond': {
383
+ 'if': { '$eq': [ '$coverage', 'user' ] },
384
+ 'then': false,
385
+ 'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
386
+ },
387
+ },
370
388
  },
371
389
  },
372
390
  questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
@@ -1726,10 +1744,16 @@ export async function submitChecklist( req, res ) {
1726
1744
  updateQuery._id = new ObjectId( requestData.processedcheckListId );
1727
1745
  updateQuery.userId = req.user._id;
1728
1746
  updateQuery.date_string = requestData.date;
1729
- let storeTimeZone = await storeService.findOne( { storeName: { $regex: getchecklist[0].storeName, $options: 'i' }, clientId: getchecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
1747
+
1730
1748
  let currentDateTime;
1731
- if ( storeTimeZone?.storeProfile?.timeZone ) {
1732
- currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
1749
+ let storeTimeZone;
1750
+ if ( getchecklist[0].storeName && getchecklist[0].storeName !='' ) {
1751
+ storeTimeZone = await storeService.findOne( { storeName: { $regex: getchecklist[0].storeName, $options: 'i' }, clientId: getchecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
1752
+ if ( storeTimeZone?.storeProfile?.timeZone ) {
1753
+ currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
1754
+ } else {
1755
+ currentDateTime = requestData?.currentTime ? dayjs( requestData.currentTime, 'HH:mm:ss' ) : dayjs();
1756
+ }
1733
1757
  } else {
1734
1758
  currentDateTime = requestData?.currentTime ? dayjs( requestData.currentTime, 'HH:mm:ss' ) : dayjs();
1735
1759
  }
@@ -1775,8 +1799,8 @@ export async function submitChecklist( req, res ) {
1775
1799
  }
1776
1800
 
1777
1801
  let logInsertData = {
1778
- store_id: getchecklist[0].store_id,
1779
- storeName: getchecklist[0].storeName,
1802
+ store_id: getchecklist[0].store_id || '',
1803
+ storeName: getchecklist[0].storeName || '',
1780
1804
  action: requestData?.submittype === 'draft' ? 'saved' : 'submitted',
1781
1805
  checklistId: getchecklist[0].sourceCheckList_id,
1782
1806
  processedChecklistId: getchecklist[0]._id,
@@ -1785,7 +1809,7 @@ export async function submitChecklist( req, res ) {
1785
1809
  client_id: req.user.clientId,
1786
1810
  redoStatus: requestData?.redoStatus ? true : false,
1787
1811
  };
1788
-
1812
+ console.log( 'logInsertData=>', logInsertData );
1789
1813
  await checklistLogs.create( logInsertData );
1790
1814
  // let time = dayjs().format( 'HH:mm:ss' );
1791
1815
  // let [ hours, minutes ] = time.split( ':' ).map( Number );
@@ -2183,17 +2207,24 @@ export async function dashboard( req, res ) {
2183
2207
  export async function dashboardv1( req, res ) {
2184
2208
  try {
2185
2209
  // eslint-disable-next-line camelcase
2186
- const { store_id, date } = req.query;
2210
+ // const { store_id, date } = req.query;
2211
+ const { date } = req.query;
2187
2212
  const userId = req.user._id;
2188
2213
 
2214
+ // //Get User Based Checklist //
2215
+ const clientId = { client_id: req.user.clientId };
2216
+ const storeMatch = { $or: [ { store_id: { $eq: req.query.store_id || '' } }, { store_id: { $eq: '' } } ] };
2217
+ // //End: Get User Based Checklist////
2218
+
2189
2219
  const baseMatch = {
2190
2220
  // eslint-disable-next-line camelcase
2191
- store_id,
2221
+ // store_id,
2192
2222
  userId,
2193
2223
  date_string: date,
2194
2224
  timeFlagStatus: true,
2225
+ ...clientId,
2226
+ ...storeMatch,
2195
2227
  };
2196
-
2197
2228
  const buildPipeline = ( matchExtraConditions = {} ) => [
2198
2229
  { $match: { ...baseMatch, ...matchExtraConditions } },
2199
2230
  {
@@ -2249,6 +2280,7 @@ export async function dashboardv1( req, res ) {
2249
2280
 
2250
2281
  return res.sendSuccess( totalResult );
2251
2282
  } catch ( e ) {
2283
+ console.log( 'v1 =>', e );
2252
2284
  logger.error( { function: 'dashboardv1', error: e, body: req.body } );
2253
2285
  return res.sendError( e, 500 );
2254
2286
  }
@@ -2317,7 +2349,13 @@ export async function checklist( req, res ) {
2317
2349
  $cond: {
2318
2350
  if: { $eq: [ '$client_id', '11' ] },
2319
2351
  then: false,
2320
- else: { $ifNull: [ '$allowedStoreLocation', false ] },
2352
+ else: {
2353
+ '$cond': {
2354
+ 'if': { '$eq': [ '$coverage', 'user' ] },
2355
+ 'then': false,
2356
+ 'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
2357
+ },
2358
+ },
2321
2359
  },
2322
2360
  },
2323
2361
  reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
@@ -2349,19 +2387,26 @@ export async function checklist( req, res ) {
2349
2387
  export async function checklistv1( req, res ) {
2350
2388
  try {
2351
2389
  // eslint-disable-next-line camelcase
2352
- const { store_id, date, checklistStatus, searchValue } = req.query;
2390
+ // const { store_id, date, checklistStatus, searchValue } = req.query;
2391
+ const { date, checklistStatus, searchValue } = req.query;
2353
2392
  const userId = req.user._id;
2354
2393
 
2394
+ // Get User Based Checklist //
2395
+ const clientId = { client_id: req.user.clientId };
2396
+ const storeMatch = { $or: [ { store_id: { $eq: req.query.store_id || '' } }, { store_id: { $eq: '' } } ] };
2397
+ // End: Get User Based Checklist////
2398
+
2355
2399
  const buildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
2356
2400
  const matchConditions = [
2357
2401
  // eslint-disable-next-line camelcase
2358
- { store_id },
2402
+ // { store_id },
2359
2403
  { userId },
2360
2404
  { date_string: date },
2361
2405
  { timeFlagStatus: true },
2362
2406
  ...matchExtraConditions,
2407
+ clientId,
2408
+ storeMatch,
2363
2409
  ];
2364
-
2365
2410
  if ( checklistStatus ) {
2366
2411
  matchConditions.push( { checklistStatus } );
2367
2412
  }
@@ -2388,7 +2433,13 @@ export async function checklistv1( req, res ) {
2388
2433
  $cond: {
2389
2434
  if: { $eq: [ '$client_id', '11' ] },
2390
2435
  then: false,
2391
- else: { $ifNull: [ '$allowedStoreLocation', false ] },
2436
+ else: {
2437
+ '$cond': {
2438
+ 'if': { '$eq': [ '$coverage', 'user' ] },
2439
+ 'then': false,
2440
+ 'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
2441
+ },
2442
+ },
2392
2443
  },
2393
2444
  },
2394
2445
  reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
@@ -2401,6 +2452,8 @@ export async function checklistv1( req, res ) {
2401
2452
  type: { $ifNull: [ '$checkListType', '' ] },
2402
2453
  priorityType: { $ifNull: [ '$priorityType', '' ] },
2403
2454
  ...projectExtraConditions,
2455
+ client_id: { $ifNull: [ '$client_id', '' ] },
2456
+ coverage: { $ifNull: [ '$coverage', '' ] },
2404
2457
  },
2405
2458
  },
2406
2459
  ];
@@ -2479,7 +2532,13 @@ export async function questionList( req, res ) {
2479
2532
  $cond: {
2480
2533
  if: { $eq: [ '$client_id', '11' ] },
2481
2534
  then: false,
2482
- else: { $ifNull: [ '$allowedStoreLocation', false ] },
2535
+ else: {
2536
+ '$cond': {
2537
+ 'if': { '$eq': [ '$coverage', 'user' ] },
2538
+ 'then': false,
2539
+ 'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
2540
+ },
2541
+ },
2483
2542
  },
2484
2543
  },
2485
2544
  reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
@@ -2798,7 +2857,13 @@ export async function taskQuestionList( req, res ) {
2798
2857
  $cond: {
2799
2858
  if: { $eq: [ '$client_id', '11' ] },
2800
2859
  then: false,
2801
- else: { $ifNull: [ '$allowedStoreLocation', false ] },
2860
+ else: {
2861
+ '$cond': {
2862
+ 'if': { '$eq': [ '$coverage', 'user' ] },
2863
+ 'then': false,
2864
+ 'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
2865
+ },
2866
+ },
2802
2867
  },
2803
2868
  },
2804
2869
  reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },