tango-app-api-task 1.0.0-alpha.6 → 1.0.0-alpha.8
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
|
@@ -96,15 +96,19 @@ export async function createUpdateTask( req, res ) {
|
|
|
96
96
|
for ( let i = 0; i < inputBody?.sections?.length; i++ ) {
|
|
97
97
|
let section = inputBody.sections[i];
|
|
98
98
|
section.questions.forEach( ( section ) => {
|
|
99
|
-
if ( section.questionReferenceImage && section.questionReferenceImage
|
|
100
|
-
let
|
|
101
|
-
let
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
if ( section.questionReferenceImage && section.questionReferenceImage.length ) {
|
|
100
|
+
let image = [];
|
|
101
|
+
for ( let img of section.questionReferenceImage ) {
|
|
102
|
+
let imgUrl = decodeURIComponent( img.split( '?' )[0] );
|
|
103
|
+
let url = imgUrl.split( '/' );
|
|
104
|
+
url.splice( 0, 3 );
|
|
105
|
+
image.push( url.join( '/' ) );
|
|
106
|
+
}
|
|
107
|
+
section.questionReferenceImage = image;
|
|
104
108
|
}
|
|
105
109
|
section.answers.forEach( ( answer ) => {
|
|
106
110
|
if ( answer.referenceImage != '' ) {
|
|
107
|
-
let imgUrl = decodeURIComponent( answer.referenceImage
|
|
111
|
+
let imgUrl = decodeURIComponent( answer.referenceImage?.split( '?' )[0] );
|
|
108
112
|
let url = imgUrl.split( '/' );
|
|
109
113
|
url.splice( 0, 3 );
|
|
110
114
|
answer.referenceImage = url.join( '/' );
|
|
@@ -231,12 +235,24 @@ export async function taskDetails( req, res ) {
|
|
|
231
235
|
let bucket = JSON.parse( process.env.BUCKET );
|
|
232
236
|
questionDetails.forEach( ( item ) => {
|
|
233
237
|
item.question.forEach( async ( question ) => {
|
|
234
|
-
if ( question.questionReferenceImage && question.questionReferenceImage !='' ) {
|
|
238
|
+
if ( question.questionReferenceImage && question.questionReferenceImage !='' && typeof question.questionReferenceImage == 'string' ) {
|
|
235
239
|
let inputData = {
|
|
236
240
|
Bucket: bucket.sop,
|
|
237
241
|
file_path: decodeURIComponent( question.questionReferenceImage ),
|
|
238
242
|
};
|
|
239
243
|
question.questionReferenceImage = await signedUrl( inputData );
|
|
244
|
+
} else {
|
|
245
|
+
if ( question.questionReferenceImage.length ) {
|
|
246
|
+
let image = [];
|
|
247
|
+
for ( let img of question.questionReferenceImage ) {
|
|
248
|
+
let inputData = {
|
|
249
|
+
Bucket: bucket.sop,
|
|
250
|
+
file_path: decodeURIComponent( img ),
|
|
251
|
+
};
|
|
252
|
+
image.push( await signedUrl( inputData ) );
|
|
253
|
+
}
|
|
254
|
+
question.questionReferenceImage = image;
|
|
255
|
+
}
|
|
240
256
|
}
|
|
241
257
|
question.answers.forEach( async ( answer ) => {
|
|
242
258
|
if ( answer.referenceImage != '' ) {
|
|
@@ -320,7 +336,7 @@ export async function validateUser( req, res ) {
|
|
|
320
336
|
}
|
|
321
337
|
if ( alreadyExist.length ) {
|
|
322
338
|
let email = [ ...new Set( alreadyExist ) ];
|
|
323
|
-
return res.sendError( `${email.join()} - email already exist`, 500 );
|
|
339
|
+
return res.sendError( `${email.join()} - email already exist for another brand`, 500 );
|
|
324
340
|
} else {
|
|
325
341
|
userEmail.forEach( ( item ) => {
|
|
326
342
|
data.push( {
|
|
@@ -701,7 +717,7 @@ export async function taskConfig( req, res ) {
|
|
|
701
717
|
await taskService.updateOne( { _id: inputBody._id }, { storeCount, locationCount } );
|
|
702
718
|
if ( inputBody.submitType == 'publish' ) {
|
|
703
719
|
let currentDate = dayjs.utc().format();
|
|
704
|
-
let updatedscheduleEndTimeISO = dayjs( checklistDetails?.scheduleDate ).format( 'YYYY-MM-DD' ) + ' ' + checklistDetails.scheduleEndTime;
|
|
720
|
+
let updatedscheduleEndTimeISO = dayjs.utc( checklistDetails?.scheduleDate ).format( 'YYYY-MM-DD' ) + ' ' + checklistDetails.scheduleEndTime;
|
|
705
721
|
updatedscheduleEndTimeISO = dayjs.utc( updatedscheduleEndTimeISO, 'YYYY-MM-DD hh:mm A' ).format();
|
|
706
722
|
if ( updatedscheduleEndTimeISO >= currentDate ) {
|
|
707
723
|
let deleteQuery = {
|
|
@@ -1042,7 +1058,7 @@ export async function createChecklistTask( req, res ) {
|
|
|
1042
1058
|
publish: true,
|
|
1043
1059
|
questionCount: 1,
|
|
1044
1060
|
storeCount: 1,
|
|
1045
|
-
scheduleDate:
|
|
1061
|
+
scheduleDate: date,
|
|
1046
1062
|
scheduleEndTime: time,
|
|
1047
1063
|
scheduleEndTimeISO: dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format(),
|
|
1048
1064
|
priorityType: 'high',
|
|
@@ -1145,22 +1161,46 @@ export async function createChecklistTask( req, res ) {
|
|
|
1145
1161
|
|
|
1146
1162
|
export async function approveTask( req, res ) {
|
|
1147
1163
|
try {
|
|
1148
|
-
|
|
1149
|
-
|
|
1164
|
+
let toDate = new Date( req.body.toDate );
|
|
1165
|
+
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
1166
|
+
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
1167
|
+
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
1168
|
+
let query = { sourceCheckList_id: req.body.sourceCheckList_id, date_iso: { $gte: req.body.fromDate, $lte: toDate }, checklistStatus: 'submit', approvalEnable: true };
|
|
1169
|
+
if ( req.body?.storeId?.length ) {
|
|
1170
|
+
query['store_id'] = { $in: req.body.storeId };
|
|
1150
1171
|
}
|
|
1151
|
-
let taskDetails = await taskProcessedService.
|
|
1152
|
-
if ( !taskDetails ) {
|
|
1172
|
+
let taskDetails = await taskProcessedService.find( query, { _id: 1 } );
|
|
1173
|
+
if ( !taskDetails.length ) {
|
|
1153
1174
|
return res.sendError( 'No data found', 204 );
|
|
1154
1175
|
}
|
|
1155
|
-
|
|
1156
|
-
|
|
1176
|
+
let idList = taskDetails.map( ( item ) => item._id );
|
|
1177
|
+
let updateResponse = await taskProcessedService.updateMany( { _id: { $in: idList } }, { approvalStatus: true } );
|
|
1178
|
+
if ( updateResponse.modifiedCount || updateResponse.matchedCount ) {
|
|
1179
|
+
let params = {
|
|
1180
|
+
'payload': {
|
|
1181
|
+
sourceCheckList_id: req.body.sourceCheckList_id,
|
|
1182
|
+
fromDate: req.body.fromDate,
|
|
1183
|
+
toDate: req.body.toDate,
|
|
1184
|
+
store_id: req.body.storeId,
|
|
1185
|
+
},
|
|
1186
|
+
'upsert': {
|
|
1187
|
+
approvalStatus: true,
|
|
1188
|
+
},
|
|
1189
|
+
};
|
|
1190
|
+
const requestOptions = {
|
|
1191
|
+
method: 'POST',
|
|
1192
|
+
headers: {
|
|
1193
|
+
'Content-Type': 'application/json',
|
|
1194
|
+
},
|
|
1195
|
+
body: JSON.stringify( params ),
|
|
1196
|
+
};
|
|
1197
|
+
let searchResponse = await fetch( 'https://wnx32v5mtyqx6kh3nt6xuosjqa0xvdfq.lambda-url.ap-south-1.on.aws', requestOptions );
|
|
1198
|
+
if ( searchResponse.ok ) {
|
|
1199
|
+
return res.sendSuccess( 'Task Approved successfully' );
|
|
1200
|
+
} else {
|
|
1201
|
+
return res.sendError( 'Something went wrong', 500 );
|
|
1202
|
+
}
|
|
1157
1203
|
}
|
|
1158
|
-
taskDetails.approvalStatus = true;
|
|
1159
|
-
taskDetails.save().then( () => {
|
|
1160
|
-
return res.sendSuccess( 'task Approved Successfully' );
|
|
1161
|
-
} ).catch( ( e ) => {
|
|
1162
|
-
return res.sendError( e, 500 );
|
|
1163
|
-
} );
|
|
1164
1204
|
} catch ( e ) {
|
|
1165
1205
|
logger.error( { function: 'approveTask', error: e } );
|
|
1166
1206
|
return res.sendError( e, 500 );
|
|
@@ -2,6 +2,7 @@ import * as traxApprover from '../service/approver.service.js';
|
|
|
2
2
|
import * as processedTask from '../service/processedTaskList.service.js';
|
|
3
3
|
import { logger } from 'tango-app-api-middleware';
|
|
4
4
|
import * as processedChecklist from '../service/processedChecklist.service.js';
|
|
5
|
+
import * as checklistLog from '../service/checklistLog.service.js';
|
|
5
6
|
import mongoose from 'mongoose';
|
|
6
7
|
const ObjectId = mongoose.Types.ObjectId;
|
|
7
8
|
export const overallCardsV1 = async ( req, res ) => {
|
|
@@ -183,10 +184,10 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
183
184
|
},
|
|
184
185
|
} );
|
|
185
186
|
}
|
|
186
|
-
if ( req.body?.filter
|
|
187
|
+
if ( req.body?.filter.length ) {
|
|
187
188
|
query.push( {
|
|
188
189
|
$match: {
|
|
189
|
-
priorityType: req.body?.filter,
|
|
190
|
+
priorityType: { $in: req.body?.filter },
|
|
190
191
|
},
|
|
191
192
|
} );
|
|
192
193
|
}
|
|
@@ -260,6 +261,58 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
260
261
|
}
|
|
261
262
|
};
|
|
262
263
|
|
|
264
|
+
export const activityLogV1 = async ( req, res ) => {
|
|
265
|
+
try {
|
|
266
|
+
let requestData = req.body;
|
|
267
|
+
let findQuery = [];
|
|
268
|
+
let findAndQuery = [];
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
findAndQuery.push(
|
|
272
|
+
{ client_id: requestData.clientId },
|
|
273
|
+
{ store_id: { $in: requestData.storeId } },
|
|
274
|
+
{ action: { $in: [ 'submitted', 'started' ] } },
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
279
|
+
findQuery.push( {
|
|
280
|
+
$project: {
|
|
281
|
+
checkListName: 1,
|
|
282
|
+
storeName: 1,
|
|
283
|
+
action: 1,
|
|
284
|
+
createdAt: 1,
|
|
285
|
+
},
|
|
286
|
+
} );
|
|
287
|
+
let limit = parseInt( requestData?.limit ) || 10;
|
|
288
|
+
let skip = limit * ( requestData?.offset -1 ) || 0;
|
|
289
|
+
|
|
290
|
+
findQuery.push( {
|
|
291
|
+
$facet: {
|
|
292
|
+
activityLogData: [
|
|
293
|
+
{ $skip: skip },
|
|
294
|
+
{ $limit: limit },
|
|
295
|
+
],
|
|
296
|
+
count: [
|
|
297
|
+
{ $count: 'total' },
|
|
298
|
+
],
|
|
299
|
+
},
|
|
300
|
+
} );
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
let activityLogData = await checklistLog.aggregate( findQuery );
|
|
304
|
+
|
|
305
|
+
if ( activityLogData && activityLogData.length > 0 ) {
|
|
306
|
+
return res.sendSuccess( activityLogData );
|
|
307
|
+
} else {
|
|
308
|
+
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
309
|
+
}
|
|
310
|
+
} catch ( error ) {
|
|
311
|
+
logger.error( { error: error, function: 'activityLogV1' } );
|
|
312
|
+
return res.sendError( error, 500 );
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
263
316
|
export const overallCards = async ( req, res ) => {
|
|
264
317
|
try {
|
|
265
318
|
let requestData = req.body;
|
|
@@ -3,7 +3,7 @@ import { isAllowedSessionHandler } from 'tango-app-api-middleware';
|
|
|
3
3
|
export const taskActionCenterRouter = express.Router();
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
overallCards, approvalTable, activityLog, overallCardsV1, approvalTableV1,
|
|
6
|
+
overallCards, approvalTable, activityLog, overallCardsV1, approvalTableV1, activityLogV1,
|
|
7
7
|
} from '../controllers/taskActionCenter.controllers.js';
|
|
8
8
|
|
|
9
9
|
taskActionCenterRouter
|
|
@@ -11,6 +11,8 @@ taskActionCenterRouter
|
|
|
11
11
|
.post( '/overallcards', overallCards )
|
|
12
12
|
.post( '/approvalTableV1', isAllowedSessionHandler, approvalTableV1 )
|
|
13
13
|
.post( '/approvalTable', approvalTable )
|
|
14
|
-
.post( '/activityLog', activityLog )
|
|
14
|
+
.post( '/activityLog', activityLog )
|
|
15
|
+
.post( '/activityLogV1', isAllowedSessionHandler, activityLogV1 );
|
|
16
|
+
|
|
15
17
|
|
|
16
18
|
export default taskActionCenterRouter;
|