tango-app-api-task 1.0.0-alpha.0
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/.eslintrc.cjs +41 -0
- package/README.md +29 -0
- package/index.js +10 -0
- package/package.json +39 -0
- package/src/controllers/internalAPI.controller.js +304 -0
- package/src/controllers/task.controller.js +1059 -0
- package/src/controllers/taskActionCenter.controllers.js +383 -0
- package/src/controllers/taskDashboard.controllers.js +747 -0
- package/src/routes/internalAPI.routes.js +11 -0
- package/src/routes/task.routes.js +19 -0
- package/src/routes/taskActionCenter.routes.js +16 -0
- package/src/routes/taskDashboard.routes.js +18 -0
- package/src/service/approver.service.js +17 -0
- package/src/service/checklistLog.service.js +33 -0
- package/src/service/domain.service.js +23 -0
- package/src/service/processedChecklist.service.js +6 -0
- package/src/service/processedTaskConfig.service.js +32 -0
- package/src/service/processedTaskList.service.js +26 -0
- package/src/service/store.service.js +29 -0
- package/src/service/task.service.js +23 -0
- package/src/service/taskAssign.service.js +33 -0
- package/src/service/taskQuestion.service.js +31 -0
- package/src/service/user.service.js +26 -0
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import * as traxApprover from '../service/approver.service.js';
|
|
2
|
+
import * as processedTask from '../service/processedTaskList.service.js';
|
|
3
|
+
import { logger } from 'tango-app-api-middleware';
|
|
4
|
+
import * as processedChecklist from '../service/processedChecklist.service.js';
|
|
5
|
+
import mongoose from 'mongoose';
|
|
6
|
+
const ObjectId = mongoose.Types.ObjectId;
|
|
7
|
+
export const overallCards = async ( req, res ) => {
|
|
8
|
+
try {
|
|
9
|
+
let query;
|
|
10
|
+
let taskIdList = [];
|
|
11
|
+
let checklistIdList = [];
|
|
12
|
+
let resultData;
|
|
13
|
+
if ( req?.user?.userType == 'client' && req.user.role == 'superadmin' || req.body?.clientId ) {
|
|
14
|
+
let clientId = req.user?.clientId || req.body?.clientId;
|
|
15
|
+
query = { client_id: clientId };
|
|
16
|
+
} else {
|
|
17
|
+
query = { userEmail: req.user.userEmail };
|
|
18
|
+
}
|
|
19
|
+
let details = await traxApprover.find( query );
|
|
20
|
+
if ( details.length ) {
|
|
21
|
+
taskIdList = [
|
|
22
|
+
...new Set(
|
|
23
|
+
details
|
|
24
|
+
.filter( ( item ) => item.type === 'task' )
|
|
25
|
+
.map( ( ele ) => ele.checkListId.toString() ),
|
|
26
|
+
),
|
|
27
|
+
].map( ( item ) => new ObjectId( item ) );
|
|
28
|
+
checklistIdList = [
|
|
29
|
+
...new Set(
|
|
30
|
+
details
|
|
31
|
+
.filter( ( item ) => item.type === 'checklist' )
|
|
32
|
+
.map( ( ele ) => ele.checkListId.toString() ),
|
|
33
|
+
),
|
|
34
|
+
].map( ( item ) => new ObjectId( item ) );
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let toDate = new Date( req.body.date );
|
|
38
|
+
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
39
|
+
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
40
|
+
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
41
|
+
let groupQuery = {
|
|
42
|
+
$group: {
|
|
43
|
+
_id: '',
|
|
44
|
+
count: { $sum: 1 },
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
query = [
|
|
49
|
+
{
|
|
50
|
+
$match: {
|
|
51
|
+
date_iso: { $gte: new Date( req.body.date ), $lte: toDate },
|
|
52
|
+
sourceCheckList_id: { $in: taskIdList },
|
|
53
|
+
approvalStatus: false,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{ ...groupQuery },
|
|
57
|
+
];
|
|
58
|
+
let taskCount = await processedTask.aggregate( query );
|
|
59
|
+
|
|
60
|
+
query = [
|
|
61
|
+
{
|
|
62
|
+
$match: {
|
|
63
|
+
date_iso: { $gte: new Date( req.body.date ), $lte: toDate },
|
|
64
|
+
sourceCheckList_id: { $in: checklistIdList },
|
|
65
|
+
approvalStatus: false,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
{ ...groupQuery },
|
|
69
|
+
];
|
|
70
|
+
let checklistCount = await processedChecklist.aggregate( query );
|
|
71
|
+
resultData = { taskCount: taskCount?.[0]?.count || 0, checklistCount: checklistCount?.[0]?.count || 0 };
|
|
72
|
+
return res.sendSuccess( resultData );
|
|
73
|
+
} catch ( error ) {
|
|
74
|
+
console.log( 'error =>', error );
|
|
75
|
+
logger.error( { error: error, function: 'overallCards' } );
|
|
76
|
+
return res.sendError( error, 500 );
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// async function overallCardsData( requestData ) {
|
|
81
|
+
// try {
|
|
82
|
+
// let cardData = {
|
|
83
|
+
// 'checklistApproval': {
|
|
84
|
+
// 'count': 50, // Checklist Count
|
|
85
|
+
// },
|
|
86
|
+
// 'taskApproval': {
|
|
87
|
+
// 'count': 40, // Task Count
|
|
88
|
+
// },
|
|
89
|
+
// };
|
|
90
|
+
// // resultData.card = cardData;
|
|
91
|
+
// return { cardData: cardData };
|
|
92
|
+
// } catch ( error ) {
|
|
93
|
+
// console.log( 'error =>', error );
|
|
94
|
+
// logger.error( { error: error, message: data, function: 'overallCardsData' } );
|
|
95
|
+
// }
|
|
96
|
+
// }
|
|
97
|
+
|
|
98
|
+
export const approvalTable = async ( req, res ) => {
|
|
99
|
+
try {
|
|
100
|
+
let query;
|
|
101
|
+
let taskIdList = [];
|
|
102
|
+
let checklistIdList = [];
|
|
103
|
+
let resultData;
|
|
104
|
+
let taskResult = [];
|
|
105
|
+
let checklistResult = [];
|
|
106
|
+
if ( req?.user?.userType == 'client' && req.user.role == 'superadmin' || req.body?.clientId ) {
|
|
107
|
+
let clientId = req.user?.clientId || req.body?.clientId;
|
|
108
|
+
query = { client_id: clientId };
|
|
109
|
+
} else {
|
|
110
|
+
query = { userEmail: req.user.userEmail };
|
|
111
|
+
}
|
|
112
|
+
let details = await traxApprover.find( query );
|
|
113
|
+
if ( details.length ) {
|
|
114
|
+
taskIdList = [
|
|
115
|
+
...new Set(
|
|
116
|
+
details
|
|
117
|
+
.filter( ( item ) => item.type === 'task' )
|
|
118
|
+
.map( ( ele ) => ele.checkListId.toString() ),
|
|
119
|
+
),
|
|
120
|
+
].map( ( item ) => new ObjectId( item ) );
|
|
121
|
+
checklistIdList = [
|
|
122
|
+
...new Set(
|
|
123
|
+
details
|
|
124
|
+
.filter( ( item ) => item.type === 'checklist' )
|
|
125
|
+
.map( ( ele ) => ele.checkListId.toString() ),
|
|
126
|
+
),
|
|
127
|
+
].map( ( item ) => new ObjectId( item ) );
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let toDate = new Date( req.body.date );
|
|
131
|
+
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
132
|
+
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
133
|
+
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
134
|
+
|
|
135
|
+
let groupQuery = [ {
|
|
136
|
+
$group: {
|
|
137
|
+
_id: { checklistId: '$sourceCheckList_id', redoType: '$redoStatus' },
|
|
138
|
+
checkListName: { $first: '$checkListName' },
|
|
139
|
+
scheduleRepeatedType: { $first: '$scheduleRepeatedType' },
|
|
140
|
+
checkListType: { $first: '$checkListType' },
|
|
141
|
+
createdByName: { $first: '$createdByName' },
|
|
142
|
+
storeCount: { $sum: 1 },
|
|
143
|
+
submitCount: { $sum: {
|
|
144
|
+
$cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ],
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
publishDate: { $first: '$publishDate' },
|
|
148
|
+
priorityType: { $first: '$priorityType' },
|
|
149
|
+
approveCount: { $sum: {
|
|
150
|
+
$cond: [ { $eq: [ '$approvalStatus', true ] }, 1, 0 ],
|
|
151
|
+
} },
|
|
152
|
+
unApproveCount: {
|
|
153
|
+
$sum: {
|
|
154
|
+
$cond: [
|
|
155
|
+
{ $eq: [ '$approvalStatus', false ] }, 1, 0,
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
$project: {
|
|
163
|
+
_id: 0,
|
|
164
|
+
sourceChecklistId: '$_id.checklistId',
|
|
165
|
+
checkListName: 1,
|
|
166
|
+
scheduleRepeatedType: 1,
|
|
167
|
+
checkListType: 1,
|
|
168
|
+
createdByName: 1,
|
|
169
|
+
storeCount: 1,
|
|
170
|
+
submitCount: 1,
|
|
171
|
+
publishDate: 1,
|
|
172
|
+
priorityType: 1,
|
|
173
|
+
approveCount: 1,
|
|
174
|
+
unApproveCount: 1,
|
|
175
|
+
redo: '$_id.redoType',
|
|
176
|
+
},
|
|
177
|
+
} ];
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
if ( [ 'task', 'all' ].includes( req.body.type ) ) {
|
|
181
|
+
query = [
|
|
182
|
+
{
|
|
183
|
+
$match: {
|
|
184
|
+
date_iso: { $gte: new Date( req.body.date ), $lte: toDate },
|
|
185
|
+
sourceCheckList_id: { $in: taskIdList },
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
...groupQuery,
|
|
189
|
+
];
|
|
190
|
+
taskResult = await processedTask.aggregate( query );
|
|
191
|
+
}
|
|
192
|
+
if ( [ 'checklist', 'all' ].includes( req.body.type ) ) {
|
|
193
|
+
query = [
|
|
194
|
+
{
|
|
195
|
+
$match: {
|
|
196
|
+
date_iso: { $gte: new Date( req.body.date ), $lte: toDate },
|
|
197
|
+
sourceCheckList_id: { $in: checklistIdList },
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
...groupQuery,
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
checklistResult = await processedChecklist.aggregate( query );
|
|
204
|
+
}
|
|
205
|
+
const taskSummary = taskResult.reduce(
|
|
206
|
+
( acc, ele ) => {
|
|
207
|
+
if ( ele.unApproveCount === ele.storeCount ) {
|
|
208
|
+
acc.openTask.push( ele );
|
|
209
|
+
} else if ( ele.approveCount === ele.storeCount ) {
|
|
210
|
+
acc.doneTask.push( ele );
|
|
211
|
+
} else {
|
|
212
|
+
acc.inprogressTask.push( ele );
|
|
213
|
+
}
|
|
214
|
+
return acc;
|
|
215
|
+
},
|
|
216
|
+
{ openTask: [], inprogressTask: [], doneTask: [] },
|
|
217
|
+
);
|
|
218
|
+
const { openTask, inprogressTask, doneTask } = taskSummary;
|
|
219
|
+
|
|
220
|
+
const checklistSummary = checklistResult.reduce(
|
|
221
|
+
( acc, ele ) => {
|
|
222
|
+
if ( ele.unApproveCount === ele.storeCount ) {
|
|
223
|
+
acc.openChecklist.push( ele );
|
|
224
|
+
} else if ( ele.approveCount === ele.storeCount ) {
|
|
225
|
+
acc.doneChecklist.push( ele );
|
|
226
|
+
} else {
|
|
227
|
+
acc.inprogressChecklist.push( ele );
|
|
228
|
+
}
|
|
229
|
+
return acc;
|
|
230
|
+
},
|
|
231
|
+
{ openChecklist: [], inprogressChecklist: [], doneChecklist: [] },
|
|
232
|
+
);
|
|
233
|
+
const { openChecklist, inprogressChecklist, doneChecklist } = checklistSummary;
|
|
234
|
+
|
|
235
|
+
resultData = { open: [ ...openTask, ...openChecklist ], inprogress: [ ...inprogressTask, ...inprogressChecklist ], done: [ ...doneTask, ...doneChecklist ] };
|
|
236
|
+
|
|
237
|
+
return res.sendSuccess( resultData );
|
|
238
|
+
} catch ( error ) {
|
|
239
|
+
logger.error( { error: error, function: 'taskTable' } );
|
|
240
|
+
return res.sendError( error, 500 );
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// async function approvalTableData( requestData ) {
|
|
245
|
+
// try {
|
|
246
|
+
// let tableData = {
|
|
247
|
+
// 'totalCount': 50,
|
|
248
|
+
// 'approvalList': [
|
|
249
|
+
// {
|
|
250
|
+
// 'taskName': 'Hustlr Tray',
|
|
251
|
+
// 'createdBy': 'Olivia Rhye',
|
|
252
|
+
// 'totalAssigned': 100,
|
|
253
|
+
// 'totalSubmitted': 200,
|
|
254
|
+
// 'scheduledRepeatedType': 'daily', // weekly or monthly,
|
|
255
|
+
// 'dateString': '12 Jan,2024',
|
|
256
|
+
// 'sorceTaskId': '4862896912909',
|
|
257
|
+
// 'taskType': 'task', // checklist or redo
|
|
258
|
+
// 'status': 'open', // inprogress or approved
|
|
259
|
+
// 'priority': 'high',
|
|
260
|
+
// 'approved': 90,
|
|
261
|
+
// },
|
|
262
|
+
// {
|
|
263
|
+
// 'taskName': 'Hustlr Tray',
|
|
264
|
+
// 'createdBy': 'Olivia Rhye',
|
|
265
|
+
// 'totalAssigned': 100,
|
|
266
|
+
// 'totalSubmitted': 200,
|
|
267
|
+
// 'scheduledRepeatedType': 'daily', // weekly or monthly,
|
|
268
|
+
// 'dateString': '12 Jan,2024',
|
|
269
|
+
// 'sorceTaskId': '4862896912909',
|
|
270
|
+
// 'taskType': 'redo', // checklist or redo
|
|
271
|
+
// 'status': 'inprogress', // inprogress or approved
|
|
272
|
+
// 'priority': 'low',
|
|
273
|
+
// 'approved': 90,
|
|
274
|
+
// },
|
|
275
|
+
// {
|
|
276
|
+
// 'taskName': 'Hustlr Tray',
|
|
277
|
+
// 'createdBy': 'Olivia Rhye',
|
|
278
|
+
// 'totalAssigned': 100,
|
|
279
|
+
// 'totalSubmitted': 200,
|
|
280
|
+
// 'scheduledRepeatedType': 'daily', // weekly or monthly,
|
|
281
|
+
// 'dateString': '12 Jan,2024',
|
|
282
|
+
// 'sorceTaskId': '4862896912909',
|
|
283
|
+
// 'taskType': 'task', // checklist or redo
|
|
284
|
+
// 'status': 'approved', // inprogress or approved
|
|
285
|
+
// 'priority': 'low',
|
|
286
|
+
// 'approved': 90,
|
|
287
|
+
// },
|
|
288
|
+
// {
|
|
289
|
+
// 'taskName': 'Hustlr Tray',
|
|
290
|
+
// 'createdBy': 'Olivia Rhye',
|
|
291
|
+
// 'totalAssigned': 100,
|
|
292
|
+
// 'totalSubmitted': 200,
|
|
293
|
+
// 'scheduledRepeatedType': 'daily', // weekly or monthly,
|
|
294
|
+
// 'dateString': '12 Jan,2024',
|
|
295
|
+
// 'sorceTaskId': '4862896912909',
|
|
296
|
+
// 'taskType': 'task', // checklist or redo
|
|
297
|
+
// 'status': 'approved', // inprogress or approved
|
|
298
|
+
// 'priority': 'low',
|
|
299
|
+
// 'approved': 90,
|
|
300
|
+
// },
|
|
301
|
+
// ],
|
|
302
|
+
// };
|
|
303
|
+
// return tableData;
|
|
304
|
+
// } catch ( error ) {
|
|
305
|
+
// console.log( 'error =>', error );
|
|
306
|
+
// logger.error( { error: error, message: requestData, function: 'approvalTableData' } );
|
|
307
|
+
// return res.sendError( error, 500 );
|
|
308
|
+
// }
|
|
309
|
+
// }
|
|
310
|
+
|
|
311
|
+
export const activityLog = async ( req, res ) => {
|
|
312
|
+
try {
|
|
313
|
+
let requestData = req.body;
|
|
314
|
+
let resultData = await activityLogData( requestData );
|
|
315
|
+
return res.sendSuccess( resultData );
|
|
316
|
+
} catch ( error ) {
|
|
317
|
+
console.log( 'error =>', error );
|
|
318
|
+
logger.error( { error: error, function: 'activityLog' } );
|
|
319
|
+
return res.sendError( error, 500 );
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
async function activityLogData( requestData ) {
|
|
323
|
+
try {
|
|
324
|
+
let activityLogData = {
|
|
325
|
+
'totalCount': 50,
|
|
326
|
+
'activityLog': [
|
|
327
|
+
{
|
|
328
|
+
'storeName': 'LKST007',
|
|
329
|
+
'status': 'lapsed',
|
|
330
|
+
'checklistName': 'Daily VM Checklist',
|
|
331
|
+
'createdAt': '11:22 AM',
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
'storeName': 'LKST007',
|
|
335
|
+
'status': 'submitted',
|
|
336
|
+
'checklistName': 'Daily VM Checklist',
|
|
337
|
+
'createdAt': '11:22 AM',
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
'storeName': 'LKST007',
|
|
341
|
+
'status': 'started',
|
|
342
|
+
'checklistName': 'Daily VM Checklist',
|
|
343
|
+
'createdAt': '11:22 AM',
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
'storeName': 'LKST007',
|
|
347
|
+
'status': 'lapsed',
|
|
348
|
+
'checklistName': 'Daily VM Checklist',
|
|
349
|
+
'createdAt': '11:22 AM',
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
'storeName': 'LKST007',
|
|
353
|
+
'status': 'submitted',
|
|
354
|
+
'checklistName': 'Daily VM Checklist',
|
|
355
|
+
'createdAt': '11:22 AM',
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
'storeName': 'LKST007',
|
|
359
|
+
'status': 'submitted',
|
|
360
|
+
'checklistName': 'Daily VM Checklist',
|
|
361
|
+
'createdAt': '11:22 AM',
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
'storeName': 'LKST007',
|
|
365
|
+
'status': 'submitted',
|
|
366
|
+
'checklistName': 'Daily VM Checklist',
|
|
367
|
+
'createdAt': '11:22 AM',
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
'storeName': 'LKST007',
|
|
371
|
+
'status': 'submitted',
|
|
372
|
+
'checklistName': 'Daily VM Checklist',
|
|
373
|
+
'createdAt': '11:22 AM',
|
|
374
|
+
},
|
|
375
|
+
],
|
|
376
|
+
};
|
|
377
|
+
return activityLogData;
|
|
378
|
+
} catch ( error ) {
|
|
379
|
+
console.log( 'error =>', error );
|
|
380
|
+
logger.error( { error: error, message: requestData, function: 'activityLogData' } );
|
|
381
|
+
return res.sendError( error, 500 );
|
|
382
|
+
}
|
|
383
|
+
}
|