tango-app-api-trax 3.4.1-activitylog-4 → 3.4.1-activitylog-6

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.4.1-activitylog-4",
3
+ "version": "3.4.1-activitylog-6",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,6 +25,7 @@ import handlebars from 'handlebars';
25
25
  dayjs.extend( customParseFormat );
26
26
  dayjs.extend( timeZone );
27
27
  import isSameOrBefore from 'dayjs/plugin/isSameOrBefore.js';
28
+ import * as cameraService from '../services/camera.service.js';
28
29
  dayjs.extend( isSameOrBefore );
29
30
 
30
31
  export async function storeList( req, res ) {
@@ -2102,6 +2103,189 @@ export async function submitTask( req, res ) {
2102
2103
  return res.sendError( error.message || 'Internal Server Error', 500 );
2103
2104
  }
2104
2105
  }
2106
+ export async function submiteyeTestTask( req, res ) {
2107
+ try {
2108
+ const { body: requestData, user } = req;
2109
+ const { processedcheckListId, date, submittype, currentTime, questionAnswers, streamId, qrCode } = requestData;
2110
+ console.log( requestData );
2111
+ if ( !streamId ) {
2112
+ return res.sendError( 'streamId is required', 400 );
2113
+ }
2114
+ if ( !qrCode||qrCode=='' ) {
2115
+ return res.sendError( 'qrCode is required', 400 );
2116
+ }
2117
+ let findoldQrExists = await cameraService.findOne( { qrCode: qrCode } );
2118
+ if ( findoldQrExists ) {
2119
+ return res.sendError( 'Qr code already Exists', 400 );
2120
+ }
2121
+ let findQrExists = await cameraService.findOne( { streamName: streamId, qrCode: qrCode } );
2122
+ console.log( findQrExists );
2123
+ if ( findQrExists ) {
2124
+ return res.sendError( 'Qr code already Exists', 400 );
2125
+ }
2126
+
2127
+ await cameraService.updateOne( { streamName: streamId }, { qrCode: qrCode } );
2128
+ return res.sendSuccess( 'Qr code added successfully' );
2129
+
2130
+ const findQuery = [
2131
+ {
2132
+ $match: {
2133
+ _id: new ObjectId( processedcheckListId ),
2134
+ userId: user._id,
2135
+ date_string: date,
2136
+ },
2137
+ },
2138
+ ];
2139
+
2140
+ const [ checklist ] = await processedTask.aggregate( findQuery );
2141
+
2142
+ if ( !checklist ) {
2143
+ return res.sendError( 'Task edited. Please fill again', 422 );
2144
+ }
2145
+
2146
+ // eslint-disable-next-line camelcase
2147
+ const { checklistStatus, storeName, userEmail, checkListName, store_id } = checklist;
2148
+
2149
+ if ( checklistStatus === 'open' ) {
2150
+ return res.sendError( 'Checklist is in open status. Please start.', 400 );
2151
+ }
2152
+
2153
+ if ( checklistStatus === 'submit' ) {
2154
+ return res.sendError( 'Checklist already submitted', 400 );
2155
+ }
2156
+
2157
+ const storeTimeZone = await storeService.findOne( { storeName }, { 'storeProfile.timeZone': 1 } );
2158
+ const currentDateTime = storeTimeZone?.storeProfile?.timeZone ?
2159
+ dayjs().tz( storeTimeZone.storeProfile.timeZone ) :
2160
+ dayjs();
2161
+
2162
+ const updateQuery = {
2163
+ _id: new ObjectId( processedcheckListId ),
2164
+ userId: user._id,
2165
+ date_string: date,
2166
+ };
2167
+
2168
+ // questionAnswers.forEach( ( section ) => {
2169
+ // section.questions.forEach( ( question ) => {
2170
+ // if ( question.redo === true ) {
2171
+ // question.redo = false;
2172
+ // }
2173
+ // } );
2174
+ // } );
2175
+
2176
+ const updateData = {
2177
+ questionAnswers,
2178
+ updatedAt: dayjs.utc( currentDateTime.format( 'hh:mm:ss A, DD MMM YYYY' ), 'hh:mm:ss A, DD MMM YYYY' ).format(),
2179
+ questionFlag: QuestionFlag( req, res ),
2180
+ };
2181
+
2182
+ if ( submittype === 'draft' ) {
2183
+ logger.info(
2184
+ `v5 => Checklist Save => store Name: ${storeName}, User Email: ${userEmail}, Checklist Name: ${checkListName}`,
2185
+ );
2186
+ updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
2187
+ } else if ( submittype === 'submit' ) {
2188
+ logger.info(
2189
+ `v5 => Checklist Submit => store Name: ${storeName}, User Email: ${userEmail}, Checklist Name: ${checkListName}`,
2190
+ );
2191
+ Object.assign( updateData, {
2192
+ submitTime: dayjs.utc( currentDateTime.format( 'hh:mm:ss A, DD MMM YYYY' ), 'hh:mm:ss A, DD MMM YYYY' ).format(),
2193
+ checklistStatus: 'submit',
2194
+ submitMobileTime: currentTime,
2195
+ submitTime_string: currentDateTime.format( 'hh:mm A, DD MMM YYYY' ),
2196
+ } );
2197
+ }
2198
+
2199
+ const updateResult = await processedTask.updateOne( updateQuery, updateData );
2200
+
2201
+ if ( updateResult.modifiedCount > 0 ) {
2202
+ if ( submittype === 'submit' ) {
2203
+ const query1 = [
2204
+ {
2205
+ $match: {
2206
+ userId: user._id,
2207
+ sourceCheckList_id: checklist.sourceCheckList_id,
2208
+ checklistStatus: { $in: [ 'open', 'inprogress' ] },
2209
+ },
2210
+ },
2211
+ {
2212
+ $project: {
2213
+ _id: 1,
2214
+ date_iso: 1,
2215
+ date_string: 1,
2216
+ },
2217
+ },
2218
+ ];
2219
+
2220
+ const processedTasksToDelete = await processedTask.aggregate( query1 );
2221
+
2222
+ if ( processedTasksToDelete?.length ) {
2223
+ const deleteIds = processedTasksToDelete?.filter( ( val ) => val?.date_string !== date )?.map( ( val ) => val?._id );
2224
+
2225
+ if ( deleteIds?.length ) {
2226
+ await processedTask.deleteMany( { _id: { $in: deleteIds } } );
2227
+ }
2228
+ }
2229
+ } else if ( submittype === 'draft' ) {
2230
+ const query2 = [
2231
+ {
2232
+ $match: {
2233
+ _id: checklist.sourceCheckList_id,
2234
+ },
2235
+ },
2236
+ ];
2237
+ const [ taskConfig ] = await taskConfigService.aggregate( query2 );
2238
+
2239
+ if ( taskConfig.scheduleEndTimeISO ) {
2240
+ const endDate = dayjs( taskConfig.scheduleEndTimeISO ).utc();
2241
+ const startDate = dayjs().add( 1, 'day' );
2242
+
2243
+ let currentDate = startDate;
2244
+
2245
+ while ( currentDate.isSameOrBefore( endDate ) ) {
2246
+ const updateDate = currentDate.format( 'YYYY-MM-DD' );
2247
+
2248
+ const updateQuery = {
2249
+ sourceCheckList_id: taskConfig._id,
2250
+ date_string: updateDate,
2251
+ userId: user._id,
2252
+ };
2253
+
2254
+ if ( Object.values( updateQuery ).length === 3 ) {
2255
+ await processedTask.updateOne( updateQuery, { questionAnswers, checklistStatus: 'inprogress' } );
2256
+ }
2257
+
2258
+ currentDate = currentDate.add( 1, 'day' );
2259
+ }
2260
+ }
2261
+ }
2262
+ const logInsertData = {
2263
+ // eslint-disable-next-line camelcase
2264
+ store_id,
2265
+ storeName,
2266
+ action: submittype === 'draft' ? 'saved' : 'submitted',
2267
+ checklistId: checklist.sourceCheckList_id,
2268
+ processedChecklistId: checklist._id,
2269
+ type: checklist.checkListType,
2270
+ checkListName,
2271
+ client_id: user.clientId,
2272
+ redoStatus: requestData?.redoStatus ? true : false,
2273
+ };
2274
+ await checklistLogs.create( logInsertData );
2275
+
2276
+ if ( submittype == 'submit' ) {
2277
+ updateOpenSearchTask( user, requestData );
2278
+ }
2279
+
2280
+ return res.sendSuccess( 'Task Updated Successfully' );
2281
+ } else {
2282
+ return res.sendError( 'Something went wrong. Please try again', 500 );
2283
+ }
2284
+ } catch ( error ) {
2285
+ logger.error( { function: 'submiteyeTestTask', error, body: req.body } );
2286
+ return res.sendError( error.message || 'Internal Server Error', 500 );
2287
+ }
2288
+ }
2105
2289
 
2106
2290
 
2107
2291
  async function updateOpenSearch( user, data ) {
@@ -2548,6 +2732,7 @@ export async function checklistv1( req, res ) {
2548
2732
  client_id: { $ifNull: [ '$client_id', '' ] },
2549
2733
  coverage: { $ifNull: [ '$coverage', '' ] },
2550
2734
  taskType: { $ifNull: [ '$planoType', '' ] },
2735
+ streamId: { $ifNull: [ '$streamId', '' ] },
2551
2736
  },
2552
2737
  },
2553
2738
  ];
@@ -2643,6 +2828,8 @@ export async function questionList( req, res ) {
2643
2828
  redoStatus: { $ifNull: [ '$redoStatus', false ] },
2644
2829
  rawImageUpload: { $ifNull: [ '$rawImageUpload', false ] },
2645
2830
  rawVideoUpload: { $ifNull: [ '$rawVideoUpload', false ] },
2831
+ taskType: { $ifNull: [ '$planoType', '' ] },
2832
+ streamId: { $ifNull: [ '$streamId', '' ] },
2646
2833
  },
2647
2834
  } );
2648
2835
 
@@ -129,7 +129,6 @@ export const checklist = async ( req, res ) => {
129
129
 
130
130
  export const create = async ( req, res ) => {
131
131
  try {
132
- console.log( 'create' );
133
132
  let inputBody = req.body;
134
133
  let checkNumber;
135
134
  let questionCount = 0;
@@ -307,11 +306,8 @@ export const create = async ( req, res ) => {
307
306
  logDetails: {},
308
307
  userType: req.user.userType,
309
308
  };
310
- console.log( 'req.user', req.user );
311
- console.log( 'logObj', logObj );
312
309
  insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
313
310
  if ( inputBody.submitType == 'save' ) {
314
- console.log( 'logObj', logObj );
315
311
  let logObj = {
316
312
  client_id: inputBody.clientId,
317
313
  createAt: new Date(),
@@ -13,6 +13,7 @@ mobileRouter
13
13
  .post( '/submitCheckList', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidator, mobileController.sopMobilechecklistMultiSectionFormatter, mobileController.submitChecklist )
14
14
  .post( '/submitCheckListv5', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidatorv1, mobileController.sopMobilechecklistMultiSectionFormatterv1, mobileController.submitChecklist )
15
15
  .post( '/submitTask', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobileTaskQuestionValidator, mobileController.sopMobileTaskMultiSectionFormatter, mobileController.submitTask )
16
+ .post( '/submiteyeTestTask', isAllowedSessionHandler, mobileController.submiteyeTestTask )
16
17
  .get( '/dashboard', isAllowedSessionHandler, validate( dashboardValidation ), mobileController.dashboard )
17
18
  .get( '/dashboardv1', isAllowedSessionHandler, validate( dashboardValidation ), mobileController.dashboardv1 )
18
19
  .get( '/checklist', isAllowedSessionHandler, validate( mobileChecklistValidation ), mobileController.checklist )
@@ -0,0 +1,14 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export const aggregate = async ( query ={} ) => {
4
+ return model.cameraModel.aggregate( query );
5
+ };
6
+
7
+ export const updateOne = async ( query, record ) => {
8
+ return model.cameraModel.updateOne( query, { $set: record }, { upsert: true } );
9
+ };
10
+
11
+ export const findOne = async ( query ={}, field={} ) => {
12
+ return model.cameraModel.findOne( query, field );
13
+ };
14
+