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,747 @@
|
|
|
1
|
+
import * as taskService from '../service/task.service.js';
|
|
2
|
+
import * as processedTaskService from '../service/processedTaskList.service.js';
|
|
3
|
+
import { logger } from 'tango-app-api-middleware';
|
|
4
|
+
import dayjs from 'dayjs';
|
|
5
|
+
import mongoose from 'mongoose';
|
|
6
|
+
// const ObjectId = mongoose.Types.ObjectId;
|
|
7
|
+
|
|
8
|
+
export const overallCards = async ( req, res ) => {
|
|
9
|
+
try {
|
|
10
|
+
let requestData = req.body;
|
|
11
|
+
let resultData = await overallCardsData( requestData );
|
|
12
|
+
return res.sendSuccess( resultData );
|
|
13
|
+
} catch ( error ) {
|
|
14
|
+
console.log( 'error =>', error );
|
|
15
|
+
logger.error( { error: error, function: 'overallCards' } );
|
|
16
|
+
return res.sendError( error, 500 );
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
async function overallCardsData( requestData ) {
|
|
20
|
+
try {
|
|
21
|
+
// let resultData = {};
|
|
22
|
+
let cardData = {
|
|
23
|
+
'TotalTasks': {
|
|
24
|
+
'count': 700,
|
|
25
|
+
},
|
|
26
|
+
'open': {
|
|
27
|
+
'count': 40,
|
|
28
|
+
},
|
|
29
|
+
'inprogress': {
|
|
30
|
+
'count': 70,
|
|
31
|
+
},
|
|
32
|
+
'reopen': {
|
|
33
|
+
'count': 70,
|
|
34
|
+
},
|
|
35
|
+
'submitted': {
|
|
36
|
+
'count': 70,
|
|
37
|
+
},
|
|
38
|
+
'closed': {
|
|
39
|
+
'count': 70,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
// resultData.card = cardData;
|
|
43
|
+
return { cardData: cardData };
|
|
44
|
+
} catch ( error ) {
|
|
45
|
+
console.log( 'error =>', error );
|
|
46
|
+
logger.error( { error: error, message: data, function: 'overallCardsData' } );
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export const overallCardsV1 = async ( req, res ) => {
|
|
50
|
+
try {
|
|
51
|
+
let requestData = req.body;
|
|
52
|
+
let fromDate = new Date( requestData.fromDate );
|
|
53
|
+
let toDate = new Date( requestData.toDate );
|
|
54
|
+
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
55
|
+
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
56
|
+
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
57
|
+
let findQuery = [];
|
|
58
|
+
let findAndQuery = [];
|
|
59
|
+
|
|
60
|
+
findAndQuery.push(
|
|
61
|
+
{ checkListType: { $eq: 'task' } },
|
|
62
|
+
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
63
|
+
{ client_id: requestData.clientId },
|
|
64
|
+
{ store_id: { $in: requestData.storeId } },
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
68
|
+
findQuery.push( {
|
|
69
|
+
$group: {
|
|
70
|
+
_id: '$checklistStatus',
|
|
71
|
+
count: { $sum: 1 },
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
$group: {
|
|
76
|
+
_id: null,
|
|
77
|
+
TotalTasks: { $sum: '$count' },
|
|
78
|
+
open: { $sum: { $cond: [ { $eq: [ '$_id', 'open' ] }, '$count', 0 ] } },
|
|
79
|
+
inprogress: { $sum: { $cond: [ { $eq: [ '$_id', 'inprogress' ] }, '$count', 0 ] } },
|
|
80
|
+
reopen: { $sum: { $cond: [ { $eq: [ '$_id', 'reopen' ] }, '$count', 0 ] } },
|
|
81
|
+
submitted: { $sum: { $cond: [ { $eq: [ '$_id', 'submit' ] }, '$count', 0 ] } },
|
|
82
|
+
closed: { $sum: { $cond: [ { $eq: [ '$_id', 'closed' ] }, '$count', 0 ] } },
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
$project: {
|
|
87
|
+
_id: 0,
|
|
88
|
+
TotalTasks: { count: '$TotalTasks' },
|
|
89
|
+
open: { count: '$open' },
|
|
90
|
+
inprogress: { count: '$inprogress' },
|
|
91
|
+
reopen: { count: '$reopen' },
|
|
92
|
+
submitted: { count: '$submitted' },
|
|
93
|
+
closed: { count: '$closed' },
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
let resultData = await processedTaskService.aggregate( findQuery );
|
|
98
|
+
return res.sendSuccess( { cardData: resultData } );
|
|
99
|
+
} catch ( error ) {
|
|
100
|
+
logger.error( { error: error, message: req.query, function: 'overallCards' } );
|
|
101
|
+
return res.sendError( { error: error }, 500 );
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
export const taskTableV1 = async ( req, res ) => {
|
|
105
|
+
try {
|
|
106
|
+
console.log( 'req.body', req.body );
|
|
107
|
+
let limit = parseInt( req.body.limit ) || 10;
|
|
108
|
+
let offset = parseInt( req.body.offset - 1 ) || 0;
|
|
109
|
+
let page = offset * limit;
|
|
110
|
+
let query = [];
|
|
111
|
+
|
|
112
|
+
query.push(
|
|
113
|
+
{
|
|
114
|
+
$match: {
|
|
115
|
+
checkListType: 'task',
|
|
116
|
+
client_id: req.body.clientId,
|
|
117
|
+
isdeleted: false,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
if ( req.body.searchValue && req.body.searchValue != '' ) {
|
|
123
|
+
req.body.searchValue = req.body.searchValue.replace( /([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1' );
|
|
124
|
+
query.push( {
|
|
125
|
+
$match: {
|
|
126
|
+
checkListName: { $regex: new RegExp( req.body.searchValue, 'i' ) },
|
|
127
|
+
},
|
|
128
|
+
} );
|
|
129
|
+
}
|
|
130
|
+
if ( req.body.priorityType && req.body.priorityType != '' ) {
|
|
131
|
+
query.push( {
|
|
132
|
+
$match: {
|
|
133
|
+
priorityType: { $in: req.body.priorityType },
|
|
134
|
+
},
|
|
135
|
+
} );
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
query.push(
|
|
139
|
+
{
|
|
140
|
+
$project: {
|
|
141
|
+
checkList: { $toLower: '$checkListName' },
|
|
142
|
+
checkListName: 1,
|
|
143
|
+
storeCount: 1,
|
|
144
|
+
createdBy: 1,
|
|
145
|
+
createdBySort: { $toLower: '$createdByName' },
|
|
146
|
+
createdByName: 1,
|
|
147
|
+
createdAt: 1,
|
|
148
|
+
publish: 1,
|
|
149
|
+
checkListType: 1,
|
|
150
|
+
questionCount: 1,
|
|
151
|
+
checkListChar: { $substr: [ '$createdByName', 0, 2 ] },
|
|
152
|
+
priorityType: 1,
|
|
153
|
+
scheduleDate: 1,
|
|
154
|
+
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
if ( req.body.sortColumnName && req.body.sortColumnName != '' && req.body.sortBy != '' ) {
|
|
160
|
+
if ( req.body.sortColumnName == 'createdByName' ) {
|
|
161
|
+
req.body.sortColumnName = 'createdBySort';
|
|
162
|
+
}
|
|
163
|
+
if ( req.body.sortColumnName == 'status' ) {
|
|
164
|
+
req.body.sortColumnName = 'publish';
|
|
165
|
+
}
|
|
166
|
+
if ( req.body.sortColumnName != 'publish' ) {
|
|
167
|
+
query.push( {
|
|
168
|
+
$addFields: { lowerName: { $toLower: `$${req.body.sortColumnName}` } },
|
|
169
|
+
} );
|
|
170
|
+
query.push( {
|
|
171
|
+
$sort: { lowerName: parseInt( req.body.sortBy ) },
|
|
172
|
+
} );
|
|
173
|
+
} else {
|
|
174
|
+
query.push( {
|
|
175
|
+
$sort: { publish: parseInt( req.body.sortBy ) },
|
|
176
|
+
} );
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
query.push(
|
|
180
|
+
{ $sort: { createdAt: -1 } },
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
console.log( 'page', page );
|
|
184
|
+
query.push( {
|
|
185
|
+
$facet: {
|
|
186
|
+
data: [
|
|
187
|
+
{ $skip: page },
|
|
188
|
+
{ $limit: limit },
|
|
189
|
+
],
|
|
190
|
+
count: [
|
|
191
|
+
{ $count: 'totalCount' },
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
} );
|
|
195
|
+
|
|
196
|
+
let checkList = await taskService.aggregate( query );
|
|
197
|
+
|
|
198
|
+
if ( !checkList[0].data.length ) {
|
|
199
|
+
return res.sendError( 'no data found', 204 );
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
checkList[0].data.forEach( ( item ) => {
|
|
203
|
+
if ( item.storeCount > 0 && item.storeCount <= 9 ) {
|
|
204
|
+
item.storeCount = '0' + item.storeCount;
|
|
205
|
+
}
|
|
206
|
+
if ( item.questionCount > 0 && item.questionCount <= 9 ) {
|
|
207
|
+
item.questionCount = '0' + item.questionCount;
|
|
208
|
+
}
|
|
209
|
+
item.scheduleDate = dayjs( item.scheduleDate ).format( 'DD MMM, YYYY' );
|
|
210
|
+
} );
|
|
211
|
+
|
|
212
|
+
return res.sendSuccess( { taskTableData: checkList[0].data, totalCount: checkList[0].count[0].totalCount } );
|
|
213
|
+
} catch ( e ) {
|
|
214
|
+
console.log( 'e', e );
|
|
215
|
+
logger.error( 'checklist =>', e );
|
|
216
|
+
return res.sendError( e, 500 );
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
export const taskInfoTableV1 = async ( req, res ) => {
|
|
220
|
+
try {
|
|
221
|
+
let requestData = req.body;
|
|
222
|
+
let fromDate = new Date( requestData.fromDate );
|
|
223
|
+
let toDate = new Date( requestData.toDate );
|
|
224
|
+
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
225
|
+
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
226
|
+
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
227
|
+
let result = {};
|
|
228
|
+
|
|
229
|
+
let findQuery = [];
|
|
230
|
+
let findAndQuery = [];
|
|
231
|
+
|
|
232
|
+
findAndQuery.push(
|
|
233
|
+
{ client_id: requestData.clientId },
|
|
234
|
+
{ store_id: { $in: requestData.storeId } },
|
|
235
|
+
{ date_iso: { $gte: fromDate } },
|
|
236
|
+
{ date_iso: { $lte: toDate } },
|
|
237
|
+
{ checkListType: { $eq: 'task' } },
|
|
238
|
+
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.taskId ) },
|
|
239
|
+
);
|
|
240
|
+
if ( requestData.checklistStatus && requestData.checklistStatus != 'All' ) {
|
|
241
|
+
findAndQuery.push( { checklistStatus: requestData.checklistStatus } );
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
245
|
+
|
|
246
|
+
if ( requestData.searchValue && requestData.searchValue != '' ) {
|
|
247
|
+
let storeList = requestData.searchValue.split( ',' ).map( ( item ) => item.trim().toLowerCase() );
|
|
248
|
+
let query;
|
|
249
|
+
if ( storeList.length > 1 ) {
|
|
250
|
+
findQuery.push( { $addFields: { store: { $toLower: '$storeName' } } } );
|
|
251
|
+
query = { store: { $in: storeList } };
|
|
252
|
+
} else {
|
|
253
|
+
query = { storeName: { $regex: requestData.searchValue.trim(), $options: 'i' } };
|
|
254
|
+
}
|
|
255
|
+
findQuery.push( { $match: { $or: [ query ] } } );
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
findQuery.push( {
|
|
259
|
+
$project: {
|
|
260
|
+
checkListName: 1,
|
|
261
|
+
createdByName: 1,
|
|
262
|
+
userName: 1,
|
|
263
|
+
userEmail: 1,
|
|
264
|
+
checklistStatus: 1,
|
|
265
|
+
submitTime_string: 1,
|
|
266
|
+
storeName: 1,
|
|
267
|
+
checkListType: 1,
|
|
268
|
+
scheduleRepeatedType: 1,
|
|
269
|
+
date_iso: 1,
|
|
270
|
+
store_id: 1,
|
|
271
|
+
timeFlag: 1,
|
|
272
|
+
date_string: 1,
|
|
273
|
+
sourceCheckList_id: 1,
|
|
274
|
+
reinitiateStatus: 1,
|
|
275
|
+
scheduleEndTime_iso: 1,
|
|
276
|
+
|
|
277
|
+
},
|
|
278
|
+
} );
|
|
279
|
+
|
|
280
|
+
findQuery.push( {
|
|
281
|
+
$project: {
|
|
282
|
+
checkListName: 1,
|
|
283
|
+
checkListChar: { $substr: [ '$checkListName', 0, 2 ] },
|
|
284
|
+
createdByName: 1,
|
|
285
|
+
userName: 1,
|
|
286
|
+
userEmail: 1,
|
|
287
|
+
checklistStatus: {
|
|
288
|
+
$cond: {
|
|
289
|
+
if: { $eq: [ '$checklistStatus', 'submit' ] },
|
|
290
|
+
then: 'Submitted',
|
|
291
|
+
else: {
|
|
292
|
+
$cond: {
|
|
293
|
+
if: { $eq: [ '$checklistStatus', 'open' ] },
|
|
294
|
+
then: 'Open',
|
|
295
|
+
else: 'In Progress',
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
submitTime_string: {
|
|
301
|
+
$cond: {
|
|
302
|
+
if: { $eq: [ '$checklistStatus', 'submit' ] },
|
|
303
|
+
then: '$submitTime_string',
|
|
304
|
+
else: '',
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
storeName: 1,
|
|
308
|
+
checkListType: 1,
|
|
309
|
+
date_iso: 1,
|
|
310
|
+
store_id: 1,
|
|
311
|
+
date_string: 1,
|
|
312
|
+
checklistDate: '$date_string',
|
|
313
|
+
sourceCheckList_id: 1,
|
|
314
|
+
scheduleEndTime_iso: 1,
|
|
315
|
+
},
|
|
316
|
+
} );
|
|
317
|
+
|
|
318
|
+
let getTotalCount = await processedTaskService.aggregate( findQuery );
|
|
319
|
+
console.log( 'getTotalCount', getTotalCount );
|
|
320
|
+
if ( !getTotalCount.length ) {
|
|
321
|
+
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
325
|
+
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
326
|
+
} else {
|
|
327
|
+
findQuery.push( { $sort: { ['date_iso']: -1 } } );
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
let limit = parseInt( requestData?.limit ) || 10;
|
|
331
|
+
let skip = limit * ( requestData?.offset -1 ) || 0;
|
|
332
|
+
findQuery.push( { $skip: skip }, { $limit: limit } );
|
|
333
|
+
let taskInfoData = await processedTaskService.aggregate( findQuery );
|
|
334
|
+
|
|
335
|
+
result.totalCount = getTotalCount.length;
|
|
336
|
+
for ( let i = 0; i < taskInfoData.length; i++ ) {
|
|
337
|
+
taskInfoData[i].scheduleEndTime_iso = dayjs( taskInfoData[i].scheduleEndTime_iso ).format( 'DD MMM YYYY' );
|
|
338
|
+
}
|
|
339
|
+
result.taskInfo = taskInfoData;
|
|
340
|
+
return res.sendSuccess( result );
|
|
341
|
+
} catch ( error ) {
|
|
342
|
+
console.log( 'error =>', error );
|
|
343
|
+
logger.error( { error: error, message: req.query, function: 'taskInfo' } );
|
|
344
|
+
return res.sendError( { error: error }, 500 );
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
export const taskTable = async ( req, res ) => {
|
|
349
|
+
try {
|
|
350
|
+
let requestData = req.body;
|
|
351
|
+
let resultData = await taskTableData( requestData );
|
|
352
|
+
return res.sendSuccess( resultData );
|
|
353
|
+
} catch ( error ) {
|
|
354
|
+
console.log( 'error =>', error );
|
|
355
|
+
logger.error( { error: error, function: 'taskTable' } );
|
|
356
|
+
return res.sendError( error, 500 );
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
async function taskTableData( requestData ) {
|
|
360
|
+
try {
|
|
361
|
+
let tableData = {
|
|
362
|
+
'totalCount': 50,
|
|
363
|
+
'taskTableData': [
|
|
364
|
+
{
|
|
365
|
+
'taskName': 'Hustlr Tray1',
|
|
366
|
+
'assignedTo': '12',
|
|
367
|
+
'Priority': 'High',
|
|
368
|
+
'createdByChar': 'OR',
|
|
369
|
+
'createdBy': 'Orivia Rhye',
|
|
370
|
+
'dueOn': '02 Aug,2024',
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
'taskName': 'Hustlr2',
|
|
374
|
+
'assignedTo': '14',
|
|
375
|
+
'Priority': 'Medium',
|
|
376
|
+
'createdByChar': 'DE',
|
|
377
|
+
'createdBy': 'Devia Rhye',
|
|
378
|
+
'dueOn': '02 Aug,2024',
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
'taskName': 'Hustlr Tray3',
|
|
382
|
+
'assignedTo': '11',
|
|
383
|
+
'Priority': 'Low',
|
|
384
|
+
'createdByChar': 'OR',
|
|
385
|
+
'createdBy': 'Olivia Rhye',
|
|
386
|
+
'dueOn': '02 Aug,2024',
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
'taskName': 'Hustlr Tray4',
|
|
390
|
+
'assignedTo': '12',
|
|
391
|
+
'Priority': 'High',
|
|
392
|
+
'createdByChar': 'OR',
|
|
393
|
+
'createdBy': 'Olivia Rhye',
|
|
394
|
+
'dueOn': '02 Aug,2024',
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
'taskName': 'Hustlr Tray5',
|
|
398
|
+
'assignedTo': '12',
|
|
399
|
+
'Priority': 'High',
|
|
400
|
+
'createdByChar': 'OR',
|
|
401
|
+
'createdBy': 'Olivia Rhye',
|
|
402
|
+
'dueOn': '02 Aug,2024',
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
'taskName': 'Hustlr Tray6',
|
|
406
|
+
'assignedTo': '12',
|
|
407
|
+
'Priority': 'High',
|
|
408
|
+
'createdByChar': 'OR',
|
|
409
|
+
'createdBy': 'Olivia Rhye',
|
|
410
|
+
'dueOn': '02 Aug,2024',
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
'taskName': 'Hustlr Tray7',
|
|
414
|
+
'assignedTo': '12',
|
|
415
|
+
'Priority': 'High',
|
|
416
|
+
'createdByChar': 'OR',
|
|
417
|
+
'createdBy': 'Olivia Rhye',
|
|
418
|
+
'dueOn': '02 Aug,2024',
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
'taskName': 'Hustlr Tray8',
|
|
422
|
+
'assignedTo': '12',
|
|
423
|
+
'Priority': 'High',
|
|
424
|
+
'createdByChar': 'OR',
|
|
425
|
+
'createdBy': 'Olivia Rhye',
|
|
426
|
+
'dueOn': '02 Aug,2024',
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
'taskName': 'Hustlr Tray9',
|
|
430
|
+
'assignedTo': '12',
|
|
431
|
+
'Priority': 'High',
|
|
432
|
+
'createdByChar': 'OR',
|
|
433
|
+
'createdBy': 'Olivia Rhye',
|
|
434
|
+
'dueOn': '02 Aug,2024',
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
'taskName': 'Hustlr Tray10',
|
|
438
|
+
'assignedTo': '12',
|
|
439
|
+
'Priority': 'High',
|
|
440
|
+
'createdByChar': 'OR',
|
|
441
|
+
'createdBy': 'Olivia Rhye',
|
|
442
|
+
'dueOn': '02 Aug,2024',
|
|
443
|
+
},
|
|
444
|
+
],
|
|
445
|
+
};
|
|
446
|
+
return tableData;
|
|
447
|
+
} catch ( error ) {
|
|
448
|
+
console.log( 'error =>', error );
|
|
449
|
+
logger.error( { error: error, message: requestData, function: 'taskTableData' } );
|
|
450
|
+
return res.sendError( error, 500 );
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export const taskInfoTable = async ( req, res ) => {
|
|
455
|
+
try {
|
|
456
|
+
let requestData = req.body;
|
|
457
|
+
let resultData = await taskInfoTableData( requestData );
|
|
458
|
+
return res.sendSuccess( resultData );
|
|
459
|
+
} catch ( error ) {
|
|
460
|
+
console.log( 'error =>', error );
|
|
461
|
+
logger.error( { error: error, function: 'taskInfoTable' } );
|
|
462
|
+
return res.sendError( error, 500 );
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
async function taskInfoTableData( requestData ) {
|
|
466
|
+
try {
|
|
467
|
+
let tableInfoData = {
|
|
468
|
+
'totalCount': 50,
|
|
469
|
+
'TaskInfoTableData': [
|
|
470
|
+
{
|
|
471
|
+
'Store': 'LKST123',
|
|
472
|
+
'storeSpoc': 'olivia@tango.co.in',
|
|
473
|
+
'dueOn': '02 Aug,2024',
|
|
474
|
+
'submittedOn': '02 Aug,2024',
|
|
475
|
+
'_id': '1234453525412',
|
|
476
|
+
'taskName': 'Hustlr Tray1',
|
|
477
|
+
'sorceTaskId': '4862896912912',
|
|
478
|
+
'status': 'open', // "closed or submitted or inProgress"
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
'Store': 'LKST124',
|
|
482
|
+
'storeSpoc': 'olivia@tango.co.in',
|
|
483
|
+
'dueOn': '02 Aug,2024',
|
|
484
|
+
'submittedOn': '02 Aug,2024',
|
|
485
|
+
'_id': '1234453525413',
|
|
486
|
+
'taskName': 'Hustlr Tray2',
|
|
487
|
+
'sorceTaskId': '4862896912913',
|
|
488
|
+
'status': 'inprogress', // "closed or submitted or inProgress"
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
'Store': 'LKST125',
|
|
492
|
+
'storeSpoc': 'olivia@tango.co.in',
|
|
493
|
+
'dueOn': '02 Aug,2024',
|
|
494
|
+
'submittedOn': '02 Aug,2024',
|
|
495
|
+
'_id': '1234453525414',
|
|
496
|
+
'taskName': 'Hustlr Tray3',
|
|
497
|
+
'sorceTaskId': '4862896912914',
|
|
498
|
+
'status': 'closed', // "closed or submitted or inProgress"
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
'Store': 'LKST126',
|
|
502
|
+
'storeSpoc': 'olivia@tango.co.in',
|
|
503
|
+
'dueOn': '02 Aug,2024',
|
|
504
|
+
'submittedOn': '02 Aug,2024',
|
|
505
|
+
'_id': '1234453525414',
|
|
506
|
+
'taskName': 'Hustlr Tray3',
|
|
507
|
+
'sorceTaskId': '4862896912914',
|
|
508
|
+
'status': 'closed', // "closed or submitted or inProgress"
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
'Store': 'LKST127',
|
|
512
|
+
'storeSpoc': 'olivia@tango.co.in',
|
|
513
|
+
'dueOn': '02 Aug,2024',
|
|
514
|
+
'submittedOn': '02 Aug,2024',
|
|
515
|
+
'_id': '1234453525414',
|
|
516
|
+
'taskName': 'Hustlr Tray3',
|
|
517
|
+
'sorceTaskId': '4862896912914',
|
|
518
|
+
'status': 'closed', // "closed or submitted or inProgress"
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
'Store': 'LKST128',
|
|
522
|
+
'storeSpoc': 'olivia@tango.co.in',
|
|
523
|
+
'dueOn': '02 Aug,2024',
|
|
524
|
+
'submittedOn': '02 Aug,2024',
|
|
525
|
+
'_id': '1234453525414',
|
|
526
|
+
'taskName': 'Hustlr Tray3',
|
|
527
|
+
'sorceTaskId': '4862896912914',
|
|
528
|
+
'status': 'closed', // "closed or submitted or inProgress"
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
'Store': 'LKST124',
|
|
532
|
+
'storeSpoc': 'olivia@tango.co.in',
|
|
533
|
+
'dueOn': '02 Aug,2024',
|
|
534
|
+
'submittedOn': '02 Aug,2024',
|
|
535
|
+
'_id': '1234453525414',
|
|
536
|
+
'taskName': 'Hustlr Tray3',
|
|
537
|
+
'sorceTaskId': '4862896912914',
|
|
538
|
+
'status': 'closed', // "closed or submitted or inProgress"
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
'Store': 'LKST124',
|
|
542
|
+
'storeSpoc': 'olivia@tango.co.in',
|
|
543
|
+
'dueOn': '02 Aug,2024',
|
|
544
|
+
'submittedOn': '02 Aug,2024',
|
|
545
|
+
'_id': '1234453525414',
|
|
546
|
+
'taskName': 'Hustlr Tray3',
|
|
547
|
+
'sorceTaskId': '4862896912914',
|
|
548
|
+
'status': 'closed', // "closed or submitted or inProgress"
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
'Store': 'LKST124',
|
|
552
|
+
'storeSpoc': 'olivia@tango.co.in',
|
|
553
|
+
'dueOn': '02 Aug,2024',
|
|
554
|
+
'submittedOn': '02 Aug,2024',
|
|
555
|
+
'_id': '1234453525414',
|
|
556
|
+
'taskName': 'Hustlr Tray3',
|
|
557
|
+
'sorceTaskId': '4862896912914',
|
|
558
|
+
'status': 'closed', // "closed or submitted or inProgress"
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
'Store': 'LKST124',
|
|
562
|
+
'storeSpoc': 'olivia@tango.co.in',
|
|
563
|
+
'dueOn': '02 Aug,2024',
|
|
564
|
+
'submittedOn': '02 Aug,2024',
|
|
565
|
+
'_id': '1234453525414',
|
|
566
|
+
'taskName': 'Hustlr Tray3',
|
|
567
|
+
'sorceTaskId': '4862896912914',
|
|
568
|
+
'status': 'closed', // "closed or submitted or inProgress"
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
'Store': 'LKST124',
|
|
572
|
+
'storeSpoc': 'olivia@tango.co.in',
|
|
573
|
+
'dueOn': '02 Aug,2024',
|
|
574
|
+
'submittedOn': '02 Aug,2024',
|
|
575
|
+
'_id': '1234453525414',
|
|
576
|
+
'taskName': 'Hustlr Tray3',
|
|
577
|
+
'sorceTaskId': '4862896912914',
|
|
578
|
+
'status': 'closed', // "closed or submitted or inProgress"
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
'Store': 'LKST124',
|
|
582
|
+
'storeSpoc': 'olivia@tango.co.in',
|
|
583
|
+
'dueOn': '02 Aug,2024',
|
|
584
|
+
'submittedOn': '02 Aug,2024',
|
|
585
|
+
'_id': '1234453525414',
|
|
586
|
+
'taskName': 'Hustlr Tray3',
|
|
587
|
+
'sorceTaskId': '4862896912914',
|
|
588
|
+
'status': 'closed', // "closed or submitted or inProgress"
|
|
589
|
+
},
|
|
590
|
+
],
|
|
591
|
+
};
|
|
592
|
+
return tableInfoData;
|
|
593
|
+
} catch ( error ) {
|
|
594
|
+
console.log( 'error =>', error );
|
|
595
|
+
logger.error( { error: error, message: requestData, function: 'tableInfoData' } );
|
|
596
|
+
return res.sendError( error, 500 );
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
export const taskDropdownList = async ( req, res ) => {
|
|
600
|
+
try {
|
|
601
|
+
let requestData = req.body;
|
|
602
|
+
let resultData = await taskDropdownListData( requestData );
|
|
603
|
+
return res.sendSuccess( resultData );
|
|
604
|
+
} catch ( error ) {
|
|
605
|
+
console.log( 'error =>', error );
|
|
606
|
+
logger.error( { error: error, function: 'taskDropdownList' } );
|
|
607
|
+
return res.sendError( error, 500 );
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
async function taskDropdownListData( requestData ) {
|
|
611
|
+
try {
|
|
612
|
+
let taskDropdownListData = {
|
|
613
|
+
'taskDropdownListData': [
|
|
614
|
+
{
|
|
615
|
+
'_id': '1234453525412',
|
|
616
|
+
'sorceTaskId': '4862896912912',
|
|
617
|
+
'taskName': 'Hustlr Tray1',
|
|
618
|
+
'createdby': 'Olivia Rhye',
|
|
619
|
+
'noOfStores': '100',
|
|
620
|
+
'dueOn': '02 Aug,2024',
|
|
621
|
+
},
|
|
622
|
+
{
|
|
623
|
+
'_id': '1234453525413',
|
|
624
|
+
'sorceTaskId': '4862896912913',
|
|
625
|
+
'taskName': 'Hustlr Tray2',
|
|
626
|
+
'createdby': 'Olivia Rhye',
|
|
627
|
+
'noOfStores': '100',
|
|
628
|
+
'dueOn': '02 Aug,2024',
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
'_id': '1234453525414',
|
|
632
|
+
'sorceTaskId': '4862896912914',
|
|
633
|
+
'taskName': 'Hustlr Tray3',
|
|
634
|
+
'createdby': 'Olivia Rhye',
|
|
635
|
+
'noOfStores': '100',
|
|
636
|
+
'dueOn': '02 Aug,2024',
|
|
637
|
+
},
|
|
638
|
+
{
|
|
639
|
+
'_id': '1234453525414',
|
|
640
|
+
'sorceTaskId': '4862896912914',
|
|
641
|
+
'taskName': 'Hustlr Tray4',
|
|
642
|
+
'createdby': 'Olivia Rhye',
|
|
643
|
+
'noOfStores': '100',
|
|
644
|
+
'dueOn': '02 Aug,2024',
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
'_id': '1234453525414',
|
|
648
|
+
'sorceTaskId': '4862896912914',
|
|
649
|
+
'taskName': 'Hustlr Tray5',
|
|
650
|
+
'createdby': 'Olivia Rhye',
|
|
651
|
+
'noOfStores': '100',
|
|
652
|
+
'dueOn': '02 Aug,2024',
|
|
653
|
+
},
|
|
654
|
+
],
|
|
655
|
+
};
|
|
656
|
+
return taskDropdownListData;
|
|
657
|
+
} catch ( error ) {
|
|
658
|
+
console.log( 'error =>', error );
|
|
659
|
+
logger.error( { error: error, message: requestData, function: 'taskDropdownListData' } );
|
|
660
|
+
return res.sendError( error, 500 );
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
export const taskDropdownListV1 = async ( req, res ) => {
|
|
664
|
+
try {
|
|
665
|
+
let requestData = req.body;
|
|
666
|
+
let result = {};
|
|
667
|
+
let findQuery = [];
|
|
668
|
+
let findAndQuery = [];
|
|
669
|
+
findAndQuery.push(
|
|
670
|
+
{ client_id: requestData.clientId },
|
|
671
|
+
{ checkListType: 'task' },
|
|
672
|
+
);
|
|
673
|
+
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
674
|
+
findQuery.push( {
|
|
675
|
+
$project: {
|
|
676
|
+
sourceCheckList_id: '$_id',
|
|
677
|
+
checkListName: 1,
|
|
678
|
+
checkListNameLowercase: { $toLower: '$checkListName' },
|
|
679
|
+
checkListType: 1,
|
|
680
|
+
createdByName: 1,
|
|
681
|
+
storeCount: 1,
|
|
682
|
+
scheduleEndTimeISO: 1,
|
|
683
|
+
},
|
|
684
|
+
} );
|
|
685
|
+
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
686
|
+
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
687
|
+
} else {
|
|
688
|
+
findQuery.push( { $sort: { ['checkListNameLowercase']: 1 } } );
|
|
689
|
+
}
|
|
690
|
+
let getChecklistData = await taskService.aggregate( findQuery );
|
|
691
|
+
if ( !getChecklistData.length ) {
|
|
692
|
+
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
693
|
+
}
|
|
694
|
+
for ( let i = 0; i < getChecklistData.length; i++ ) {
|
|
695
|
+
getChecklistData[i].scheduleEndTime_iso = dayjs( getChecklistData[i].scheduleEndTime_iso ).format( 'DD MMM YYYY' );
|
|
696
|
+
}
|
|
697
|
+
result.totalCount = getChecklistData.length;
|
|
698
|
+
result.taskDropdown = getChecklistData;
|
|
699
|
+
return res.sendSuccess( result );
|
|
700
|
+
} catch ( error ) {
|
|
701
|
+
console.log( 'error =>', error );
|
|
702
|
+
logger.error( { error: error, message: req.query, function: 'checklistDropdown' } );
|
|
703
|
+
return res.sendError( { error: error }, 500 );
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
export const taskInfoView = async ( req, res ) => {
|
|
707
|
+
try {
|
|
708
|
+
let requestData = req.body;
|
|
709
|
+
let resultData = await taskInfoViewData( requestData );
|
|
710
|
+
return res.sendSuccess( resultData );
|
|
711
|
+
} catch ( error ) {
|
|
712
|
+
console.log( 'error =>', error );
|
|
713
|
+
logger.error( { error: error, function: 'taskInfoView' } );
|
|
714
|
+
return res.sendError( error, 500 );
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
async function taskInfoViewData( requestData ) {
|
|
718
|
+
try {
|
|
719
|
+
let taskInfoViewData = {
|
|
720
|
+
'TaskInfoViewData':
|
|
721
|
+
{
|
|
722
|
+
'taskTitle :': 'Daily Task',
|
|
723
|
+
'description :': 'test123',
|
|
724
|
+
'storeName': 'LKST123',
|
|
725
|
+
'dueDate': '02 Aug,2024',
|
|
726
|
+
'dueTime': '03:04',
|
|
727
|
+
'_id': '1234453525412',
|
|
728
|
+
'taskName': 'Hustlr Tray',
|
|
729
|
+
'sorceTaskId': '4862896912912',
|
|
730
|
+
'approver': [
|
|
731
|
+
{
|
|
732
|
+
'name': 'Olivia Rhye',
|
|
733
|
+
'email': 'OliviaRhye@yopmail.com',
|
|
734
|
+
},
|
|
735
|
+
],
|
|
736
|
+
'priority': 'High', // "Low or Medium" ,
|
|
737
|
+
'geoFacing': true,
|
|
738
|
+
'attendance': false,
|
|
739
|
+
},
|
|
740
|
+
};
|
|
741
|
+
return taskInfoViewData;
|
|
742
|
+
} catch ( error ) {
|
|
743
|
+
console.log( 'error =>', error );
|
|
744
|
+
logger.error( { error: error, message: requestData, function: 'taskInfoViewData' } );
|
|
745
|
+
return res.sendError( error, 500 );
|
|
746
|
+
}
|
|
747
|
+
}
|