tango-app-api-task 1.0.0-beta.3 → 1.0.0-beta.5
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-task",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
4
|
"description": "Task",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"mongodb": "^6.10.0",
|
|
25
25
|
"nodemon": "^3.1.7",
|
|
26
26
|
"npm": "^10.9.2",
|
|
27
|
-
"tango-api-schema": "2.2.
|
|
27
|
+
"tango-api-schema": "2.2.3",
|
|
28
28
|
"tango-app-api-middleware": "3.1.43-alpha.10",
|
|
29
29
|
"winston": "^3.17.0",
|
|
30
30
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -83,13 +83,15 @@ export async function createUpdateTask( req, res ) {
|
|
|
83
83
|
if ( data.upsertedId || req.body._id ) {
|
|
84
84
|
checkListId = data?.upsertedId || req.body._id;
|
|
85
85
|
let logInsertData = {
|
|
86
|
-
action: req.body?._id ? '
|
|
86
|
+
action: req.body?._id ? 'taskUpdate' : 'taskCreate',
|
|
87
|
+
type: 'task',
|
|
87
88
|
checklistId: checkListId,
|
|
88
89
|
checkListName: inputBody.checklistName,
|
|
89
90
|
createdBy: req.user._id,
|
|
90
91
|
createdByName: req.user.userName,
|
|
91
92
|
client_id: req.body.clientId,
|
|
92
93
|
sections: inputBody?.sections,
|
|
94
|
+
createdByEmail: req.user.email,
|
|
93
95
|
};
|
|
94
96
|
await checklistLogs.create( logInsertData );
|
|
95
97
|
let sectionList = [];
|
|
@@ -652,11 +654,14 @@ export async function taskConfig( req, res ) {
|
|
|
652
654
|
|
|
653
655
|
let logInsertData = {
|
|
654
656
|
action: inputBody.submitType == 'publish' ? 'taskPublishUsingConfigPage' : 'taskConfigDraft',
|
|
657
|
+
type: 'task',
|
|
655
658
|
checklistId: inputBody._id,
|
|
656
659
|
checkListName: inputBody?.checkListName,
|
|
657
660
|
createdBy: req.user._id,
|
|
658
661
|
createdByName: req.user.userName,
|
|
659
662
|
client_id: inputBody.client_id,
|
|
663
|
+
createdByEmail: req.user.email,
|
|
664
|
+
approver: inputBody?.approver || [],
|
|
660
665
|
};
|
|
661
666
|
await checklistLogs.create( logInsertData );
|
|
662
667
|
|
|
@@ -688,6 +693,7 @@ export async function taskConfig( req, res ) {
|
|
|
688
693
|
checkListId: inputBody._id,
|
|
689
694
|
type: 'task',
|
|
690
695
|
client_id: inputBody.client_id,
|
|
696
|
+
checkListName: inputBody?.checkListName,
|
|
691
697
|
} );
|
|
692
698
|
}
|
|
693
699
|
} );
|
|
@@ -860,6 +866,7 @@ export async function insertSingleProcessData( checklistId ) {
|
|
|
860
866
|
...insertdata,
|
|
861
867
|
date_string: dayjs( dateVal ).format( 'YYYY-MM-DD' ),
|
|
862
868
|
date_iso: dayjs( dateVal ).toDate(),
|
|
869
|
+
approver: getCLconfig?.approver,
|
|
863
870
|
};
|
|
864
871
|
|
|
865
872
|
let updatedchecklist;
|
|
@@ -892,7 +899,6 @@ async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date,
|
|
|
892
899
|
checkListId: new ObjectId( checklistId ),
|
|
893
900
|
checkFlag: true,
|
|
894
901
|
isdeleted: false,
|
|
895
|
-
// ...( getCLconfig?.reinitiate ) ? { reinitiate: true } : {},
|
|
896
902
|
},
|
|
897
903
|
} );
|
|
898
904
|
let allQuestion = await taskAssignService.aggregate( getquestionQuery );
|
|
@@ -1041,9 +1047,11 @@ export async function reinitiateTask( req, res ) {
|
|
|
1041
1047
|
return res.sendError( 'no data found', 204 );
|
|
1042
1048
|
}
|
|
1043
1049
|
let data = {};
|
|
1050
|
+
let endDate = dayjs( req.body.scheduleDate ).format( 'YYYY-MM-DD' ) + ' ' + req.body.scheduleEndTime;
|
|
1051
|
+
endDate = dayjs.utc( endDate, 'YYYY-MM-DD hh:mm A' ).format();
|
|
1044
1052
|
data.scheduleDate = req.body.scheduleDate;
|
|
1045
1053
|
data.scheduleEndTime = req.body.scheduleEndTime;
|
|
1046
|
-
data.scheduleEndTimeISO =
|
|
1054
|
+
data.scheduleEndTimeISO = endDate;
|
|
1047
1055
|
data.allowedStoreLocation = req.body.allowedStoreLocation;
|
|
1048
1056
|
data.approver = req.body.approver;
|
|
1049
1057
|
data.priorityType = req.body.priorityType;
|
|
@@ -1074,8 +1082,55 @@ export async function reinitiateTask( req, res ) {
|
|
|
1074
1082
|
}
|
|
1075
1083
|
|
|
1076
1084
|
await taskService.updateOne( { _id: req.body.taskId }, data );
|
|
1077
|
-
|
|
1078
|
-
|
|
1085
|
+
function getDaysBeforeEndDate( endDate ) {
|
|
1086
|
+
const end = dayjs.utc( endDate );
|
|
1087
|
+
const now = dayjs.utc( req.body.previousEndDate ).add( 1, 'day' );
|
|
1088
|
+
|
|
1089
|
+
if ( end.isBefore( now ) ) {
|
|
1090
|
+
throw new Error( 'End date must be in the future.' );
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
const daysArray = [];
|
|
1094
|
+
let currentDate = now.startOf( 'day' );
|
|
1095
|
+
|
|
1096
|
+
while ( currentDate.isBefore( end ) ) {
|
|
1097
|
+
daysArray.push( currentDate.format( ) );
|
|
1098
|
+
currentDate = currentDate.add( 1, 'day' );
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
return daysArray;
|
|
1102
|
+
};
|
|
1103
|
+
|
|
1104
|
+
const dateArray = getDaysBeforeEndDate( endDate );
|
|
1105
|
+
console.log( dateArray );
|
|
1106
|
+
await taskProcessedService.updateMany( { userEmail: req.body.userEmail, store_id: req.body.store_id, date_iso: { $gte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) }, sourceCheckList_id: req.body.taskId }, { scheduleEndTime_iso: endDate } );
|
|
1107
|
+
await taskProcessedConfigService.updateMany( { date_iso: { $gte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) }, sourceCheckList_id: req.body.taskId }, { scheduleEndTime_iso: endDate } );
|
|
1108
|
+
|
|
1109
|
+
let getPreviousUserTaskDate = await taskProcessedService.findOne( { userEmail: req.body.userEmail, store_id: req.body.store_id, sourceCheckList_id: req.body.taskId } );
|
|
1110
|
+
if ( !getPreviousUserTaskDate ) {
|
|
1111
|
+
return res.sendError( 'No data found', 204 );
|
|
1112
|
+
}
|
|
1113
|
+
let getPreviousConfigDate = await taskProcessedConfigService.findOne( { sourceCheckList_id: req.body.taskId } );
|
|
1114
|
+
|
|
1115
|
+
for ( let date of dateArray ) {
|
|
1116
|
+
let configData = {
|
|
1117
|
+
...getPreviousConfigDate._doc,
|
|
1118
|
+
date_string: dayjs( date ).format( 'YYYY-MM-DD' ),
|
|
1119
|
+
date_iso: new Date( dayjs( date ).format( 'YYYY-MM-DD' ) ),
|
|
1120
|
+
};
|
|
1121
|
+
|
|
1122
|
+
let userTaskData = {
|
|
1123
|
+
...getPreviousUserTaskDate._doc,
|
|
1124
|
+
date_string: dayjs( date ).format( 'YYYY-MM-DD' ),
|
|
1125
|
+
date_iso: new Date( dayjs( date ).format( 'YYYY-MM-DD' ) ),
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
delete configData._id;
|
|
1129
|
+
delete userTaskData._id;
|
|
1130
|
+
|
|
1131
|
+
await taskProcessedConfigService.insert( configData );
|
|
1132
|
+
await taskProcessedService.insert( userTaskData );
|
|
1133
|
+
}
|
|
1079
1134
|
return res.sendSuccess( 'Task reinitaite SUccessfully' );
|
|
1080
1135
|
} catch ( e ) {
|
|
1081
1136
|
logger.error( { functionName: 'reinitiateTask', error: e } );
|
|
@@ -1157,7 +1212,9 @@ export async function createChecklistTask( req, res ) {
|
|
|
1157
1212
|
inputBody.question[0].questionReferenceImage.forEach( ( ele ) => {
|
|
1158
1213
|
let imgUrl = decodeURIComponent( ele.split( '?' )[0] );
|
|
1159
1214
|
let url = imgUrl.split( '/' );
|
|
1160
|
-
url.
|
|
1215
|
+
if ( url.includes( 'https' ) || url.includes( 'http' ) ) {
|
|
1216
|
+
url.splice( 0, 3 );
|
|
1217
|
+
}
|
|
1161
1218
|
images.push( url.join( '/' ) );
|
|
1162
1219
|
} );
|
|
1163
1220
|
inputBody.question[0].questionReferenceImage = images;
|
|
@@ -1322,7 +1379,7 @@ export async function redoTask( req, res ) {
|
|
|
1322
1379
|
if ( sectionIndex == -1 ) {
|
|
1323
1380
|
return res.sendError( 'section is not found', 400 );
|
|
1324
1381
|
}
|
|
1325
|
-
let data = { ...question[sectionIndex].questions[req.body.payload.qno - 1], redo: true };
|
|
1382
|
+
let data = { ...question[sectionIndex].questions[req.body.payload.qno - 1], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
|
|
1326
1383
|
let userAnswer = data.userAnswer;
|
|
1327
1384
|
question[sectionIndex].questions[req.body.payload.qno - 1] = data;
|
|
1328
1385
|
question[sectionIndex].questions[req.body.payload.qno - 1].userAnswer = [];
|
|
@@ -1776,6 +1833,7 @@ export const updatePublish = async ( req, res ) => {
|
|
|
1776
1833
|
createdBy: req.user._id,
|
|
1777
1834
|
createdByName: req.user.userName,
|
|
1778
1835
|
client_id: req.body.clientId,
|
|
1836
|
+
createdByEmail: req.user.email,
|
|
1779
1837
|
};
|
|
1780
1838
|
await checklistLogs.create( logInsertData );
|
|
1781
1839
|
return res.sendSuccess( { checklistName: getCheckDetails.checkListName, message: 'Updated Successfully' } );
|
|
@@ -1819,6 +1877,7 @@ export const duplicateChecklist = async ( req, res ) => {
|
|
|
1819
1877
|
createdBy: req.user._id,
|
|
1820
1878
|
createdByName: req.user.userName,
|
|
1821
1879
|
client_id: req.query.clientId,
|
|
1880
|
+
createdByEmail: req.user.email,
|
|
1822
1881
|
};
|
|
1823
1882
|
await checklistLogs.create( logInsertData );
|
|
1824
1883
|
taskService.create( dupDetails ).then( async ( data ) => {
|
|
@@ -218,21 +218,15 @@ export const taskTableV1 = async ( req, res ) => {
|
|
|
218
218
|
export const taskInfoTableV1 = async ( req, res ) => {
|
|
219
219
|
try {
|
|
220
220
|
let requestData = req.body;
|
|
221
|
-
// let fromDate = new Date( requestData.fromDate );
|
|
222
|
-
// let toDate = new Date( requestData.toDate );
|
|
223
|
-
// let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
224
|
-
// toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
225
|
-
// toDate.setUTCHours( 23, 59, 59, 59 );
|
|
226
221
|
let result = {};
|
|
227
222
|
|
|
228
223
|
let findQuery = [];
|
|
229
224
|
let findAndQuery = [];
|
|
230
225
|
|
|
231
226
|
findAndQuery.push(
|
|
232
|
-
|
|
227
|
+
{ date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) } },
|
|
233
228
|
{ client_id: requestData.clientId },
|
|
234
229
|
{ store_id: { $in: requestData.storeId } },
|
|
235
|
-
// { checkListType: { $eq: 'task' } },
|
|
236
230
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.taskId ) },
|
|
237
231
|
);
|
|
238
232
|
if ( requestData.checklistStatus && requestData.checklistStatus != 'All' ) {
|
|
@@ -259,8 +253,36 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
259
253
|
findQuery.push( { $match: { $or: [ query ] } } );
|
|
260
254
|
}
|
|
261
255
|
|
|
256
|
+
findQuery.push( { $sort: { date_iso: -1, userName: 1 } } );
|
|
257
|
+
|
|
258
|
+
findQuery.push(
|
|
259
|
+
{
|
|
260
|
+
$group: {
|
|
261
|
+
_id: { userEmail: '$userEmail', storeId: '$store_id' },
|
|
262
|
+
checkListName: { $first: '$checkListName' },
|
|
263
|
+
createdByName: { $first: '$createdByName' },
|
|
264
|
+
userName: { $first: '$userName' },
|
|
265
|
+
userEmail: { $first: '$userEmail' },
|
|
266
|
+
checklistStatus: { $first: '$checklistStatus' },
|
|
267
|
+
submitTime_string: { $first: '$submitTime_string' },
|
|
268
|
+
storeName: { $first: '$storeName' },
|
|
269
|
+
checkListType: { $first: '$checkListType' },
|
|
270
|
+
scheduleRepeatedType: { $first: '$scheduleRepeatedType' },
|
|
271
|
+
date_iso: { $first: '$date_iso' },
|
|
272
|
+
store_id: { $first: '$store_id' },
|
|
273
|
+
timeFlag: { $first: '$timeFlag' },
|
|
274
|
+
date_string: { $first: '$date_string' },
|
|
275
|
+
sourceCheckList_id: { $first: '$sourceCheckList_id' },
|
|
276
|
+
reinitiateStatus: { $first: '$reinitiateStatus' },
|
|
277
|
+
scheduleEndTime_iso: { $first: '$scheduleEndTime_iso' },
|
|
278
|
+
processedchecklistId: { $first: '$_id' },
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
);
|
|
282
|
+
|
|
262
283
|
findQuery.push( {
|
|
263
284
|
$project: {
|
|
285
|
+
_id: 0,
|
|
264
286
|
checkListName: 1,
|
|
265
287
|
createdByName: 1,
|
|
266
288
|
userName: 1,
|
|
@@ -277,12 +299,13 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
277
299
|
sourceCheckList_id: 1,
|
|
278
300
|
reinitiateStatus: 1,
|
|
279
301
|
scheduleEndTime_iso: 1,
|
|
280
|
-
|
|
302
|
+
processedchecklistId: 1,
|
|
281
303
|
},
|
|
282
304
|
} );
|
|
283
305
|
|
|
284
306
|
findQuery.push( {
|
|
285
307
|
$project: {
|
|
308
|
+
_id: 0,
|
|
286
309
|
checkListName: 1,
|
|
287
310
|
checkListChar: { $substr: [ '$checkListName', 0, 2 ] },
|
|
288
311
|
createdByName: 1,
|
|
@@ -316,13 +339,14 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
316
339
|
checklistDate: '$date_string',
|
|
317
340
|
sourceCheckList_id: 1,
|
|
318
341
|
scheduleEndTime_iso: 1,
|
|
342
|
+
processedchecklistId: 1,
|
|
319
343
|
},
|
|
320
344
|
} );
|
|
321
345
|
|
|
322
346
|
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
323
347
|
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
324
348
|
} else {
|
|
325
|
-
findQuery.push( { $sort: {
|
|
349
|
+
findQuery.push( { $sort: { userEmail: 1 } } );
|
|
326
350
|
}
|
|
327
351
|
|
|
328
352
|
let limit = parseInt( requestData?.limit ) || 10;
|
|
@@ -348,7 +372,8 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
348
372
|
|
|
349
373
|
result.totalCount = taskInfoData[0].count[0].total;
|
|
350
374
|
for ( let i = 0; i < taskInfoData[0].data.length; i++ ) {
|
|
351
|
-
taskInfoData[0].data[i].
|
|
375
|
+
taskInfoData[0].data[i].date = dayjs.utc( taskInfoData[0].data[i].scheduleEndTime_iso ).format();
|
|
376
|
+
taskInfoData[0].data[i].scheduleEndTime_iso = dayjs.utc( taskInfoData[0].data[i].scheduleEndTime_iso ).format( 'DD MMM YYYY' );
|
|
352
377
|
}
|
|
353
378
|
result.taskInfo = taskInfoData[0].data;
|
|
354
379
|
return res.sendSuccess( result );
|
|
@@ -13,7 +13,7 @@ taskRouter
|
|
|
13
13
|
.post( '/upload', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.validateUser )
|
|
14
14
|
.post( '/uploadImage', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.uploadImage )
|
|
15
15
|
.post( '/config', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.taskConfig )
|
|
16
|
-
.post( '/reinitiate', isAllowedSessionHandler,
|
|
16
|
+
.post( '/reinitiate', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.reinitiateTask )
|
|
17
17
|
.post( '/checklistTask', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.createChecklistTask )
|
|
18
18
|
.post( '/updateApprove', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.approveTask )
|
|
19
19
|
.post( '/redo', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.redoTask )
|
|
@@ -5,7 +5,7 @@ export const find = async ( query = {}, field={} ) => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export const findOne = async ( query = {}, field={} ) => {
|
|
8
|
-
return model.taskProcessedConfigModel.findOne( query, field );
|
|
8
|
+
return model.taskProcessedConfigModel.findOne( query, field ).sort( { date_iso: -1 } );
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export const updateMany = async ( query = {}, record={} ) => {
|
|
@@ -5,7 +5,7 @@ export const find = async ( query = {}, field={} ) => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export const findOne = async ( query = {}, field={} ) => {
|
|
8
|
-
return model.taskProcessedModel.findOne( query, field );
|
|
8
|
+
return model.taskProcessedModel.findOne( query, field ).sort( { date_iso: -1 } );
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export const updateMany = async ( query = {}, record={} ) => {
|
|
@@ -28,3 +28,7 @@ export const aggregate = async ( query = [] ) => {
|
|
|
28
28
|
return model.taskProcessedModel.aggregate( query );
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
export const insert = async ( query = [] ) => {
|
|
32
|
+
return model.taskProcessedModel.create( query );
|
|
33
|
+
};
|
|
34
|
+
|