tango-app-api-task 3.6.0-task-6 → 3.6.2-bulktask-1
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
|
@@ -1229,7 +1229,7 @@ function findObjectDifference( oldObj, newObj ) {
|
|
|
1229
1229
|
}
|
|
1230
1230
|
|
|
1231
1231
|
|
|
1232
|
-
export async function insertSingleProcessData( checklistId, answerTypechange, inputBody ) {
|
|
1232
|
+
export async function insertSingleProcessData( checklistId, answerTypechange, inputBody, insertfrom ) {
|
|
1233
1233
|
try {
|
|
1234
1234
|
let currentdate = new Date();
|
|
1235
1235
|
let date = dayjs( currentdate ).format();
|
|
@@ -1343,7 +1343,7 @@ export async function insertSingleProcessData( checklistId, answerTypechange, in
|
|
|
1343
1343
|
updatedchecklist = checklistDetails;
|
|
1344
1344
|
}
|
|
1345
1345
|
if ( updatedchecklist ) {
|
|
1346
|
-
await insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, dateVal, startTimeIso, endTimeIso, insertdata, answerTypechange, inputBody );
|
|
1346
|
+
await insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, dateVal, startTimeIso, endTimeIso, insertdata, answerTypechange, inputBody, insertfrom );
|
|
1347
1347
|
}
|
|
1348
1348
|
}
|
|
1349
1349
|
}
|
|
@@ -1355,7 +1355,7 @@ export async function insertSingleProcessData( checklistId, answerTypechange, in
|
|
|
1355
1355
|
}
|
|
1356
1356
|
};
|
|
1357
1357
|
|
|
1358
|
-
async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date, startTimeIso, endTimeIso, insertdata, answerTypechange, inputBody ) {
|
|
1358
|
+
async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date, startTimeIso, endTimeIso, insertdata, answerTypechange, inputBody, insertfrom ) {
|
|
1359
1359
|
let getquestionQuery = [];
|
|
1360
1360
|
|
|
1361
1361
|
if ( dayjs( getCLconfig.publishDate ).format( 'YYYY-MM-DD' ) != dayjs( date ).format( 'YYYY-MM-DD' ) ) {
|
|
@@ -1528,10 +1528,20 @@ async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date,
|
|
|
1528
1528
|
if ( inputBody && inputBody?.streamId ) {
|
|
1529
1529
|
element4.streamId = inputBody?.streamId;
|
|
1530
1530
|
}
|
|
1531
|
+
console.log( insertdata.questionAnswers, element4.comments );
|
|
1531
1532
|
if ( answerTypechange ) {
|
|
1532
1533
|
element4.questionAnswers = insertdata.questionAnswers;
|
|
1533
1534
|
element4.planoType = 'qrScan';
|
|
1534
1535
|
}
|
|
1536
|
+
|
|
1537
|
+
if ( insertfrom === 'gallery' ) {
|
|
1538
|
+
// Clone the data to prevent shared reference
|
|
1539
|
+
const clonedQuestionAnswers = JSON.parse( JSON.stringify( insertdata.questionAnswers ) );
|
|
1540
|
+
clonedQuestionAnswers[0].questions[0].qcomment = element4.comments;
|
|
1541
|
+
|
|
1542
|
+
element4.questionAnswers = clonedQuestionAnswers;
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1535
1545
|
element4.coverage = getCLconfig?.coverage;
|
|
1536
1546
|
assignUserList.push( element4 );
|
|
1537
1547
|
}
|
|
@@ -1568,6 +1578,11 @@ async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date,
|
|
|
1568
1578
|
item1.store_id === item2.store_id && item1.userEmail === item2.userEmail,
|
|
1569
1579
|
),
|
|
1570
1580
|
);
|
|
1581
|
+
|
|
1582
|
+
// for ( let insertdetail of insertList ) {
|
|
1583
|
+
// console.log( insertdetail.questionAnswers[0].questions[0] );
|
|
1584
|
+
// }
|
|
1585
|
+
|
|
1571
1586
|
await taskProcessedService.insertMany( insertList );
|
|
1572
1587
|
logger.info( { function: 'insertPCBulk_v3', query: assigndeletequery } );
|
|
1573
1588
|
}
|
|
@@ -2119,39 +2134,73 @@ export async function createChecklistMultiTask( req, res ) {
|
|
|
2119
2134
|
|
|
2120
2135
|
let time = inputBody?.scheduleEndTime || '11:59 PM';
|
|
2121
2136
|
let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2137
|
+
let checklistDetails = await checklistService.findOne( { _id: inputData[0]?.checkListId }, { coverage: 1 } );
|
|
2138
|
+
let data = {
|
|
2139
|
+
checkListName: inputBody.checkListName,
|
|
2140
|
+
checkListDescription: inputBody.checkListDescription,
|
|
2141
|
+
createdBy: req.user._id,
|
|
2142
|
+
createdByName: req.user.userName,
|
|
2143
|
+
publish: true,
|
|
2144
|
+
questionCount: 1,
|
|
2145
|
+
storeCount: 1,
|
|
2146
|
+
scheduleDate: date,
|
|
2147
|
+
scheduleEndTime: time,
|
|
2148
|
+
scheduleEndTimeISO: dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format(),
|
|
2149
|
+
priorityType: 'high',
|
|
2150
|
+
client_id: inputBody.clientId,
|
|
2151
|
+
checkListType: inputBody.checkListType,
|
|
2152
|
+
publishDate: new Date(),
|
|
2153
|
+
locationCount: 1,
|
|
2154
|
+
...( inputData[0]?.checkListId ) ? { referenceCheckListId: inputData[0]?.checkListId } : {},
|
|
2155
|
+
coverage: checklistDetails?.coverage || 'store',
|
|
2156
|
+
checkListFrom: 'gallery',
|
|
2157
|
+
restrictAttendance: req.body.restrictAttendance,
|
|
2158
|
+
allowedStoreLocation: req.body.allowedStoreLocation,
|
|
2159
|
+
};
|
|
2144
2160
|
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2161
|
+
if ( req.user.userType == 'tango' || ( req.user.userType == 'client' && [ 'user' ].includes( req.user.role ) ) ) {
|
|
2162
|
+
let userList = await userService.findOne( { clientId: inputBody.clientId, role: 'superadmin' }, { userName: 1, email: 1 } );
|
|
2163
|
+
if ( userList ) {
|
|
2164
|
+
data['approver'] = { name: userList.userName, value: userList.email };
|
|
2165
|
+
}
|
|
2166
|
+
} else {
|
|
2167
|
+
data['approver'] = { name: req.user.userName, value: req.user.email };
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
let response = await taskService.create( data );
|
|
2171
|
+
let newquestion = {
|
|
2172
|
+
'qno': 1,
|
|
2173
|
+
'qname': inputBody.question[0].qname,
|
|
2174
|
+
'answerType': inputBody.question[0].answerType,
|
|
2175
|
+
'runAI': false,
|
|
2176
|
+
'runAIDescription': '',
|
|
2177
|
+
'allowUploadfromGallery': inputBody.question[0].allowUploadfromGallery,
|
|
2178
|
+
'linkType': false,
|
|
2179
|
+
'questionReferenceImage': inputBody.question[0].questionReferenceImage,
|
|
2180
|
+
'descriptivetype': inputBody.question[0].descriptivetype,
|
|
2181
|
+
'answers': inputBody.question[0].answers,
|
|
2182
|
+
};
|
|
2183
|
+
let question = {
|
|
2184
|
+
checkListId: response?._id,
|
|
2185
|
+
question: inputBody.showcomment? inputBody.question:newquestion,
|
|
2186
|
+
section: 'Section 1',
|
|
2187
|
+
checkList: inputBody?.checkListName,
|
|
2188
|
+
client_id: inputBody.clientId,
|
|
2189
|
+
};
|
|
2190
|
+
console.log( question );
|
|
2191
|
+
await taskQuestionService.create( question );
|
|
2192
|
+
for ( let originaldata of inputData ) {
|
|
2193
|
+
let findcomment= {};
|
|
2194
|
+
if ( !inputBody.showcomment ) {
|
|
2195
|
+
if ( inputBody?.coverage ==='store' ) {
|
|
2196
|
+
findcomment = inputBody.excelData.find( ( ele ) => ele.storeName === originaldata.storeName );
|
|
2197
|
+
} else if ( inputBody?.coverage==='users' ) {
|
|
2198
|
+
findcomment = inputBody.excelData.find( ( ele ) => ele.userEmail === originaldata.userEmail );
|
|
2149
2199
|
}
|
|
2150
|
-
} else {
|
|
2151
|
-
data['approver'] = { name: req.user.userName, value: req.user.email };
|
|
2152
2200
|
}
|
|
2201
|
+
console.log( '****************', findcomment );
|
|
2202
|
+
|
|
2153
2203
|
|
|
2154
|
-
let response = await taskService.create( data );
|
|
2155
2204
|
if ( response?.approver.length ) {
|
|
2156
2205
|
let data = [];
|
|
2157
2206
|
response?.approver.forEach( ( ele ) => {
|
|
@@ -2191,14 +2240,7 @@ export async function createChecklistMultiTask( req, res ) {
|
|
|
2191
2240
|
} );
|
|
2192
2241
|
inputBody.question[0].answers[0].referenceImage = images;
|
|
2193
2242
|
}
|
|
2194
|
-
|
|
2195
|
-
checkListId: response?._id,
|
|
2196
|
-
question: inputBody.question,
|
|
2197
|
-
section: 'Section 1',
|
|
2198
|
-
checkList: data.checkListName,
|
|
2199
|
-
client_id: inputBody.clientId,
|
|
2200
|
-
};
|
|
2201
|
-
await taskQuestionService.create( question );
|
|
2243
|
+
|
|
2202
2244
|
let storeDetails;
|
|
2203
2245
|
if ( originaldata?.storeName ) {
|
|
2204
2246
|
storeDetails = await storeService.findOne( { storeName: originaldata.storeName, status: 'active' }, { storeId: 1, storeProfile: 1 } );
|
|
@@ -2217,12 +2259,13 @@ export async function createChecklistMultiTask( req, res ) {
|
|
|
2217
2259
|
userId: userDetailList && userDetailList._id ? userDetailList._id : '',
|
|
2218
2260
|
assignId: response?.coverage == 'store' ? storeDetails?._id : userDetailList._id,
|
|
2219
2261
|
coverage: response?.coverage || 'store',
|
|
2262
|
+
comments: inputBody?.showcomment? inputBody.checkListDescription:findcomment?.comments,
|
|
2220
2263
|
};
|
|
2221
2264
|
await taskAssignService.create( userDetails );
|
|
2222
2265
|
// console.log( originaldata?.checklistId );
|
|
2223
2266
|
if ( inputBody.checkListType == 'checklistTask' ) {
|
|
2224
2267
|
let taskDetails = await processedChecklist.findOne( { _id: originaldata?.checklistId }, { questionAnswers: 1, taskStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1 } );
|
|
2225
|
-
|
|
2268
|
+
console.log( taskDetails );
|
|
2226
2269
|
if ( !taskDetails ) {
|
|
2227
2270
|
return res.sendError( 'No data found', 204 );
|
|
2228
2271
|
}
|
|
@@ -2232,7 +2275,7 @@ export async function createChecklistMultiTask( req, res ) {
|
|
|
2232
2275
|
return res.sendError( 'section is not found', 400 );
|
|
2233
2276
|
}
|
|
2234
2277
|
let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.qno );
|
|
2235
|
-
|
|
2278
|
+
console.log( findQuestion );
|
|
2236
2279
|
let data = { ...question[sectionIndex].questions[findQuestion], taskId: response?._id, task: true };
|
|
2237
2280
|
question[sectionIndex].questions[req.body.qno - 1] = data;
|
|
2238
2281
|
taskDetails.questionAnswers = question;
|
|
@@ -2240,6 +2283,7 @@ export async function createChecklistMultiTask( req, res ) {
|
|
|
2240
2283
|
taskStatus: true,
|
|
2241
2284
|
questionAnswers: question,
|
|
2242
2285
|
};
|
|
2286
|
+
console.log( updateData );
|
|
2243
2287
|
await processedChecklist.updateOne( { _id: originaldata.checklistId }, updateData );
|
|
2244
2288
|
let params = {
|
|
2245
2289
|
'payload': {
|
|
@@ -2295,7 +2339,7 @@ export async function createChecklistMultiTask( req, res ) {
|
|
|
2295
2339
|
console.log( 'logData', logData );
|
|
2296
2340
|
await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
|
|
2297
2341
|
}
|
|
2298
|
-
await insertSingleProcessData( response?._id );
|
|
2342
|
+
await insertSingleProcessData( response?._id, false, inputBody, 'gallery' );
|
|
2299
2343
|
}
|
|
2300
2344
|
}
|
|
2301
2345
|
return res.sendSuccess( 'Task created successfully' );
|