tango-app-api-task 3.7.24 → 3.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-task",
3
- "version": "3.7.24",
3
+ "version": "3.7.26",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -5038,9 +5038,12 @@ export async function taskcreation( req, res ) {
5038
5038
  inputBody.clientId = 458;
5039
5039
  inputBody.taskDescription = '';
5040
5040
  let userId;
5041
- let storeDetails = await storeService.findOne( { storeName: inputBody.storeName, clientId: inputBody.clientId, status: 'active' }, { storeId: 1, storeName: 1, storeProfile: 1 } );
5042
- if ( !storeDetails ) {
5043
- return res.sendError( 'Store Not Found', 500 );
5041
+ let storeDetails;
5042
+ if ( inputBody?.storeName ) {
5043
+ storeDetails = await storeService.findOne( { storeName: inputBody.storeName, clientId: inputBody.clientId, status: 'active' }, { storeId: 1, storeName: 1, storeProfile: 1 } );
5044
+ if ( !storeDetails ) {
5045
+ return res.sendError( 'Store Not Found', 500 );
5046
+ }
5044
5047
  }
5045
5048
 
5046
5049
 
@@ -5056,10 +5059,10 @@ export async function taskcreation( req, res ) {
5056
5059
  inputBody.userEmail = finduser.email;
5057
5060
 
5058
5061
 
5059
- let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
5062
+ let title = `New Task Alert ${inputBody.taskName}-`+storeDetails?.storeName ? storeDetails?.storeName : ``+`-${dayjs().format( 'YYYY-MM-DD' )}`;
5060
5063
  let time = inputBody?.scheduleEndTime || '11:59 PM';
5061
5064
  let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
5062
- let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
5065
+ let description = `A new task has been assigned to`+storeDetails?.storeName ? storeDetails?.storeName : `you` +`. Please complete it before the due date of ${date}.`;
5063
5066
  if ( userDetails && userDetails.fcmToken ) {
5064
5067
  const fcmToken = userDetails.fcmToken;
5065
5068
  await sendPushNotification( title, description, fcmToken );
@@ -5086,13 +5089,19 @@ export async function taskcreation( req, res ) {
5086
5089
  if ( req.body && req.body.referenceImage && req.body.referenceImage.length > 3 ) {
5087
5090
  return res.sendError( 'Maximum 3 referenceImage only allowed', 500 );
5088
5091
  }
5092
+ let taskName;
5093
+ if ( inputBody?.storeName ) {
5094
+ taskName = `${inputBody.taskName}(${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )})`;
5095
+ } else {
5096
+ taskName = `${inputBody.taskName}(-${dayjs().format( 'YYYY-MM-DD' )})`;
5097
+ }
5089
5098
  let data = {
5090
- checkListName: `${inputBody.taskName}(${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )})`,
5099
+ checkListName: taskName,
5091
5100
  checkListDescription: inputBody.taskDescription,
5092
5101
  createdBy: creator[0]._id,
5093
5102
  createdByName: creator[0].userName,
5094
5103
  publish: true,
5095
- questionCount: 1,
5104
+ questionCount: inputBody?.questions?.length || 1,
5096
5105
  storeCount: 1,
5097
5106
  scheduleDate: date,
5098
5107
  scheduleEndTime: time,
@@ -5103,6 +5112,7 @@ export async function taskcreation( req, res ) {
5103
5112
  publishDate: new Date(),
5104
5113
  locationCount: 1,
5105
5114
  ...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
5115
+ coverage: inputBody?.storeName ? 'store' : 'user',
5106
5116
  };
5107
5117
  let clientDetails = await clientService.findOne( { clientId: inputBody?.clientId }, { traxVideoUploadTimeLimit: 1 } );
5108
5118
  data['videoUploadTimeLimit'] = clientDetails?.traxVideoUploadTimeLimit || 0;
@@ -5210,8 +5220,8 @@ export async function taskcreation( req, res ) {
5210
5220
  let userDetails = {
5211
5221
  userName: inputBody.userName,
5212
5222
  userEmail: inputBody.userEmail,
5213
- store_id: storeDetails.storeId,
5214
- storeName: storeDetails.storeName,
5223
+ store_id: storeDetails?.storeId,
5224
+ storeName: storeDetails?.storeName,
5215
5225
  city: storeDetails?.storeProfile?.city,
5216
5226
  checkFlag: true,
5217
5227
  checkListId: response?._id,
@@ -5221,6 +5231,7 @@ export async function taskcreation( req, res ) {
5221
5231
  assignId: storeDetails?._id,
5222
5232
  country: storeDetails?.storeProfile?.country,
5223
5233
  state: storeDetails?.storeProfile?.state,
5234
+ coverage: inputBody?.storeName ? 'store' : 'user',
5224
5235
  };
5225
5236
  await taskAssignService.create( userDetails );
5226
5237
  await insertSingleProcessData( response?._id );
@@ -1104,11 +1104,12 @@ export async function taskDetails( req, res ) {
1104
1104
  },
1105
1105
  ];
1106
1106
 
1107
- if ( req.body?.searchValue.trim().length ) {
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: req.body.searchValue, $options: 'i' },
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
+ }
@@ -56,7 +56,7 @@ const gettaskSchema = Joi.object( {
56
56
  sourceCheckList_id: Joi.string().required(),
57
57
  } );
58
58
  export const taskcreationSchema = Joi.object().keys( {
59
- storeName: Joi.string().required(),
59
+ storeName: Joi.string().optional().allow( '' ),
60
60
  taskName: Joi.string().required(),
61
61
  user: Joi.string().required(),
62
62
  questions: Joi.array().items( questionSchema ).required(),
@@ -65,6 +65,7 @@ export const taskcreationSchema = Joi.object().keys( {
65
65
  scheduleEndTime: Joi.string().optional(),
66
66
  approver: Joi.string().required(),
67
67
  creator: Joi.string().required(),
68
+ coverage: Joi.string().optional(),
68
69
  } );
69
70
 
70
71
  export const commonAiTaskvalidation = {