tango-app-api-task 3.7.25 → 3.7.27
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": "3.7.
|
|
3
|
+
"version": "3.7.27",
|
|
4
4
|
"description": "Task",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"mongodb": "^6.10.0",
|
|
26
26
|
"nodemon": "^3.1.7",
|
|
27
27
|
"npm": "^10.9.2",
|
|
28
|
-
"tango-api-schema": "^2.5.
|
|
28
|
+
"tango-api-schema": "^2.5.70",
|
|
29
29
|
"tango-app-api-middleware": "^3.6.8",
|
|
30
30
|
"winston": "^3.17.0",
|
|
31
31
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -4472,6 +4472,37 @@ async function findAnswer( type ) {
|
|
|
4472
4472
|
];
|
|
4473
4473
|
return answer;
|
|
4474
4474
|
break;
|
|
4475
|
+
case 'dropdown':
|
|
4476
|
+
answer = [
|
|
4477
|
+
{
|
|
4478
|
+
'answer': '',
|
|
4479
|
+
'sopFlag': false,
|
|
4480
|
+
'validation': false,
|
|
4481
|
+
'validationType': '',
|
|
4482
|
+
'referenceImage': [],
|
|
4483
|
+
'runAI': false,
|
|
4484
|
+
'allowUploadfromGallery': false,
|
|
4485
|
+
'descriptivetype': '',
|
|
4486
|
+
'showLinked': false,
|
|
4487
|
+
'linkedQuestion': 0,
|
|
4488
|
+
'nestedQuestion': [],
|
|
4489
|
+
},
|
|
4490
|
+
{
|
|
4491
|
+
'answer': '',
|
|
4492
|
+
'sopFlag': false,
|
|
4493
|
+
'validation': false,
|
|
4494
|
+
'validationType': '',
|
|
4495
|
+
'referenceImage': [],
|
|
4496
|
+
'runAI': false,
|
|
4497
|
+
'allowUploadfromGallery': false,
|
|
4498
|
+
'descriptivetype': '',
|
|
4499
|
+
'showLinked': false,
|
|
4500
|
+
'linkedQuestion': 0,
|
|
4501
|
+
'nestedQuestion': [],
|
|
4502
|
+
},
|
|
4503
|
+
];
|
|
4504
|
+
return answer;
|
|
4505
|
+
break;
|
|
4475
4506
|
default:
|
|
4476
4507
|
return [];
|
|
4477
4508
|
}
|
|
@@ -6634,6 +6665,9 @@ async function insertAItaskSingleProcessedTask( checkTask, inputBody, date, time
|
|
|
6634
6665
|
newData.questionAnswers = [ questions ];
|
|
6635
6666
|
newData.zoneName = inputBody.zoneName || '';
|
|
6636
6667
|
newData.checkListType = 'task' || '';
|
|
6668
|
+
if ( inputBody?.aiType ) {
|
|
6669
|
+
newData.aiType = inputBody.aiType;
|
|
6670
|
+
}
|
|
6637
6671
|
let insertprocessdata = await taskProcessedService.insert( newData );
|
|
6638
6672
|
await taskProcessedConfigService.insert( newData );
|
|
6639
6673
|
console.log( '🚀 ~ insertAItaskSingleProcessedTask ~ insertprocessdata:', insertprocessdata );
|
|
@@ -7050,6 +7084,465 @@ export async function createAITaskGroup( req, res ) {
|
|
|
7050
7084
|
}
|
|
7051
7085
|
}
|
|
7052
7086
|
|
|
7087
|
+
|
|
7088
|
+
export async function AITaskCreation( req, res ) {
|
|
7089
|
+
try {
|
|
7090
|
+
let inputBody = req.body;
|
|
7091
|
+
|
|
7092
|
+
inputBody.taskDescription = '';
|
|
7093
|
+
// Step:1 Store Validation
|
|
7094
|
+
let storeData = await storeService.findOne( { storeName: inputBody.storeName, clientId: inputBody.clientId, status: 'active' }, { storeId: 1, storeName: 1, storeProfile: 1, spocDetails: 1 } );
|
|
7095
|
+
if ( !storeData ) {
|
|
7096
|
+
return res.sendError( 'Store Not Found', 500 );
|
|
7097
|
+
}
|
|
7098
|
+
|
|
7099
|
+
if ( inputBody.taskAssigned == 'teams' ) {
|
|
7100
|
+
let teamDetails = await teamsServices.findteams( { teamName: { $in: inputBody.userList }, clientId: inputBody.clientId }, { users: 1 } );
|
|
7101
|
+
if ( teamDetails.length ) {
|
|
7102
|
+
inputBody.userEmail = teamDetails.map( ( team ) => team.users.map( ( user ) => user.email ) );
|
|
7103
|
+
}
|
|
7104
|
+
}
|
|
7105
|
+
|
|
7106
|
+
let finduser;
|
|
7107
|
+
// Step:2 User Validation
|
|
7108
|
+
if ( inputBody.userEmail.length ) {
|
|
7109
|
+
let userFind = [
|
|
7110
|
+
{
|
|
7111
|
+
$match: {
|
|
7112
|
+
email: { $in: inputBody.userEmail },
|
|
7113
|
+
clientId: inputBody.clientId,
|
|
7114
|
+
},
|
|
7115
|
+
},
|
|
7116
|
+
{
|
|
7117
|
+
$project: {
|
|
7118
|
+
_id: 0,
|
|
7119
|
+
userId: '$_id',
|
|
7120
|
+
userName: 1,
|
|
7121
|
+
userEmail: '$email',
|
|
7122
|
+
},
|
|
7123
|
+
},
|
|
7124
|
+
];
|
|
7125
|
+
let finduserData = await userService.aggregate( userFind );
|
|
7126
|
+
if ( finduserData && finduserData.length > 0 ) {
|
|
7127
|
+
finduser = finduserData;
|
|
7128
|
+
}
|
|
7129
|
+
} else {
|
|
7130
|
+
// get Store Spoc
|
|
7131
|
+
if ( storeData.spocDetails[0].email && storeData.spocDetails[0].email !='' ) {
|
|
7132
|
+
finduser =[ { userId: storeData.spocDetails[0]._id, userName: storeData.spocDetails[0].name, userEmail: storeData.spocDetails[0].email } ];
|
|
7133
|
+
} else {
|
|
7134
|
+
return res.sendError( 'store spoc email invalid', 500 );
|
|
7135
|
+
}
|
|
7136
|
+
}
|
|
7137
|
+
|
|
7138
|
+
// return finduser;
|
|
7139
|
+
// console.log( 'finduser =>', finduser );
|
|
7140
|
+
if ( !finduser.length ) {
|
|
7141
|
+
return res.sendError( 'No user Found For this store', 500 );
|
|
7142
|
+
}
|
|
7143
|
+
|
|
7144
|
+
|
|
7145
|
+
if ( inputBody.approver && !inputBody.approver.length ) {
|
|
7146
|
+
await Promise.all( finduser.map( async ( user ) => {
|
|
7147
|
+
let teamList = await findteams( { users: { $elemMatch: { email: user.userEmail } } } );
|
|
7148
|
+
// console.log( 'teamList =>', teamList );
|
|
7149
|
+
if ( teamList && teamList.length>0 ) {
|
|
7150
|
+
for ( let team of teamList ) {
|
|
7151
|
+
for ( let user of team.Teamlead ) {
|
|
7152
|
+
inputBody.approver.push( user.email );
|
|
7153
|
+
}
|
|
7154
|
+
}
|
|
7155
|
+
}
|
|
7156
|
+
} ) );
|
|
7157
|
+
}
|
|
7158
|
+
|
|
7159
|
+
// Send Push Notification
|
|
7160
|
+
// inputBody.approver = inputBody.approver.replace( /,$/, '' );
|
|
7161
|
+
let title = `New Task Alert ${inputBody.taskName}-${storeData.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
|
|
7162
|
+
let time = inputBody?.scheduleEndTime || '11:59 PM';
|
|
7163
|
+
let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
|
|
7164
|
+
let description = `A new task has been assigned to ${storeData.storeName}. Please complete it before the due date of ${date}.`;
|
|
7165
|
+
await Promise.all( finduser.map( async ( ele ) => {
|
|
7166
|
+
let userDetails = userService.findOne( { _id: new mongoose.Types.ObjectId( ele.userId ) } );
|
|
7167
|
+
if ( userDetails && userDetails.fcmToken ) {
|
|
7168
|
+
const fcmToken = userDetails.fcmToken;
|
|
7169
|
+
sendPushNotification( title, description, fcmToken );
|
|
7170
|
+
}
|
|
7171
|
+
} ) );
|
|
7172
|
+
|
|
7173
|
+
let scheduleEndData = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format();
|
|
7174
|
+
|
|
7175
|
+
if ( inputBody.taskValidity == 'min' ) {
|
|
7176
|
+
scheduleEndData = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).add( inputBody.taskValidity.time, 'miuntes' ).format();
|
|
7177
|
+
}
|
|
7178
|
+
if ( inputBody.taskValidity == 'hour' ) {
|
|
7179
|
+
scheduleEndData = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).add( inputBody.taskValidity.time, 'hour' ).format();
|
|
7180
|
+
}
|
|
7181
|
+
if ( inputBody.taskValidity == 'day' ) {
|
|
7182
|
+
scheduleEndData = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).add( inputBody.taskValidity.time, 'day' ).format();
|
|
7183
|
+
}
|
|
7184
|
+
|
|
7185
|
+
const inputDateTime = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' );
|
|
7186
|
+
const currentTime = dayjs.utc();
|
|
7187
|
+
if ( inputDateTime.isBefore( currentTime ) ) {
|
|
7188
|
+
return res.sendError( 'The input date-time is before the current time.', 500 );
|
|
7189
|
+
}
|
|
7190
|
+
|
|
7191
|
+
let creatorData = await userService.findOne( { clientId: inputBody.clientId, role: 'superadmin', userType: 'client', isActive: true } );
|
|
7192
|
+
if ( !creatorData ) {
|
|
7193
|
+
return res.sendError( 'Invalid Creator Details', 500 );
|
|
7194
|
+
}
|
|
7195
|
+
let creator = [ { _id: creatorData._id, userName: creatorData.userName, userEmail: creatorData.email } ];
|
|
7196
|
+
|
|
7197
|
+
let userAdmin;
|
|
7198
|
+
if ( inputBody.approver && inputBody.approver.length ) {
|
|
7199
|
+
userAdmin = await userService.find( { clientId: inputBody.clientId, email: { $in: inputBody.approver }, userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
|
|
7200
|
+
// console.log( 'userAdmin 1=>', userAdmin );
|
|
7201
|
+
if ( userAdmin && userAdmin.length === 0 ) {
|
|
7202
|
+
userAdmin = creator;
|
|
7203
|
+
}
|
|
7204
|
+
// console.log( 'userAdmin 2=>', userAdmin );
|
|
7205
|
+
}
|
|
7206
|
+
|
|
7207
|
+
if ( req.body && req.body.referenceImage && req.body.referenceImage.length > 3 ) {
|
|
7208
|
+
return res.sendError( 'Maximum 3 referenceImage only allowed', 500 );
|
|
7209
|
+
}
|
|
7210
|
+
|
|
7211
|
+
let answer = await findAnswer( inputBody?.answerType );
|
|
7212
|
+
if ( answer.length == 0 ) {
|
|
7213
|
+
return res.sendError( 'please enter Valid AnswerType', 500 );
|
|
7214
|
+
}
|
|
7215
|
+
|
|
7216
|
+
if ( [ 'multiplechoicesingle', 'multiplechoicemultiple', 'dropdown' ].includes( inputBody?.answerType ) ) {
|
|
7217
|
+
if ( inputBody?.options && inputBody?.options.length > 0 ) {
|
|
7218
|
+
let optionsResult = [];
|
|
7219
|
+
let optionList = inputBody?.options.split( ',' );
|
|
7220
|
+
for ( let option of optionList ) {
|
|
7221
|
+
let optiondata = {
|
|
7222
|
+
'answer': '',
|
|
7223
|
+
'sopFlag': false,
|
|
7224
|
+
'validation': false,
|
|
7225
|
+
'validationType': '',
|
|
7226
|
+
'referenceImage': [],
|
|
7227
|
+
'runAI': false,
|
|
7228
|
+
'allowUploadfromGallery': false,
|
|
7229
|
+
'descriptivetype': '',
|
|
7230
|
+
'showLinked': false,
|
|
7231
|
+
'linkedQuestion': 0,
|
|
7232
|
+
'nestedQuestion': [],
|
|
7233
|
+
'reason': inputBody.reason,
|
|
7234
|
+
'detectionTime': inputBody.detectionTime,
|
|
7235
|
+
};
|
|
7236
|
+
optiondata.answer = option;
|
|
7237
|
+
optionsResult.push( optiondata );
|
|
7238
|
+
}
|
|
7239
|
+
answer = optionsResult;
|
|
7240
|
+
} else {
|
|
7241
|
+
return res.sendError( 'please enter Valid Options', 500 );
|
|
7242
|
+
}
|
|
7243
|
+
}
|
|
7244
|
+
|
|
7245
|
+
if ( inputBody.reason ) {
|
|
7246
|
+
answer[0].reason = inputBody.reason;
|
|
7247
|
+
answer[0].detectionTime = inputBody.detectionTime;
|
|
7248
|
+
}
|
|
7249
|
+
|
|
7250
|
+
// Check this Task Already Exist////
|
|
7251
|
+
let checkTask = await taskService.findOne( { checkListName: inputBody.taskName } );
|
|
7252
|
+
if ( checkTask ) {
|
|
7253
|
+
let singleInsert = await insertAItaskProcessedTaskCreation( checkTask, inputBody, date, time, storeData, finduser, answer, userAdmin );
|
|
7254
|
+
if ( singleInsert ) {
|
|
7255
|
+
return res.sendSuccess( 'Task created successfully' );
|
|
7256
|
+
} else {
|
|
7257
|
+
return res.sendError( 'something went wrong, please try again', 500 );
|
|
7258
|
+
}
|
|
7259
|
+
} else {
|
|
7260
|
+
let data = {
|
|
7261
|
+
// checkListName: `${inputBody.taskName}(${storeData.storeName}-${dayjs().format( 'YYYY-MM-DD' )}-${inputBody.zoneName ? inputBody.zoneName : ''})`,
|
|
7262
|
+
checkListName: inputBody.taskName,
|
|
7263
|
+
checkListDescription: inputBody.taskDescription,
|
|
7264
|
+
createdBy: creator[0]._id,
|
|
7265
|
+
createdByName: creator[0].userName,
|
|
7266
|
+
publish: true,
|
|
7267
|
+
questionCount: 1,
|
|
7268
|
+
storeCount: 1,
|
|
7269
|
+
scheduleDate: date,
|
|
7270
|
+
scheduleEndTime: time,
|
|
7271
|
+
scheduleEndTimeISO: scheduleEndData,
|
|
7272
|
+
priorityType: 'high',
|
|
7273
|
+
client_id: inputBody.clientId,
|
|
7274
|
+
checkListType: 'task',
|
|
7275
|
+
publishDate: new Date(),
|
|
7276
|
+
locationCount: 1,
|
|
7277
|
+
...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
|
|
7278
|
+
coverage: 'store',
|
|
7279
|
+
checkListFrom: 'api',
|
|
7280
|
+
zoneName: inputBody.zoneName || '',
|
|
7281
|
+
checkListType: 'task',
|
|
7282
|
+
};
|
|
7283
|
+
data['approver'] = userAdmin;
|
|
7284
|
+
|
|
7285
|
+
if ( [ 'multiplechoicesingle', 'multiplechoicemultiple', 'dropdown' ].includes( inputBody?.answerType ) ) {
|
|
7286
|
+
if ( inputBody?.options && inputBody?.options.length > 0 ) {
|
|
7287
|
+
let optionsResult = [];
|
|
7288
|
+
let optionList = inputBody?.options.split( ',' );
|
|
7289
|
+
for ( let option of optionList ) {
|
|
7290
|
+
let optiondata = {
|
|
7291
|
+
'answer': '',
|
|
7292
|
+
'sopFlag': false,
|
|
7293
|
+
'validation': false,
|
|
7294
|
+
'validationType': '',
|
|
7295
|
+
'referenceImage': [],
|
|
7296
|
+
'runAI': false,
|
|
7297
|
+
'allowUploadfromGallery': false,
|
|
7298
|
+
'descriptivetype': '',
|
|
7299
|
+
'showLinked': false,
|
|
7300
|
+
'linkedQuestion': 0,
|
|
7301
|
+
'nestedQuestion': [],
|
|
7302
|
+
'reason': inputBody.reason,
|
|
7303
|
+
'detectionTime': inputBody.detectionTime,
|
|
7304
|
+
};
|
|
7305
|
+
optiondata.answer = option;
|
|
7306
|
+
optionsResult.push( optiondata );
|
|
7307
|
+
}
|
|
7308
|
+
answer = optionsResult;
|
|
7309
|
+
} else {
|
|
7310
|
+
return res.sendError( 'please enter Valid Options', 500 );
|
|
7311
|
+
}
|
|
7312
|
+
}
|
|
7313
|
+
let clientDetails = await clientService.findOne( { clientId: inputBody?.clientId }, { traxVideoUploadTimeLimit: 1 } );
|
|
7314
|
+
data['videoUploadTimeLimit'] = clientDetails?.traxVideoUploadTimeLimit || 0;
|
|
7315
|
+
let response = await taskService.create( data );
|
|
7316
|
+
if ( response?.approver.length ) {
|
|
7317
|
+
let inputData = [];
|
|
7318
|
+
response?.approver.forEach( ( ele ) => {
|
|
7319
|
+
inputData.push( {
|
|
7320
|
+
userEmail: ele.email,
|
|
7321
|
+
checkListId: response._id,
|
|
7322
|
+
type: 'task',
|
|
7323
|
+
client_id: inputBody.clientId,
|
|
7324
|
+
checkListName: data?.checkListName || '',
|
|
7325
|
+
} );
|
|
7326
|
+
} );
|
|
7327
|
+
await traxApprover.insertMany( inputData );
|
|
7328
|
+
}
|
|
7329
|
+
|
|
7330
|
+
if ( response?._id ) {
|
|
7331
|
+
let question = [
|
|
7332
|
+
{
|
|
7333
|
+
'qno': 1,
|
|
7334
|
+
'qname': inputBody.question,
|
|
7335
|
+
'answerType': inputBody?.answerType || 'yes/no',
|
|
7336
|
+
'runAI': false,
|
|
7337
|
+
'runAIDescription': '',
|
|
7338
|
+
'allowUploadfromGallery': false,
|
|
7339
|
+
'linkType': false,
|
|
7340
|
+
'questionReferenceImage': [],
|
|
7341
|
+
'answers': answer,
|
|
7342
|
+
'descriptivetype': 'text',
|
|
7343
|
+
'allowMultiple': inputBody.multi,
|
|
7344
|
+
},
|
|
7345
|
+
];
|
|
7346
|
+
|
|
7347
|
+
let images = [];
|
|
7348
|
+
for ( let imgpath of req.body.referenceImage ) {
|
|
7349
|
+
let configURL = JSON.parse( process.env.BUCKET );
|
|
7350
|
+
let inputData = {
|
|
7351
|
+
Bucket: configURL.aiTraxoutput,
|
|
7352
|
+
Key: imgpath,
|
|
7353
|
+
};
|
|
7354
|
+
let output = await getObject( inputData );
|
|
7355
|
+
// / Check Bucket
|
|
7356
|
+
console.log( 'output =>', output );
|
|
7357
|
+
let image = {
|
|
7358
|
+
data: output.Body,
|
|
7359
|
+
name: imgpath,
|
|
7360
|
+
mimetype: output.ContentType,
|
|
7361
|
+
};
|
|
7362
|
+
let uplaodedImage = await uploadmultiImage( image );
|
|
7363
|
+
let imgUrl = decodeURIComponent( uplaodedImage?.imgUrl.split( '?' )[0] );
|
|
7364
|
+
let url = imgUrl.split( '/' );
|
|
7365
|
+
if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
|
|
7366
|
+
url.splice( 0, 3 );
|
|
7367
|
+
}
|
|
7368
|
+
images.push( url.join( '/' ) );
|
|
7369
|
+
}
|
|
7370
|
+
question[0].questionReferenceImage = images;
|
|
7371
|
+
|
|
7372
|
+
if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
|
|
7373
|
+
answer[0].referenceImage = question[0].questionReferenceImage;
|
|
7374
|
+
}
|
|
7375
|
+
|
|
7376
|
+
question = {
|
|
7377
|
+
checkListId: response?._id,
|
|
7378
|
+
question: question,
|
|
7379
|
+
section: 'Section 1',
|
|
7380
|
+
checkList: data.checkListName,
|
|
7381
|
+
client_id: inputBody.clientId,
|
|
7382
|
+
};
|
|
7383
|
+
await taskQuestionService.create( question );
|
|
7384
|
+
let userDetails = [];
|
|
7385
|
+
finduser.forEach( ( ele ) => {
|
|
7386
|
+
userDetails = {
|
|
7387
|
+
userName: ele.userName,
|
|
7388
|
+
userEmail: ele.userEmail,
|
|
7389
|
+
store_id: storeData.storeId,
|
|
7390
|
+
storeName: storeData.storeName,
|
|
7391
|
+
city: storeData?.storeProfile?.city,
|
|
7392
|
+
checkFlag: true,
|
|
7393
|
+
checkListId: response?._id,
|
|
7394
|
+
checkListName: data.checkListName,
|
|
7395
|
+
client_id: inputBody.clientId,
|
|
7396
|
+
userId: ele.userId,
|
|
7397
|
+
assignId: storeData?._id,
|
|
7398
|
+
country: storeData?.storeProfile?.country,
|
|
7399
|
+
state: storeData?.storeProfile?.state,
|
|
7400
|
+
};
|
|
7401
|
+
} );
|
|
7402
|
+
|
|
7403
|
+
await taskAssignService.insertMany( userDetails );
|
|
7404
|
+
await insertSingleProcessData( response?._id, false, { aiTask: true, aiType: inputBody.aiType } );
|
|
7405
|
+
return res.sendSuccess( 'Task created successfully' );
|
|
7406
|
+
}
|
|
7407
|
+
}
|
|
7408
|
+
} catch ( e ) {
|
|
7409
|
+
console.log( 'e =>', e );
|
|
7410
|
+
logger.error( { function: 'createTaskGroup', error: e } );
|
|
7411
|
+
return res.sendError( e, 500 );
|
|
7412
|
+
}
|
|
7413
|
+
}
|
|
7414
|
+
|
|
7415
|
+
async function insertAItaskProcessedTaskCreation( checkTask, inputBody, date, time, storeDetails, finduser, answer, userAdmin ) {
|
|
7416
|
+
try {
|
|
7417
|
+
let getquestion = await taskQuestionService.findOne( { checkListId: checkTask._id } );
|
|
7418
|
+
let getolddata = await taskProcessedService.findOne( { sourceCheckList_id: checkTask._id } );
|
|
7419
|
+
let getoldConfigdata = await taskService.findOne( { _id: checkTask._id } );
|
|
7420
|
+
|
|
7421
|
+
const uniqueUsers = mergeUnique( getoldConfigdata.approver, userAdmin, '_id' );
|
|
7422
|
+
// Question Patten Making
|
|
7423
|
+
let question = [
|
|
7424
|
+
{
|
|
7425
|
+
'qno': 1,
|
|
7426
|
+
'qname': inputBody.question,
|
|
7427
|
+
'answerType': inputBody?.answerType || 'yes/no',
|
|
7428
|
+
'runAI': false,
|
|
7429
|
+
'runAIDescription': '',
|
|
7430
|
+
'allowUploadfromGallery': false,
|
|
7431
|
+
'linkType': false,
|
|
7432
|
+
'questionReferenceImage': [],
|
|
7433
|
+
'answers': answer,
|
|
7434
|
+
'descriptivetype': 'text',
|
|
7435
|
+
'allowMultiple': inputBody.multi,
|
|
7436
|
+
},
|
|
7437
|
+
];
|
|
7438
|
+
|
|
7439
|
+
let images = [];
|
|
7440
|
+
for ( let imgpath of inputBody.referenceImage ) {
|
|
7441
|
+
let configURL = JSON.parse( process.env.BUCKET );
|
|
7442
|
+
let inputData = {
|
|
7443
|
+
Bucket: configURL.aiTraxoutput,
|
|
7444
|
+
Key: imgpath,
|
|
7445
|
+
};
|
|
7446
|
+
let output = await getObject( inputData );
|
|
7447
|
+
let image = {
|
|
7448
|
+
data: output.Body,
|
|
7449
|
+
name: imgpath,
|
|
7450
|
+
mimetype: output.ContentType,
|
|
7451
|
+
};
|
|
7452
|
+
let uplaodedImage = await uploadmultiImage( image );
|
|
7453
|
+
let imgUrl = decodeURIComponent( uplaodedImage?.imgUrl.split( '?' )[0] );
|
|
7454
|
+
let url = imgUrl.split( '/' );
|
|
7455
|
+
if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
|
|
7456
|
+
url.splice( 0, 3 );
|
|
7457
|
+
}
|
|
7458
|
+
images.push( url.join( '/' ) );
|
|
7459
|
+
}
|
|
7460
|
+
question[0].questionReferenceImage = images;
|
|
7461
|
+
|
|
7462
|
+
if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
|
|
7463
|
+
answer[0].referenceImage = question[0].questionReferenceImage;
|
|
7464
|
+
}
|
|
7465
|
+
|
|
7466
|
+
let questions = {
|
|
7467
|
+
questions: question,
|
|
7468
|
+
sectionName: getquestion.section,
|
|
7469
|
+
section_id: getquestion._id,
|
|
7470
|
+
};
|
|
7471
|
+
|
|
7472
|
+
let oldData = getolddata.toObject();
|
|
7473
|
+
delete oldData._id;
|
|
7474
|
+
oldData.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
|
|
7475
|
+
oldData.date_string = dayjs( date ).format( 'YYYY-MM-DD' );
|
|
7476
|
+
oldData.scheduleStartTime_iso = date;
|
|
7477
|
+
oldData.scheduleEndTime_iso = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format();
|
|
7478
|
+
oldData.store_id = storeDetails.storeId;
|
|
7479
|
+
oldData.storeName = storeDetails.storeName;
|
|
7480
|
+
oldData.country = storeDetails.storeProfile.country;
|
|
7481
|
+
oldData.checklistStatus = 'open';
|
|
7482
|
+
oldData.timeFlagStatus = true;
|
|
7483
|
+
oldData.checkListFrom = 'api';
|
|
7484
|
+
oldData.createdAt = new Date();
|
|
7485
|
+
oldData.updatedAt = new Date();
|
|
7486
|
+
oldData.approvalStatus = false;
|
|
7487
|
+
oldData.approvalEnable = true;
|
|
7488
|
+
oldData.approvalTime = '';
|
|
7489
|
+
oldData.approvalTime_string = '';
|
|
7490
|
+
oldData.redoStatus = false;
|
|
7491
|
+
oldData.approvalByName = '';
|
|
7492
|
+
oldData.approvalByEmail = '';
|
|
7493
|
+
oldData.questionAnswers = [ questions ];
|
|
7494
|
+
oldData.zoneName = inputBody.zoneName || '';
|
|
7495
|
+
oldData.checkListType = 'task' || '';
|
|
7496
|
+
if ( inputBody.aiType ) {
|
|
7497
|
+
oldData.aiType = inputBody.aiType;
|
|
7498
|
+
}
|
|
7499
|
+
let configDetails = await taskProcessedConfigService.insert( oldData );
|
|
7500
|
+
let insertData = [];
|
|
7501
|
+
finduser.forEach( ( user ) => {
|
|
7502
|
+
let newData = oldData;
|
|
7503
|
+
newData.userId = user.userId;
|
|
7504
|
+
newData.userName = user.userName;
|
|
7505
|
+
newData.userEmail = user.userEmail;
|
|
7506
|
+
newData.checkListId = configDetails._id;
|
|
7507
|
+
insertData.push( newData );
|
|
7508
|
+
} );
|
|
7509
|
+
let insertprocessdata = await taskProcessedService.insertMany( insertData );
|
|
7510
|
+
console.log( '🚀 ~ insertAItaskSingleProcessedTask ~ insertprocessdata:', insertprocessdata );
|
|
7511
|
+
if ( insertprocessdata ) {
|
|
7512
|
+
if ( uniqueUsers && uniqueUsers.length>0 ) {
|
|
7513
|
+
// updated Task Approver//
|
|
7514
|
+
await taskService.updateOne( { _id: oldData.sourceCheckList_id }, { approver: uniqueUsers } );
|
|
7515
|
+
for ( let k = 0; k < uniqueUsers.length; k++ ) {
|
|
7516
|
+
let checkapprover = {
|
|
7517
|
+
userEmail: uniqueUsers[k].email,
|
|
7518
|
+
checkListId: oldData.sourceCheckList_id,
|
|
7519
|
+
type: 'task',
|
|
7520
|
+
client_id: oldData.client_id,
|
|
7521
|
+
isDeleted: false,
|
|
7522
|
+
};
|
|
7523
|
+
let getapproverData = await traxApprover.findOne( checkapprover );
|
|
7524
|
+
if ( !getapproverData ) {
|
|
7525
|
+
let inserApproverData = {
|
|
7526
|
+
userEmail: uniqueUsers[k].email,
|
|
7527
|
+
checkListId: oldData.sourceCheckList_id,
|
|
7528
|
+
type: 'task',
|
|
7529
|
+
client_id: oldData.client_id,
|
|
7530
|
+
isDeleted: false,
|
|
7531
|
+
};
|
|
7532
|
+
await traxApprover.create( inserApproverData );
|
|
7533
|
+
}
|
|
7534
|
+
}
|
|
7535
|
+
}
|
|
7536
|
+
return true;
|
|
7537
|
+
} else {
|
|
7538
|
+
return false;
|
|
7539
|
+
}
|
|
7540
|
+
} catch ( error ) {
|
|
7541
|
+
logger.error( { error: error, function: 'insertSingleProcessedTask' } );
|
|
7542
|
+
return false;
|
|
7543
|
+
}
|
|
7544
|
+
}
|
|
7545
|
+
|
|
7053
7546
|
function mergeUnique( arr1 = [], arr2 = [], key = '_id' ) {
|
|
7054
7547
|
const merged = [ ...arr1, ...arr2 ];
|
|
7055
7548
|
|
|
@@ -1104,11 +1104,12 @@ export async function taskDetails( req, res ) {
|
|
|
1104
1104
|
},
|
|
1105
1105
|
];
|
|
1106
1106
|
|
|
1107
|
-
if ( req.body?.searchValue
|
|
1107
|
+
if ( req.body?.searchValue?.trim()?.length ) {
|
|
1108
|
+
const safeSearch = escapeRegex( req.body?.searchValue );
|
|
1108
1109
|
query.push(
|
|
1109
1110
|
{
|
|
1110
1111
|
$match: {
|
|
1111
|
-
checkListName: { $regex:
|
|
1112
|
+
checkListName: { $regex: safeSearch, $options: 'i' },
|
|
1112
1113
|
},
|
|
1113
1114
|
},
|
|
1114
1115
|
);
|
|
@@ -1172,3 +1173,6 @@ export async function taskDetails( req, res ) {
|
|
|
1172
1173
|
return res.sendError( e, 500 );
|
|
1173
1174
|
}
|
|
1174
1175
|
}
|
|
1176
|
+
function escapeRegex( text ) {
|
|
1177
|
+
return text.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
|
|
1178
|
+
}
|
|
@@ -44,6 +44,7 @@ taskRouter
|
|
|
44
44
|
.post( '/breached-tasks', isAllowedInternalAPIHandler, validate( taskcreationvalidation ), taskController.breachedTasks )
|
|
45
45
|
.get( '/getcoustemer', taskController.customertrial )
|
|
46
46
|
.post( '/createTaskGroup', isAllowedInternalAPIHandler, validate( createTaskGroupvalidation ), taskController.createTaskGroup )
|
|
47
|
-
.post( '/createAITaskGroup', isAllowedInternalAPIHandler, validate( createTaskGroupvalidation ), taskController.createAITaskGroup )
|
|
47
|
+
.post( '/createAITaskGroup', isAllowedInternalAPIHandler, validate( createTaskGroupvalidation ), taskController.createAITaskGroup )
|
|
48
|
+
.post( '/AITaskCreation', isAllowedInternalAPIHandler, taskController.AITaskCreation );
|
|
48
49
|
|
|
49
50
|
|