tango-app-api-task 3.2.1-beta-24 → 3.2.1-beta-26
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/app.js +55 -0
- package/package.json +3 -3
- package/src/controllers/task.controller.js +79 -80
- package/src/service/user.service.js +4 -0
package/app.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import express from 'express';
|
|
4
|
+
import { taskRouter, internalAPIRouter, taskActionCenterRouter, taskDashboardRouter } from './index.js';
|
|
5
|
+
import dotenv from 'dotenv';
|
|
6
|
+
import { logger } from 'tango-app-api-middleware';
|
|
7
|
+
import { connectdb } from './config/database/database.js';
|
|
8
|
+
import responseMiddleware from './config/response/response.js';
|
|
9
|
+
import errorMiddleware from './config/response/response.js';
|
|
10
|
+
import cors from 'cors';
|
|
11
|
+
import pkg from 'body-parser';
|
|
12
|
+
import fileupload from 'express-fileupload';
|
|
13
|
+
|
|
14
|
+
const env=dotenv.config();
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const app = express();
|
|
18
|
+
const { json, urlencoded } = pkg;
|
|
19
|
+
|
|
20
|
+
const PORT = process.env.PORT || 3000;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
if ( env.error ) {
|
|
24
|
+
logger.error( '.env not found' );
|
|
25
|
+
|
|
26
|
+
process.exit( 1 );
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
app.use( fileupload() );
|
|
30
|
+
|
|
31
|
+
app.use( responseMiddleware );
|
|
32
|
+
app.use( errorMiddleware );
|
|
33
|
+
app.use( cors() );
|
|
34
|
+
app.use( responseMiddleware );
|
|
35
|
+
app.use( errorMiddleware );
|
|
36
|
+
app.use( json( { limit: '500mb' } ) );
|
|
37
|
+
app.use(
|
|
38
|
+
urlencoded( {
|
|
39
|
+
extended: true,
|
|
40
|
+
} ),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
app.use( '/task', taskRouter );
|
|
44
|
+
app.use( '/task/internalAPI', internalAPIRouter );
|
|
45
|
+
app.use( '/task/actionCenter', taskActionCenterRouter );
|
|
46
|
+
app.use( '/task/dashboard', taskDashboardRouter );
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
app.listen( PORT, () => {
|
|
50
|
+
console.log( `server is running on port= ${PORT} ` );
|
|
51
|
+
|
|
52
|
+
connectdb();
|
|
53
|
+
} );
|
|
54
|
+
|
|
55
|
+
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-task",
|
|
3
|
-
"version": "3.2.1-beta-
|
|
3
|
+
"version": "3.2.1-beta-26",
|
|
4
4
|
"description": "Task",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "app.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"start": "nodemon --exec \"eslint --fix . && node
|
|
8
|
+
"start": "nodemon --exec \"eslint --fix . && node app.js\""
|
|
9
9
|
},
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=18.10.0"
|
|
@@ -738,6 +738,7 @@ export async function taskConfig( req, res ) {
|
|
|
738
738
|
checkListName: checklistDetails.checkListName,
|
|
739
739
|
checklistId: checklistDetails._id,
|
|
740
740
|
coverage: inputBody.coverage,
|
|
741
|
+
insert: true,
|
|
741
742
|
};
|
|
742
743
|
await assignUsers( data );
|
|
743
744
|
} ) );
|
|
@@ -1142,6 +1143,7 @@ export async function uploadImage( req, res ) {
|
|
|
1142
1143
|
|
|
1143
1144
|
async function createUser( data ) {
|
|
1144
1145
|
try {
|
|
1146
|
+
console.log( 'createUser ====>', data );
|
|
1145
1147
|
let params = {
|
|
1146
1148
|
userName: data.userName,
|
|
1147
1149
|
email: data.email,
|
|
@@ -1224,7 +1226,8 @@ async function createUser( data ) {
|
|
|
1224
1226
|
],
|
|
1225
1227
|
};
|
|
1226
1228
|
let response = await userService.create( params );
|
|
1227
|
-
|
|
1229
|
+
// console.log( 'createUser ====>', response );
|
|
1230
|
+
return response;
|
|
1228
1231
|
} catch ( e ) {
|
|
1229
1232
|
logger.error( 'createUser =>', e );
|
|
1230
1233
|
return false;
|
|
@@ -3354,71 +3357,49 @@ export async function taskAssign( req, res ) {
|
|
|
3354
3357
|
if ( !taskDetails ) {
|
|
3355
3358
|
return res.sendError( 'No data found', 204 );
|
|
3356
3359
|
}
|
|
3357
|
-
let
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3360
|
+
let assignList = [];
|
|
3361
|
+
|
|
3362
|
+
// for ( let data of req.body.idList ) {
|
|
3363
|
+
// let assignedData = {
|
|
3364
|
+
// ...data,
|
|
3365
|
+
// clientId: req.body.clientId,
|
|
3366
|
+
// checkListName: taskDetails.checkListName,
|
|
3367
|
+
// checklistId: taskDetails._id,
|
|
3368
|
+
// coverage: req.body.coverage,
|
|
3369
|
+
// insert: false,
|
|
3370
|
+
// };
|
|
3371
|
+
// // console.log( assignedData, 'daterthj' );
|
|
3372
|
+
// let uploadData = await assignUsers( assignedData );
|
|
3373
|
+
// if ( uploadData ) {
|
|
3374
|
+
// if ( Array.isArray( uploadData ) ) {
|
|
3375
|
+
// assignList.push( ...uploadData );
|
|
3376
|
+
// } else {
|
|
3377
|
+
// assignList.push( uploadData );
|
|
3378
|
+
// }
|
|
3379
|
+
// }
|
|
3380
|
+
// }
|
|
3381
|
+
|
|
3382
|
+
await Promise.all( req.body.idList.map( async ( data ) => {
|
|
3383
|
+
let assignedData = {
|
|
3384
|
+
...data,
|
|
3385
|
+
clientId: req.body.clientId,
|
|
3386
|
+
checkListName: taskDetails.checkListName,
|
|
3387
|
+
checklistId: taskDetails._id,
|
|
3388
|
+
coverage: req.body.coverage,
|
|
3389
|
+
insert: false,
|
|
3390
|
+
};
|
|
3391
|
+
// console.log( assignedData, 'daterthj' );
|
|
3392
|
+
let uploadData = await assignUsers( assignedData );
|
|
3393
|
+
if ( uploadData ) {
|
|
3394
|
+
if ( Array.isArray( uploadData ) ) {
|
|
3395
|
+
assignList.push( ...uploadData );
|
|
3396
|
+
} else {
|
|
3397
|
+
assignList.push( uploadData );
|
|
3384
3398
|
}
|
|
3385
|
-
let data = {
|
|
3386
|
-
store_id: store.storeId,
|
|
3387
|
-
storeName: store.storeName,
|
|
3388
|
-
userId: userDetails._id,
|
|
3389
|
-
userName: userDetails.userName,
|
|
3390
|
-
userEmail: userDetails.email,
|
|
3391
|
-
userPhone: userDetails?.mobileNumber,
|
|
3392
|
-
clusterName: clusterDetails?.clusterName,
|
|
3393
|
-
};
|
|
3394
|
-
return data;
|
|
3395
|
-
} ) );
|
|
3396
|
-
} else {
|
|
3397
|
-
let teamDetails = await teamsServices.findteams( { _id: { $in: req.body.idList } }, { users: 1, teamName: 1 } );
|
|
3398
|
-
if ( teamDetails.length ) {
|
|
3399
|
-
let teamList = teamDetails.map( ( ele ) => ele._id.toString() );
|
|
3400
|
-
idList = [
|
|
3401
|
-
...teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) ),
|
|
3402
|
-
...req.body.idList.filter( ( ele ) => !teamList.includes( ele._id ) ),
|
|
3403
|
-
];
|
|
3404
|
-
} else {
|
|
3405
|
-
idList = req.body.idList;
|
|
3406
|
-
}
|
|
3407
|
-
let userDetails = await userService.find( { _id: { $in: idList } } );
|
|
3408
|
-
if ( !userDetails.length ) {
|
|
3409
|
-
return res.sendError( 'No data found', 204 );
|
|
3410
3399
|
}
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
userId: user._id,
|
|
3415
|
-
userName: user.userName,
|
|
3416
|
-
userEmail: user.email,
|
|
3417
|
-
userPhone: user?.mobileNumber,
|
|
3418
|
-
teamName: teamDetails?.teamName,
|
|
3419
|
-
} );
|
|
3420
|
-
} );
|
|
3421
|
-
}
|
|
3400
|
+
} ) );
|
|
3401
|
+
|
|
3402
|
+
|
|
3422
3403
|
return res.sendSuccess( { count: assignList.length, assignList } );
|
|
3423
3404
|
} catch ( e ) {
|
|
3424
3405
|
logger.error( { functionName: 'checklistAssign', error: e } );
|
|
@@ -3427,6 +3408,7 @@ export async function taskAssign( req, res ) {
|
|
|
3427
3408
|
}
|
|
3428
3409
|
|
|
3429
3410
|
async function assignUsers( data ) {
|
|
3411
|
+
console.log( data );
|
|
3430
3412
|
let assignedData;
|
|
3431
3413
|
if ( data.coverage == 'store' ) {
|
|
3432
3414
|
if ( data?.type == 'cluster' ) {
|
|
@@ -3439,7 +3421,7 @@ async function assignUsers( data ) {
|
|
|
3439
3421
|
{
|
|
3440
3422
|
$match: {
|
|
3441
3423
|
clientId: data.clientId,
|
|
3442
|
-
...( !data?.
|
|
3424
|
+
...( !data?.clusterName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { cluster: data.clusterName.toLowerCase() },
|
|
3443
3425
|
},
|
|
3444
3426
|
},
|
|
3445
3427
|
{
|
|
@@ -3451,7 +3433,7 @@ async function assignUsers( data ) {
|
|
|
3451
3433
|
];
|
|
3452
3434
|
let clusterDetails = await clusterServices.aggregateCluster( query );
|
|
3453
3435
|
if ( clusterDetails.length ) {
|
|
3454
|
-
if (
|
|
3436
|
+
if ( data.insert ) {
|
|
3455
3437
|
assignedData = {
|
|
3456
3438
|
checkFlag: true,
|
|
3457
3439
|
checkListId: data.checklistId,
|
|
@@ -3466,10 +3448,10 @@ async function assignUsers( data ) {
|
|
|
3466
3448
|
let storeDetails = await storeService.find( { _id: { $in: clusterList }, status: 'active' } );
|
|
3467
3449
|
assignedData = await Promise.all( storeDetails.map( async ( store ) => {
|
|
3468
3450
|
let userDetails = await userService.findOne( { email: store.spocDetails?.[0]?.email, clientId: data.clientId } );
|
|
3469
|
-
if ( !userDetails ) {
|
|
3451
|
+
if ( !userDetails && store?.spocDetails?.length ) {
|
|
3470
3452
|
let userData = {
|
|
3471
3453
|
userName: store.spocDetails?.[0]?.name,
|
|
3472
|
-
email: store.spocDetails[0]
|
|
3454
|
+
email: store.spocDetails[0]?.email,
|
|
3473
3455
|
mobileNumber: store.spocDetails?.[0]?.phone,
|
|
3474
3456
|
clientId: data.clientId,
|
|
3475
3457
|
};
|
|
@@ -3486,7 +3468,9 @@ async function assignUsers( data ) {
|
|
|
3486
3468
|
client_id: data.clientId,
|
|
3487
3469
|
assignId: data?.id || clusterDetails?.[0]?._id,
|
|
3488
3470
|
coverage: 'store',
|
|
3489
|
-
|
|
3471
|
+
clusterName: clusterDetails?.[0]?.clusterName,
|
|
3472
|
+
storeId: store.storeId,
|
|
3473
|
+
storeName: store.storeName,
|
|
3490
3474
|
};
|
|
3491
3475
|
return userData;
|
|
3492
3476
|
} ) );
|
|
@@ -3502,13 +3486,13 @@ async function assignUsers( data ) {
|
|
|
3502
3486
|
{
|
|
3503
3487
|
$match: {
|
|
3504
3488
|
clientId: data.clientId,
|
|
3505
|
-
...( !data.
|
|
3489
|
+
...( !data.storeName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
|
|
3506
3490
|
},
|
|
3507
3491
|
},
|
|
3508
3492
|
];
|
|
3509
3493
|
let storeDetails = await storeService.aggregate( query );
|
|
3510
3494
|
if ( storeDetails.length ) {
|
|
3511
|
-
let email = data?.
|
|
3495
|
+
let email = data?.userEmail ? data.userEmail : storeDetails?.[0]?.spocDetails?.[0]?.email;
|
|
3512
3496
|
let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
|
|
3513
3497
|
if ( !userDetails ) {
|
|
3514
3498
|
let userData = {
|
|
@@ -3518,6 +3502,7 @@ async function assignUsers( data ) {
|
|
|
3518
3502
|
clientId: data.clientId,
|
|
3519
3503
|
};
|
|
3520
3504
|
userDetails = await createUser( userData );
|
|
3505
|
+
console.log( 'userDetails =>', userDetails );
|
|
3521
3506
|
}
|
|
3522
3507
|
assignedData = {
|
|
3523
3508
|
store_id: storeDetails?.[0]?.storeId,
|
|
@@ -3548,13 +3533,13 @@ async function assignUsers( data ) {
|
|
|
3548
3533
|
{
|
|
3549
3534
|
$match: {
|
|
3550
3535
|
clientId: data.clientId,
|
|
3551
|
-
...( !data?.
|
|
3536
|
+
...( !data?.teamName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
|
|
3552
3537
|
},
|
|
3553
3538
|
},
|
|
3554
3539
|
];
|
|
3555
3540
|
let teamDetails = await teamsServices.aggregateTeams( query );
|
|
3556
3541
|
if ( teamDetails.length ) {
|
|
3557
|
-
if (
|
|
3542
|
+
if ( data.insert ) {
|
|
3558
3543
|
assignedData = {
|
|
3559
3544
|
checkFlag: true,
|
|
3560
3545
|
checkListId: data.checklistId,
|
|
@@ -3595,17 +3580,19 @@ async function assignUsers( data ) {
|
|
|
3595
3580
|
{
|
|
3596
3581
|
$match: {
|
|
3597
3582
|
clientId: data.clientId,
|
|
3598
|
-
...( !data?.
|
|
3583
|
+
...( !data?.userEmail ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { userEmail: data.userEmail.toLowerCase() },
|
|
3599
3584
|
},
|
|
3600
3585
|
},
|
|
3601
3586
|
];
|
|
3587
|
+
// console.log( 'data?.userEmail=>', data.userEmail );
|
|
3602
3588
|
let userDetails = await userService.aggregate( query );
|
|
3603
3589
|
if ( !userDetails.length ) {
|
|
3604
3590
|
let userData = {
|
|
3605
|
-
userName: data
|
|
3591
|
+
userName: data?.userEmail?.split( '@' )[0],
|
|
3606
3592
|
email: data.userEmail,
|
|
3607
3593
|
clientId: data.clientId,
|
|
3608
3594
|
};
|
|
3595
|
+
// console.log( userData, 'userData', data );
|
|
3609
3596
|
let details = await createUser( userData );
|
|
3610
3597
|
userDetails = [ details ];
|
|
3611
3598
|
}
|
|
@@ -3625,7 +3612,9 @@ async function assignUsers( data ) {
|
|
|
3625
3612
|
}
|
|
3626
3613
|
}
|
|
3627
3614
|
}
|
|
3628
|
-
|
|
3615
|
+
|
|
3616
|
+
// console.log( assignedData, 'test', data );
|
|
3617
|
+
if ( assignedData && !data.upload && data.insert ) {
|
|
3629
3618
|
await taskAssignService.updateOne( { checkListId: assignedData.checkListId, assignId: assignedData.assignId }, assignedData );
|
|
3630
3619
|
} else {
|
|
3631
3620
|
return assignedData;
|
|
@@ -3641,16 +3630,26 @@ export async function assignTaskUser( req, res ) {
|
|
|
3641
3630
|
if ( !taskDetails ) {
|
|
3642
3631
|
return res.sendError( 'No data found', 204 );
|
|
3643
3632
|
}
|
|
3644
|
-
await Promise.all( newUsers.map( async ( user ) => {
|
|
3645
|
-
|
|
3633
|
+
// await Promise.all( newUsers.map( async ( user ) => {
|
|
3634
|
+
// let getUser = inputBody.assignUsers.find( ( ele ) => ele.userEmail.toLowerCase() == user.toLowerCase() );
|
|
3635
|
+
// let userData = {
|
|
3636
|
+
// userName: getUser.userName,
|
|
3637
|
+
// email: user,
|
|
3638
|
+
// mobileNumber: getUser?.phone,
|
|
3639
|
+
// clientId: inputBody.clientId,
|
|
3640
|
+
// };
|
|
3641
|
+
// await createUser( userData );
|
|
3642
|
+
// } ) );
|
|
3643
|
+
for ( let i = 0; i < newUsers.length; i++ ) {
|
|
3644
|
+
let getUser = inputBody.assignUsers.find( ( ele ) => ele.userEmail.toLowerCase() == newUsers[i].toLowerCase() );
|
|
3646
3645
|
let userData = {
|
|
3647
3646
|
userName: getUser.userName,
|
|
3648
|
-
email:
|
|
3647
|
+
email: newUsers[i],
|
|
3649
3648
|
mobileNumber: getUser?.phone,
|
|
3650
3649
|
clientId: inputBody.clientId,
|
|
3651
3650
|
};
|
|
3652
3651
|
await createUser( userData );
|
|
3653
|
-
}
|
|
3652
|
+
}
|
|
3654
3653
|
let assignData = [];
|
|
3655
3654
|
await Promise.all( assignDetails.map( async ( assign ) => {
|
|
3656
3655
|
assign.checklistId = inputBody.taskId;
|
|
@@ -20,6 +20,10 @@ export const updateOne = async ( query = {}, record={} ) => {
|
|
|
20
20
|
return model.userModel.updateOne( query, { $set: record } );
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
export const upsert = async ( query = {}, record={} ) => {
|
|
24
|
+
return model.userModel.updateOne( query, { $set: record }, { upsert: true } );
|
|
25
|
+
};
|
|
26
|
+
|
|
23
27
|
export const aggregate = async ( query = {} ) => {
|
|
24
28
|
return model.userModel.aggregate( query );
|
|
25
29
|
};
|