tango-app-api-task 3.4.0-alpha-0 → 3.4.0-alpha-2
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 +2 -1
- package/src/controllers/task.controller.js +380 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-task",
|
|
3
|
-
"version": "3.4.0-alpha-
|
|
3
|
+
"version": "3.4.0-alpha-2",
|
|
4
4
|
"description": "Task",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"express": "^4.21.1",
|
|
22
22
|
"express-fileupload": "^1.5.1",
|
|
23
23
|
"handlebars": "^4.7.8",
|
|
24
|
+
"lodash": "^4.17.21",
|
|
24
25
|
"mongodb": "^6.10.0",
|
|
25
26
|
"nodemon": "^3.1.7",
|
|
26
27
|
"npm": "^10.9.2",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger, fileUpload, signedUrl, getObject } from 'tango-app-api-middleware';
|
|
1
|
+
import { logger, fileUpload, signedUrl, getObject, insertOpenSearchData } from 'tango-app-api-middleware';
|
|
2
2
|
import * as taskService from '../service/task.service.js';
|
|
3
3
|
import * as checklistLogs from '../service/checklistLog.service.js';
|
|
4
4
|
import * as taskQuestionService from '../service/taskQuestion.service.js';
|
|
@@ -25,6 +25,7 @@ import * as ApproverModel from '../service/approver.service.js';
|
|
|
25
25
|
import { createTeamsModel, findOneTeams, updateOneTeamModel, findteams } from '../service/teams.service.js';
|
|
26
26
|
import { sendPushNotification } from 'tango-app-api-middleware';
|
|
27
27
|
import * as checklistService from '../service/checklist.service.js';
|
|
28
|
+
import isEqual from 'lodash/isEqual.js';
|
|
28
29
|
async function LamdaServiceCall( url, data ) {
|
|
29
30
|
try {
|
|
30
31
|
const requestOptions = {
|
|
@@ -52,17 +53,26 @@ export async function createUpdateTask( req, res ) {
|
|
|
52
53
|
let questionCount = 0;
|
|
53
54
|
let checkListId;
|
|
54
55
|
let query;
|
|
55
|
-
let checkExistsQuery = { client_id:
|
|
56
|
+
let checkExistsQuery = { client_id: inputBody.clientId, checkListName: inputBody.checklistName, isdeleted: false };
|
|
56
57
|
let checkExists;
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
let taskDetails;
|
|
59
|
+
if ( inputBody._id ) {
|
|
60
|
+
checkExistsQuery['_id'] = { $nin: [ new ObjectId( inputBody._id ) ] };
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
checkExists = await taskService.findOne( checkExistsQuery );
|
|
62
|
-
|
|
63
64
|
if ( checkExists ) {
|
|
64
65
|
return res.sendError( { message: 'Task name already exists' }, 400 );
|
|
65
66
|
}
|
|
67
|
+
if ( inputBody._id ) {
|
|
68
|
+
taskDetails = await taskService.findOne( { _id: inputBody._id } );
|
|
69
|
+
|
|
70
|
+
if ( !taskDetails ) {
|
|
71
|
+
return res.sendError( 'No data found', 204 );
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let getExistQuestions = await taskQuestionService.find( { checkListId: inputBody._id } );
|
|
66
76
|
|
|
67
77
|
inputBody.sections.forEach( async ( element ) => {
|
|
68
78
|
if ( !element?.questions?.length && inputBody.submitType == 'configure' ) {
|
|
@@ -81,14 +91,14 @@ export async function createUpdateTask( req, res ) {
|
|
|
81
91
|
questionCount: questionCount,
|
|
82
92
|
client_id: req.body?.clientId,
|
|
83
93
|
};
|
|
84
|
-
if (
|
|
85
|
-
query = { _id:
|
|
94
|
+
if ( inputBody._id ) {
|
|
95
|
+
query = { _id: inputBody._id, client_id: req.body?.clientId };
|
|
86
96
|
} else {
|
|
87
97
|
query = { checkListName: inputBody.checklistName, client_id: req.body?.clientId };
|
|
88
98
|
}
|
|
89
99
|
let data = await taskService.updateOne( query, checkListDetails );
|
|
90
|
-
if ( data.upsertedId ||
|
|
91
|
-
checkListId = data?.upsertedId ||
|
|
100
|
+
if ( data.upsertedId || inputBody._id ) {
|
|
101
|
+
checkListId = data?.upsertedId || inputBody._id;
|
|
92
102
|
let logInsertData = {
|
|
93
103
|
action: req.body?._id ? 'taskUpdate' : 'taskCreate',
|
|
94
104
|
type: 'task',
|
|
@@ -96,7 +106,7 @@ export async function createUpdateTask( req, res ) {
|
|
|
96
106
|
checkListName: inputBody.checklistName,
|
|
97
107
|
createdBy: req.user._id,
|
|
98
108
|
createdByName: req.user.userName,
|
|
99
|
-
client_id:
|
|
109
|
+
client_id: inputBody.clientId,
|
|
100
110
|
sections: inputBody?.sections,
|
|
101
111
|
createdByEmail: req.user.email,
|
|
102
112
|
};
|
|
@@ -132,31 +142,138 @@ export async function createUpdateTask( req, res ) {
|
|
|
132
142
|
section: section?.name || 'Section 1',
|
|
133
143
|
createdBy: req.user._id,
|
|
134
144
|
createdByName: req.user.userName,
|
|
135
|
-
client_id:
|
|
145
|
+
client_id: inputBody.clientId,
|
|
136
146
|
checkListId: checkListId,
|
|
137
147
|
question: section.questions,
|
|
138
148
|
checkList: inputBody.checklistName,
|
|
139
149
|
} );
|
|
140
150
|
}
|
|
151
|
+
}
|
|
152
|
+
if ( inputBody._id ) {
|
|
153
|
+
await taskQuestionService.deleteMany( { checkListId: checkListId } );
|
|
154
|
+
await taskAssignService.updateMany( { checkListId: inputBody._id }, { checkListName: inputBody.checklistName } );
|
|
155
|
+
}
|
|
156
|
+
if ( sectionList.length ) {
|
|
157
|
+
await taskQuestionService.insertMany( sectionList );
|
|
158
|
+
}
|
|
159
|
+
let message = req.body?._id ? 'Task Updated Successfully' : 'Task Created Successfully';
|
|
160
|
+
if ( inputBody.submitType == 'save' ) {
|
|
161
|
+
message = 'Saved in draft successfully';
|
|
162
|
+
}
|
|
163
|
+
if ( inputBody._id ) {
|
|
164
|
+
let questionList = {
|
|
165
|
+
questionAdd: [],
|
|
166
|
+
questionEdit: [],
|
|
167
|
+
questionDelete: [],
|
|
168
|
+
};
|
|
141
169
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
170
|
+
function findDifferences( obj1, obj2 ) {
|
|
171
|
+
return Object.keys( obj1 ).reduce( ( diff, key ) => {
|
|
172
|
+
if ( !isEqual( obj1[key], obj2[key] ) ) {
|
|
173
|
+
diff[key] = { previous: obj1[key], new: obj2[key] };
|
|
174
|
+
}
|
|
175
|
+
return diff;
|
|
176
|
+
}, {} );
|
|
145
177
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
178
|
+
|
|
179
|
+
console.log( inputBody.sections );
|
|
180
|
+
getExistQuestions.forEach( ( ele ) => {
|
|
181
|
+
ele.question.forEach( ( qn ) => {
|
|
182
|
+
console.log( qn );
|
|
183
|
+
console.log( JSON.stringify( inputBody.sections[0].questions ) );
|
|
184
|
+
let question = inputBody.sections[0].questions.find( ( qns ) => qns.oldQname === qn.qname );
|
|
185
|
+
console.log( question, 'tion' );
|
|
186
|
+
if ( question ) {
|
|
187
|
+
qn.answers.forEach( ( ans ) => {
|
|
188
|
+
delete ans.answeroptionNumber;
|
|
189
|
+
} );
|
|
190
|
+
question.answers.forEach( ( ans ) => {
|
|
191
|
+
delete ans.answeroptionNumber;
|
|
192
|
+
} );
|
|
193
|
+
let compare = findDifferences( qn, question );
|
|
194
|
+
if ( Object.keys( compare ).length && ( compare?.answerType || compare?.answers || compare?.linkType ) ) {
|
|
195
|
+
questionList.questionEdit.push( { sectionName: ele.section, questions: [ { previous: qn }, { new: question } ] } );
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
let sectionIndex = questionList.questionDelete.findIndex( ( sec ) => sec.sectionName === ele.section );
|
|
199
|
+
|
|
200
|
+
if ( sectionIndex !== -1 ) {
|
|
201
|
+
questionList.questionDelete[sectionIndex].questions.push( qn );
|
|
202
|
+
} else {
|
|
203
|
+
questionList.questionDelete.push( { sectionName: ele?.section || 'Section 1', questions: [ qn ] } );
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
} );
|
|
207
|
+
} );
|
|
208
|
+
|
|
209
|
+
console.log( getExistQuestions, 'qns' );
|
|
210
|
+
|
|
211
|
+
inputBody.sections.forEach( ( ele ) => {
|
|
212
|
+
ele.questions.forEach( ( qn ) => {
|
|
213
|
+
let question = getExistQuestions[0].question.find( ( qns ) => qns.qname === qn.oldQname );
|
|
214
|
+
|
|
215
|
+
if ( !question ) {
|
|
216
|
+
let sectionIndex = questionList.questionAdd.findIndex( ( sec ) => sec.sectionName === ele.name );
|
|
217
|
+
|
|
218
|
+
if ( sectionIndex !== -1 ) {
|
|
219
|
+
questionList.questionAdd[sectionIndex].questions.push( qn );
|
|
220
|
+
} else {
|
|
221
|
+
questionList.questionAdd.push( { sectionName: ele?.name || 'Section 1', questions: [ qn ] } );
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
} );
|
|
225
|
+
} );
|
|
226
|
+
|
|
227
|
+
if ( questionList.questionAdd.length || questionList.questionEdit.length || questionList.questionDelete.length || inputBody.checklistName.toLowerCase() != checkListDetails.checkListName.toLowerCase() || inputBody.checklistDescription.toLowerCase() != checkListDetails.checkListDescription.toLowerCase() ) {
|
|
228
|
+
let insertLogData = {
|
|
229
|
+
client_id: req.body.clientId,
|
|
230
|
+
createAt: new Date(),
|
|
231
|
+
sourceCheckList_id: inputBody._id,
|
|
232
|
+
checkListName: inputBody.checklistName,
|
|
233
|
+
fromCheckListName: '',
|
|
234
|
+
type: 'checklist',
|
|
235
|
+
action: 'edited',
|
|
236
|
+
storeName: '',
|
|
237
|
+
store_id: '',
|
|
238
|
+
createdByEmail: req.user.email,
|
|
239
|
+
createdBy: req.user.userName,
|
|
240
|
+
coverage: taskDetails?.coverage,
|
|
241
|
+
logDetails: {
|
|
242
|
+
...( inputBody.checklistName.toLowerCase() == checkListDetails.checkListName.toLowerCase() ) ? { updatedChecklistName: {} } :{ updatedChecklistName: {
|
|
243
|
+
previous: checkListDetails.checkListName,
|
|
244
|
+
new: inputBody.checklistName,
|
|
245
|
+
} },
|
|
246
|
+
...( inputBody.checklistDescription.toLowerCase() == checkListDetails.checkListDescription.toLowerCase() ) ? { updatedChecklistDescription: {} } :{ updatedChecklistDescription: {
|
|
247
|
+
previous: checkListDetails.checkListDescription,
|
|
248
|
+
new: inputBody.checklistDescription,
|
|
249
|
+
} },
|
|
250
|
+
updatedSectionName: [],
|
|
251
|
+
questionAdd: questionList.questionAdd,
|
|
252
|
+
questionEdit: questionList.questionEdit,
|
|
253
|
+
questionDelete: questionList.questionDelete,
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, insertLogData );
|
|
150
257
|
}
|
|
151
|
-
return res.sendSuccess( { checklistId: checkListId, message: message } );
|
|
152
258
|
} else {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
259
|
+
let logObj = {
|
|
260
|
+
client_id: inputBody.clientId,
|
|
261
|
+
createAt: new Date(),
|
|
262
|
+
sourceCheckList_id: inputBody._id,
|
|
263
|
+
checkListName: inputBody.checklistName,
|
|
264
|
+
fromCheckListName: '',
|
|
265
|
+
type: 'task',
|
|
266
|
+
action: 'created',
|
|
267
|
+
storeName: '',
|
|
268
|
+
store_id: '',
|
|
269
|
+
createdByEmail: req.user.email,
|
|
270
|
+
createdBy: req.user.userName,
|
|
271
|
+
coverage: 'store',
|
|
272
|
+
logDetails: {},
|
|
273
|
+
};
|
|
274
|
+
await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
|
|
159
275
|
}
|
|
276
|
+
return res.sendSuccess( { checklistId: checkListId, message: message } );
|
|
160
277
|
} else {
|
|
161
278
|
return res.sendError( { message: 'something went wrong' }, 500 );
|
|
162
279
|
}
|
|
@@ -889,7 +1006,7 @@ export async function taskConfig( req, res ) {
|
|
|
889
1006
|
return res.sendError( 'No data found', 204 );
|
|
890
1007
|
}
|
|
891
1008
|
|
|
892
|
-
let configDetails = { ...
|
|
1009
|
+
let configDetails = { ...inputBody };
|
|
893
1010
|
configDetails.approver = configDetails.approver.length ? configDetails.approver.map( ( item ) => {
|
|
894
1011
|
return { name: item.name, value: item.value };
|
|
895
1012
|
} ) : [];
|
|
@@ -960,6 +1077,81 @@ export async function taskConfig( req, res ) {
|
|
|
960
1077
|
}
|
|
961
1078
|
if ( response?.modifiedCount || response?.matchedCount || response?.upsertedCount ) {
|
|
962
1079
|
let message = inputBody.submitType == 'publish' ? 'Configuration Updated Successfully' : 'Saved in draft successfully';
|
|
1080
|
+
checklistDetails = checklistDetails.toObject();
|
|
1081
|
+
checklistDetails.scheduleEndTimeISO = checklistDetails?.scheduleEndTime ? dayjs.utc( checklistDetails?.scheduleEndTime, 'hh:mm A' ).format() : '';
|
|
1082
|
+
checklistDetails.scheduleDate = checklistDetails.scheduleDate ? dayjs.utc( checklistDetails?.scheduleDate ).format( 'YYYY-MM-DD' ) : '';
|
|
1083
|
+
configDetails.scheduleDate = configDetails.scheduleDate ? dayjs( configDetails?.scheduleDate ).format( 'YYYY-MM-DD' ) : '';
|
|
1084
|
+
let removedKeys = [ 'publish', 'publishDate', 'storeCount', 'sections', 'createdAt', 'updatedAt', 'scheduleEndTimeISO' ];
|
|
1085
|
+
removedKeys.forEach( ( item ) => {
|
|
1086
|
+
delete checklistDetails?.[item];
|
|
1087
|
+
delete configDetails?.[item];
|
|
1088
|
+
} );
|
|
1089
|
+
let differences = findObjectDifference( checklistDetails, configDetails );
|
|
1090
|
+
if ( Object.keys( differences ).length || inputBody.added.length || inputBody.removed.length ) {
|
|
1091
|
+
let insertData = {
|
|
1092
|
+
client_id: inputBody.clientId,
|
|
1093
|
+
createAt: new Date(),
|
|
1094
|
+
sourceCheckList_id: configDetails._id,
|
|
1095
|
+
checkListName: configDetails.checkListName,
|
|
1096
|
+
fromCheckListName: '',
|
|
1097
|
+
type: 'task',
|
|
1098
|
+
action: 'updated',
|
|
1099
|
+
storeName: '',
|
|
1100
|
+
store_id: '',
|
|
1101
|
+
createdByEmail: req.user.email,
|
|
1102
|
+
createdBy: req.user.userName,
|
|
1103
|
+
coverage: configDetails.coverage,
|
|
1104
|
+
logDetails: {
|
|
1105
|
+
schedule: {
|
|
1106
|
+
previous: {
|
|
1107
|
+
...( differences?.scheduleDate && ( differences?.scheduleDate.previous != '' && differences?.scheduleDate.previous != null ) ) ? { scheduleDate: checklistDetails?.scheduleDate } :{},
|
|
1108
|
+
time: differences?.scheduleEndTime ? checklistDetails.scheduleEndTime : '',
|
|
1109
|
+
priority: differences?.priorityType ? checklistDetails?.priorityType : '',
|
|
1110
|
+
},
|
|
1111
|
+
new: {
|
|
1112
|
+
...( differences?.scheduleDate && ( differences?.scheduleDate.new != '' && differences?.scheduleDate.new != null ) ) ? { scheduleDate: configDetails?.scheduleDate } :{},
|
|
1113
|
+
time: differences?.scheduleEndTime ? configDetails.scheduleEndTime : '',
|
|
1114
|
+
priority: differences?.priorityType ? configDetails?.priorityType : '',
|
|
1115
|
+
},
|
|
1116
|
+
},
|
|
1117
|
+
response: {
|
|
1118
|
+
previous: [
|
|
1119
|
+
...( differences?.allowedStoreLocation && checklistDetails.allowedStoreLocation ? [ 'Geo fencing' ] : [] ),
|
|
1120
|
+
],
|
|
1121
|
+
new: [
|
|
1122
|
+
...( differences?.allowedStoreLocation && configDetails.allowedStoreLocation ? [ 'Geo fencing' ] : [] ),
|
|
1123
|
+
],
|
|
1124
|
+
},
|
|
1125
|
+
...( differences?.approver ) ? { approver:
|
|
1126
|
+
{ previous: differences?.approver?.previous.map( ( item ) => item.name ).toString(),
|
|
1127
|
+
new: differences?.approver?.new.map( ( item ) => item.name ).toString() },
|
|
1128
|
+
} : { approver: {} },
|
|
1129
|
+
owner: {},
|
|
1130
|
+
...( inputBody.coverage == 'store' ) ? { storeAdded: inputBody.added } :{ storeAdded: [] },
|
|
1131
|
+
...( inputBody.coverage == 'store' ) ? { storeRemoved: inputBody.removed } :{ storeRemoved: [] },
|
|
1132
|
+
...( inputBody.coverage == 'user' ) ? { userAdded: inputBody.added } :{ userAdded: [] },
|
|
1133
|
+
...( inputBody.coverage == 'user' ) ? { userRemoved: inputBody.removed } :{ userRemoved: [] },
|
|
1134
|
+
},
|
|
1135
|
+
};
|
|
1136
|
+
await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, insertData );
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
let logObj = {
|
|
1140
|
+
client_id: inputBody.client_id,
|
|
1141
|
+
createAt: new Date(),
|
|
1142
|
+
sourceCheckList_id: inputBody._id,
|
|
1143
|
+
checkListName: inputBody.checkListName,
|
|
1144
|
+
fromCheckListName: '',
|
|
1145
|
+
type: 'task',
|
|
1146
|
+
action: inputBody.publish ? 'published' : 'unpublished',
|
|
1147
|
+
storeName: '',
|
|
1148
|
+
store_id: '',
|
|
1149
|
+
createdByEmail: req.user.email,
|
|
1150
|
+
createdBy: req.user.userName,
|
|
1151
|
+
coverage: inputBody.coverage,
|
|
1152
|
+
logDetails: {},
|
|
1153
|
+
};
|
|
1154
|
+
await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
|
|
963
1155
|
return res.sendSuccess( { id: inputBody._id, message: message } );
|
|
964
1156
|
}
|
|
965
1157
|
} catch ( e ) {
|
|
@@ -969,6 +1161,32 @@ export async function taskConfig( req, res ) {
|
|
|
969
1161
|
}
|
|
970
1162
|
}
|
|
971
1163
|
|
|
1164
|
+
function findObjectDifference( oldObj, newObj ) {
|
|
1165
|
+
const isEqual = ( a, b ) => JSON.stringify( a ) === JSON.stringify( b );
|
|
1166
|
+
|
|
1167
|
+
const getArrayDiff = ( oldArr, newArr ) => {
|
|
1168
|
+
const removed = oldArr.filter( ( item ) => !newArr.some( ( newItem ) => isEqual( newItem, item ) ) );
|
|
1169
|
+
const added = newArr.filter( ( item ) => !oldArr.some( ( oldItem ) => isEqual( oldItem, item ) ) );
|
|
1170
|
+
if ( removed.length || added.length ) {
|
|
1171
|
+
return { previous: oldArr, new: newArr };
|
|
1172
|
+
}
|
|
1173
|
+
return [];
|
|
1174
|
+
};
|
|
1175
|
+
const difference = Object.keys( oldObj ).reduce( ( diff, key ) => {
|
|
1176
|
+
oldObj[key] = oldObj[key] == null ? '' : oldObj[key];
|
|
1177
|
+
if ( !isEqual( oldObj[key], newObj[key] ) ) {
|
|
1178
|
+
if ( !Array.isArray( newObj[key] ) ) {
|
|
1179
|
+
diff[key] = { previous: oldObj[key], new: newObj[key] };
|
|
1180
|
+
} else {
|
|
1181
|
+
diff[key] = getArrayDiff( oldObj[key] || [], newObj[key] || [] );
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
return diff;
|
|
1185
|
+
}, {} );
|
|
1186
|
+
|
|
1187
|
+
return difference;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
972
1190
|
export async function insertSingleProcessData( checklistId ) {
|
|
973
1191
|
try {
|
|
974
1192
|
let currentdate = new Date();
|
|
@@ -1713,6 +1931,26 @@ export async function createChecklistTask( req, res ) {
|
|
|
1713
1931
|
if ( !searchResponse.ok ) {
|
|
1714
1932
|
return res.sendError( 'Something went wrong', 500 );
|
|
1715
1933
|
}
|
|
1934
|
+
let logData= {
|
|
1935
|
+
'client_id': inputBody.clientId,
|
|
1936
|
+
'createAt': new Date(),
|
|
1937
|
+
'sourceCheckList_id': taskDetails.sourceCheckList_id,
|
|
1938
|
+
'checkListName': inputBody.checkListName,
|
|
1939
|
+
'fromCheckListName': taskDetails.checkListName,
|
|
1940
|
+
'type': 'task',
|
|
1941
|
+
'action': 'created',
|
|
1942
|
+
'store_id': storeDetails?.storeId?storeDetails.storeId:'',
|
|
1943
|
+
'storeName': inputBody?.storeName?inputBody?.storeName:'',
|
|
1944
|
+
'createdByEmail': req.user.email,
|
|
1945
|
+
'createdBy': req.user._id,
|
|
1946
|
+
'userName': inputBody.userName,
|
|
1947
|
+
'userEmail': inputBody.userEmail,
|
|
1948
|
+
'coverage': 'store',
|
|
1949
|
+
'logDetails': {},
|
|
1950
|
+
};
|
|
1951
|
+
let urlopensearch = JSON.parse( process.env.OPENSEARCH );
|
|
1952
|
+
console.log( 'logData', logData );
|
|
1953
|
+
await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
|
|
1716
1954
|
}
|
|
1717
1955
|
await insertSingleProcessData( response?._id );
|
|
1718
1956
|
return res.sendSuccess( 'Task created successfully' );
|
|
@@ -1911,6 +2149,26 @@ export async function createChecklistMultiTask( req, res ) {
|
|
|
1911
2149
|
if ( !searchResponse.ok ) {
|
|
1912
2150
|
return res.sendError( 'Something went wrong', 500 );
|
|
1913
2151
|
}
|
|
2152
|
+
let logData= {
|
|
2153
|
+
'client_id': inputBody.clientId,
|
|
2154
|
+
'createAt': new Date(),
|
|
2155
|
+
'sourceCheckList_id': taskDetails.sourceCheckList_id,
|
|
2156
|
+
'checkListName': inputBody.checkListName,
|
|
2157
|
+
'fromCheckListName': taskDetails.checkListName,
|
|
2158
|
+
'type': 'task',
|
|
2159
|
+
'action': 'created',
|
|
2160
|
+
'store_id': storeDetails?.storeId?storeDetails.storeId:'',
|
|
2161
|
+
'storeName': originaldata?.storeName?originaldata?.storeName:'',
|
|
2162
|
+
'createdByEmail': req.user.email,
|
|
2163
|
+
'createdBy': req.user._id,
|
|
2164
|
+
// 'userName': inputBody.userName,
|
|
2165
|
+
// 'userEmail': inputBody.userEmail,
|
|
2166
|
+
'coverage': 'store',
|
|
2167
|
+
'logDetails': {},
|
|
2168
|
+
};
|
|
2169
|
+
let urlopensearch = JSON.parse( process.env.OPENSEARCH );
|
|
2170
|
+
console.log( 'logData', logData );
|
|
2171
|
+
await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
|
|
1914
2172
|
}
|
|
1915
2173
|
await insertSingleProcessData( response?._id );
|
|
1916
2174
|
}
|
|
@@ -2001,7 +2259,7 @@ export async function redoTask( req, res ) {
|
|
|
2001
2259
|
return res.sendError( 'Question number is Required', 400 );
|
|
2002
2260
|
}
|
|
2003
2261
|
|
|
2004
|
-
let taskDetails = await taskProcessedService.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1 } );
|
|
2262
|
+
let taskDetails = await taskProcessedService.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1, userEmail: 1, coverage: 1 } );
|
|
2005
2263
|
if ( !taskDetails ) {
|
|
2006
2264
|
return res.sendError( 'No data found', 204 );
|
|
2007
2265
|
}
|
|
@@ -2066,6 +2324,26 @@ export async function redoTask( req, res ) {
|
|
|
2066
2324
|
let url = JSON.parse( process.env.LAMBDAURL );
|
|
2067
2325
|
let searchResponse = await fetch( url.redoTask, requestOptions );
|
|
2068
2326
|
// console.log( searchResponse.ok );
|
|
2327
|
+
let logData= {
|
|
2328
|
+
'client_id': taskDetails.client_id,
|
|
2329
|
+
'createAt': new Date(),
|
|
2330
|
+
'sourceCheckList_id': taskDetails.sourceCheckList_id,
|
|
2331
|
+
'checkListName': taskDetails.checkListName,
|
|
2332
|
+
'fromCheckListName': taskDetails.checkListName,
|
|
2333
|
+
'type': 'checklist',
|
|
2334
|
+
'action': 'redo',
|
|
2335
|
+
'storeName': taskDetails?.storeName?taskDetails?.storeName:'',
|
|
2336
|
+
'store_id': taskDetails?.store_id?taskDetails?.store_id:'',
|
|
2337
|
+
'userName': taskDetails.userName,
|
|
2338
|
+
'userEmail': taskDetails.userEmail,
|
|
2339
|
+
'createdByEmail': req.user.email,
|
|
2340
|
+
'createdBy': req.user.userName,
|
|
2341
|
+
'coverage': taskDetails.coverage,
|
|
2342
|
+
'logDetails': {},
|
|
2343
|
+
};
|
|
2344
|
+
let urlopensearch = JSON.parse( process.env.OPENSEARCH );
|
|
2345
|
+
console.log( 'logData', logData );
|
|
2346
|
+
await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
|
|
2069
2347
|
if ( searchResponse.ok ) {
|
|
2070
2348
|
return res.sendSuccess( 'Question redo successfully' );
|
|
2071
2349
|
} else {
|
|
@@ -2095,7 +2373,7 @@ export async function redomultiTask( req, res ) {
|
|
|
2095
2373
|
return res.sendError( 'Question number is Required', 400 );
|
|
2096
2374
|
}
|
|
2097
2375
|
|
|
2098
|
-
let taskDetails = await taskProcessedService.findOne( { _id: originalData.checklistId }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1 } );
|
|
2376
|
+
let taskDetails = await taskProcessedService.findOne( { _id: originalData.checklistId }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1, userEmail: 1, coverage: 1 } );
|
|
2099
2377
|
if ( !taskDetails ) {
|
|
2100
2378
|
return res.sendError( 'No data found', 204 );
|
|
2101
2379
|
}
|
|
@@ -2162,6 +2440,26 @@ export async function redomultiTask( req, res ) {
|
|
|
2162
2440
|
let url = JSON.parse( process.env.LAMBDAURL );
|
|
2163
2441
|
let searchResponse = await fetch( url.redoTask, requestOptions );
|
|
2164
2442
|
console.log( searchResponse.ok );
|
|
2443
|
+
let logData= {
|
|
2444
|
+
'client_id': taskDetails.client_id,
|
|
2445
|
+
'createAt': new Date(),
|
|
2446
|
+
'sourceCheckList_id': taskDetails.sourceCheckList_id,
|
|
2447
|
+
'checkListName': taskDetails.checkListName,
|
|
2448
|
+
'fromCheckListName': taskDetails.checkListName,
|
|
2449
|
+
'type': 'checklist',
|
|
2450
|
+
'action': 'redo',
|
|
2451
|
+
'storeName': taskDetails?.storeName?taskDetails?.storeName:'',
|
|
2452
|
+
'store_id': taskDetails?.store_id?taskDetails?.store_id:'',
|
|
2453
|
+
'userName': taskDetails.userName,
|
|
2454
|
+
'userEmail': taskDetails.userEmail,
|
|
2455
|
+
'createdByEmail': req.user.email,
|
|
2456
|
+
'createdBy': req.user.userName,
|
|
2457
|
+
'coverage': taskDetails.coverage,
|
|
2458
|
+
'logDetails': {},
|
|
2459
|
+
};
|
|
2460
|
+
let urlopensearch = JSON.parse( process.env.OPENSEARCH );
|
|
2461
|
+
console.log( 'logData', logData );
|
|
2462
|
+
await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
|
|
2165
2463
|
}
|
|
2166
2464
|
}
|
|
2167
2465
|
return res.sendSuccess( 'Question redo successfully' );
|
|
@@ -2588,6 +2886,22 @@ export const updatePublish = async ( req, res ) => {
|
|
|
2588
2886
|
createdByEmail: req.user.email,
|
|
2589
2887
|
};
|
|
2590
2888
|
await checklistLogs.create( logInsertData );
|
|
2889
|
+
let logObj = {
|
|
2890
|
+
client_id: req.body.clientId,
|
|
2891
|
+
createAt: new Date(),
|
|
2892
|
+
sourceCheckList_id: req.body.checklistId,
|
|
2893
|
+
checkListName: getCheckDetails.checkListName,
|
|
2894
|
+
fromCheckListName: '',
|
|
2895
|
+
type: 'task',
|
|
2896
|
+
action: req.body.publish ? 'published' : 'unpublished',
|
|
2897
|
+
storeName: '',
|
|
2898
|
+
store_id: '',
|
|
2899
|
+
createdByEmail: req.user.email,
|
|
2900
|
+
createdBy: req.user.userName,
|
|
2901
|
+
coverage: getCheckDetails.coverage,
|
|
2902
|
+
logDetails: {},
|
|
2903
|
+
};
|
|
2904
|
+
await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
|
|
2591
2905
|
return res.sendSuccess( { checklistName: getCheckDetails.checkListName, message: 'Updated Successfully' } );
|
|
2592
2906
|
} catch ( e ) {
|
|
2593
2907
|
logger.error( 'updatePublish task erroe =>', e );
|
|
@@ -3982,6 +4296,43 @@ export async function updateAssign( req, res ) {
|
|
|
3982
4296
|
// req.body.assignedGroup = req.body.assignedGroup.map( ( ele ) => {
|
|
3983
4297
|
// return { id: ele };
|
|
3984
4298
|
// } );
|
|
4299
|
+
let getAssignedDetails = await taskAssignService.find( { checkListId: req.body.taskId } );
|
|
4300
|
+
if ( getAssignedDetails.length ) {
|
|
4301
|
+
if ( req.body.coverage == 'store' ) {
|
|
4302
|
+
getAssignedDetails = [ ...new Set( getAssignedDetails.map( ( ele ) => ele.storeName ) ) ];
|
|
4303
|
+
} else {
|
|
4304
|
+
getAssignedDetails = [ ...new Set( getAssignedDetails.map( ( ele ) => ele.userName ) ) ];
|
|
4305
|
+
}
|
|
4306
|
+
}
|
|
4307
|
+
|
|
4308
|
+
let added = req.body.assignedList.filter( ( item ) => {
|
|
4309
|
+
let storeUsername;
|
|
4310
|
+
if ( req.body.coverage == 'store' ) {
|
|
4311
|
+
storeUsername = item.storeName;
|
|
4312
|
+
} else {
|
|
4313
|
+
storeUsername = item.userName;
|
|
4314
|
+
}
|
|
4315
|
+
if ( !getAssignedDetails.includes( storeUsername ) ) {
|
|
4316
|
+
return item;
|
|
4317
|
+
}
|
|
4318
|
+
} ).map( ( ele ) => {
|
|
4319
|
+
if ( req.body.coverage == 'store' ) {
|
|
4320
|
+
return ele.storeName;
|
|
4321
|
+
} else {
|
|
4322
|
+
return ele.userName;
|
|
4323
|
+
}
|
|
4324
|
+
} );
|
|
4325
|
+
let removed = getAssignedDetails.filter( ( item ) => {
|
|
4326
|
+
let list;
|
|
4327
|
+
if ( req.body.coverage == 'store' ) {
|
|
4328
|
+
list = req.body.assignedList.map( ( item ) => item.storeName );
|
|
4329
|
+
} else {
|
|
4330
|
+
list = req.body.assignedList.map( ( item ) => item.userName ); ;
|
|
4331
|
+
}
|
|
4332
|
+
if ( !list.includes( item ) ) {
|
|
4333
|
+
return item;
|
|
4334
|
+
}
|
|
4335
|
+
} );
|
|
3985
4336
|
await taskAssignService.deleteMany( { checkListId: req.body.taskId } );
|
|
3986
4337
|
let assignedUserList = [];
|
|
3987
4338
|
let userEmailList = req.body.assignedList.map( ( ele ) => ele.userEmail.toLowerCase() );
|
|
@@ -4044,7 +4395,7 @@ export async function updateAssign( req, res ) {
|
|
|
4044
4395
|
}
|
|
4045
4396
|
} ) );
|
|
4046
4397
|
await taskAssignService.insertMany( assignedUserList );
|
|
4047
|
-
return res.sendSuccess( 'Assign details updated successfully' );
|
|
4398
|
+
return res.sendSuccess( { message: 'Assign details updated successfully', added, removed } );
|
|
4048
4399
|
} catch ( e ) {
|
|
4049
4400
|
logger.error( { functionName: 'updateAssign', error: e } );
|
|
4050
4401
|
}
|