tango-app-api-store-builder 1.0.0-beta-44 → 1.0.0-beta-45

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-store-builder",
3
- "version": "1.0.0-beta-44",
3
+ "version": "1.0.0-beta-45",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,11 +1,13 @@
1
1
  import * as taskService from '../service/task.service.js';
2
- import * as processedService from '../service/processedchecklist.service.js';
2
+ import * as processedService from '../service/processedTaskservice.js';
3
3
  import * as storeService from '../service/store.service.js';
4
+ import * as processedChecklistService from '../service/processedchecklist.service.js';
4
5
  import * as userService from '../service/user.service.js';
5
6
  import dayjs from 'dayjs';
6
7
  import { logger, fileUpload, signedUrl } from 'tango-app-api-middleware';
7
8
  import * as planoTaskService from '../service/planoTask.service.js';
8
9
  import * as planoService from '../service/planogram.service.js';
10
+ import * as checklistService from '../service/checklist.service.js';
9
11
 
10
12
  async function createUser( data ) {
11
13
  try {
@@ -100,8 +102,8 @@ async function createUser( data ) {
100
102
 
101
103
  export async function createTask( req, res ) {
102
104
  try {
103
- let taskDetails = await taskService.find( { isPlano: true, client_id: req.body.clientId } );
104
- let storeList = req.body.stores.map( ( ele ) => ele.toLowerCase() );
105
+ let taskDetails = await taskService.find( { isPlano: true, client_id: req.body.clientId, ...( req.body.checkListName )? { checkListName: req.body.checkListName } : {} } );
106
+ let storeList = req.body.stores.map( ( ele ) => ele.store.toLowerCase() );
105
107
  let userDetails;
106
108
  if ( !taskDetails.length ) {
107
109
  return res.sendError( 'No data found', 204 );
@@ -149,7 +151,7 @@ export async function createTask( req, res ) {
149
151
  approvalEnable: false,
150
152
  redoStatus: false,
151
153
  isPlano: true,
152
- type: task.checkListName == 'Product Verification' ? 'product' : task.checkListName == 'Fixture Verification' ? 'fixture' : 'vm',
154
+ planoType: task.checkListName == 'Product Verification' ? 'product' : task.checkListName == 'Fixture Verification' ? 'fixture' : task.checkListName == 'Layout Verification' ? 'layout' : 'vm',
153
155
  };
154
156
  let query = [
155
157
  {
@@ -166,47 +168,34 @@ export async function createTask( req, res ) {
166
168
  ];
167
169
 
168
170
  let storeDetails = await storeService.aggregate( query );
169
- if ( req.body.userEmail ) {
170
- let query = [
171
- {
172
- $addFields: {
173
- emailLower: { $toLower: '$email' },
174
- },
175
- },
176
- {
177
- $match: {
178
- clientId: req.body.clientId,
179
- emailLower: req.body.userEmail,
180
- },
181
- },
182
- ];
183
- userDetails = await userService.aggregate( query );
184
- if ( !userDetails.length ) {
185
- let userData = {
186
- clientId: req.body.clientId,
187
- mobileNumber: '',
188
- email: req.body.userEmail,
189
- userName: req.body.userEmail.split( '@' )[0],
190
- };
191
- userDetails = await createUser( userData );
192
- } else {
193
- userDetails = userDetails[0];
194
- }
195
- }
196
-
197
171
  await Promise.all( storeDetails.map( async ( store ) => {
172
+ let getUserEmail = req.body.stores.find( ( ele ) => ele.store.toLowerCase() == store.storeName.toLowerCase() );
198
173
  let planoDetails = await planoService.findOne( { storeId: store.storeId } );
199
- console.log( planoDetails, store.storeId, 'details' );
200
- if ( !req.body.userEmail ) {
201
- userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email } );
202
- if ( !userDetails ) {
174
+ if ( getUserEmail ) {
175
+ let query = [
176
+ {
177
+ $addFields: {
178
+ emailLower: { $toLower: '$email' },
179
+ },
180
+ },
181
+ {
182
+ $match: {
183
+ clientId: req.body.clientId,
184
+ email: getUserEmail.email,
185
+ },
186
+ },
187
+ ];
188
+ userDetails = await userService.aggregate( query );
189
+ if ( !userDetails.length ) {
203
190
  let userData = {
204
191
  clientId: req.body.clientId,
205
- mobileNumber: store?.spocDetails?.[0]?.contact,
206
- email: store?.spocDetails?.[0]?.email,
207
- userName: store?.spocDetails?.[0]?.name,
192
+ mobileNumber: '',
193
+ email: getUserEmail.email,
194
+ userName: getUserEmail.email.split( '@' )[0],
208
195
  };
209
196
  userDetails = await createUser( userData );
197
+ } else {
198
+ userDetails = userDetails[0];
210
199
  }
211
200
  }
212
201
  let taskData = { ...data };
@@ -232,6 +221,127 @@ export async function createTask( req, res ) {
232
221
  }
233
222
  }
234
223
 
224
+ export async function createPlano( req, res ) {
225
+ try {
226
+ let checklistDetails = await checklistService.find( { isPlano: true, client_id: req.body.clientId } );
227
+ let storeList = req.body.stores.map( ( ele ) => ele.store.toLowerCase() );
228
+ let userDetails;
229
+ if ( !checklistDetails.length ) {
230
+ return res.sendError( 'No data found', 204 );
231
+ }
232
+ await Promise.all( checklistDetails.map( async ( checklist ) => {
233
+ let data = {
234
+ client_id: req.body.clientId,
235
+ date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
236
+ date_string: dayjs().format( 'YYYY-MM-DD' ),
237
+ sourceCheckList_id: checklist._id,
238
+ checkListName: checklist.checkListName,
239
+ checkListId: checklist._id,
240
+ scheduleStartTime: '08:00 AM',
241
+ scheduleEndTime: '11:59 PM',
242
+ scheduleStartTime_iso: dayjs.utc( '08:00 AM', 'hh:mm A' ).format(),
243
+ scheduleEndTime_iso: dayjs.utc( '11:59 PM', 'hh:mm A' ).format(),
244
+ allowedOverTime: false,
245
+ allowedStoreLocation: false,
246
+ createdBy: checklist.createdBy,
247
+ createdByName: checklist.createdByName,
248
+ questionAnswers: [],
249
+ isdeleted: false,
250
+ questionCount: 0,
251
+ storeCount: 0,
252
+ locationCount: 0,
253
+ checkListType: 'custom',
254
+ country: '',
255
+ store_id: '',
256
+ storeName: '',
257
+ userId: '',
258
+ userName: '',
259
+ userEmail: '',
260
+ checklistStatus: 'open',
261
+ timeFlagStatus: true,
262
+ timeFlag: 0,
263
+ questionFlag: 0,
264
+ mobileDetectionFlag: 0,
265
+ storeOpenCloseFlag: 0,
266
+ reinitiateStatus: false,
267
+ markasread: false,
268
+ uniformDetectionFlag: 0,
269
+ scheduleRepeatedType: 'daily',
270
+ approvalStatus: false,
271
+ approvalEnable: false,
272
+ redoStatus: false,
273
+ isPlano: true,
274
+ planoType: checklist.checkListName == 'Planogram QR' ? 'qr' : 'rfid',
275
+ };
276
+ let query = [
277
+ {
278
+ $addFields: {
279
+ store: { $toLower: '$storeName' },
280
+ },
281
+ },
282
+ {
283
+ $match: {
284
+ clientId: req.body.clientId,
285
+ store: { $in: storeList },
286
+ },
287
+ },
288
+ ];
289
+
290
+ let storeDetails = await storeService.aggregate( query );
291
+ await Promise.all( storeDetails.map( async ( store ) => {
292
+ let getUserEmail = req.body.stores.find( ( ele ) => ele.store.toLowerCase() == store.storeName.toLowerCase() );
293
+ let planoDetails = await planoService.findOne( { storeId: store.storeId } );
294
+ if ( getUserEmail ) {
295
+ let query = [
296
+ {
297
+ $addFields: {
298
+ emailLower: { $toLower: '$email' },
299
+ },
300
+ },
301
+ {
302
+ $match: {
303
+ clientId: req.body.clientId,
304
+ email: getUserEmail.email,
305
+ },
306
+ },
307
+ ];
308
+ userDetails = await userService.aggregate( query );
309
+ console.log( userDetails );
310
+ if ( !userDetails.length ) {
311
+ let userData = {
312
+ clientId: req.body.clientId,
313
+ mobileNumber: '',
314
+ email: getUserEmail.email,
315
+ userName: getUserEmail.email.split( '@' )[0],
316
+ };
317
+ userDetails = await createUser( userData );
318
+ } else {
319
+ userDetails = userDetails[0];
320
+ }
321
+ }
322
+ let checklistData = { ...data };
323
+ checklistData.store_id = store.storeId;
324
+ checklistData.storeName = store.storeName;
325
+ checklistData.userId = userDetails._id;
326
+ checklistData.userName = userDetails.userName;
327
+ checklistData.userEmail = userDetails.email;
328
+ checklistData.planoId = planoDetails?._id;
329
+ for ( let i=0; i<req.body.days; i++ ) {
330
+ let currDate = dayjs().add( i, 'day' );
331
+ let insertData = { ...checklistData, date_string: currDate.format( 'YYYY-MM-DD' ), date_iso: new Date( currDate.format( 'YYYY-MM-DD' ) ), scheduleStartTime_iso: dayjs.utc( `${currDate.format( 'YYYY-MM-DD' )} 08:00 AM`, 'YYYY-MM-DD hh:mm A' ).format(), scheduleEndTime_iso: dayjs.utc( `${currDate.format( 'YYYY-MM-DD' )} 11:59 PM`, 'YYYY-MM-DD hh:mm A' ).format() };
332
+ let response = await processedChecklistService.updateOne( { date_string: currDate.format( 'YYYY-MM-DD' ), store_id: insertData.store_id, userEmail: insertData.userEmail, planoId: insertData.planoId, sourceCheckList_id: checklist._id }, insertData );
333
+ console.log( insertData.store_id, response );
334
+ }
335
+ } ) );
336
+ } ) );
337
+
338
+ return res.sendSuccess( 'Checklist created successfully' );
339
+ } catch ( e ) {
340
+ logger.error( { functionName: 'createTask', error: e } );
341
+ return res.sendError( e, 500 );
342
+ }
343
+ }
344
+
235
345
  export async function getTaskDetails( req, res ) {
236
346
  try {
237
347
  if ( !req.query.storeId ) {
@@ -337,10 +447,21 @@ export async function updateAnswers( req, res ) {
337
447
 
338
448
  export async function getFixtureDetails( req, res ) {
339
449
  try {
340
- if ( !req.query.fixtureId ) {
341
- return res.sendError( 'Fixture id is required', 400 );
450
+ if ( !req.query.fixtureId && !req.query.planoId ) {
451
+ return res.sendError( 'Fixture/Plano id is required', 400 );
342
452
  }
343
- let fixtureDetails = await planoTaskService.findOne( { fixtureId: req.query.fixtureId, type: req.query.type } );
453
+ let query = { type: req.query.type };
454
+ if ( req.query?.fixtureId ) {
455
+ query['fixtureId'] = req.query.fixtureId;
456
+ } else {
457
+ if ( !req.query.floorId ) {
458
+ return res.sendError( 'Floor id is required', 400 );
459
+ }
460
+ query['planoId'] = req.query.planoId;
461
+ query['floorId'] = req.query.floorId;
462
+ }
463
+
464
+ let fixtureDetails = await planoTaskService.findOne( { fixtureId: req.query.fixtureId } );
344
465
  if ( !fixtureDetails ) {
345
466
  return res.sendError( 'No data found', 204 );
346
467
  }
@@ -6,6 +6,7 @@ export const storeBuilderTaskRouter = express.Router();
6
6
 
7
7
  storeBuilderTaskRouter
8
8
  .post( '/createTask', taskController.createTask )
9
+ .post( '/createPlano', taskController.createPlano )
9
10
  .get( '/taskDetails', taskController.getTaskDetails )
10
11
  .post( '/uploadImage', taskController.uploadImage )
11
12
  .post( '/updateStatus', taskController.updateStatus )
@@ -0,0 +1,7 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export async function find( query = {}, field={} ) {
4
+ return await model.checklistconfigModel.find( query, field );
5
+ }
6
+
7
+
@@ -0,0 +1,17 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export async function create( data ) {
4
+ return model.taskProcessedModel.create( data );
5
+ }
6
+
7
+ export async function findOne( query = {}, field = {} ) {
8
+ return model.taskProcessedModel.findOne( query, field );
9
+ }
10
+
11
+ export async function updateOne( query = {}, record = {} ) {
12
+ return model.taskProcessedModel.updateOne( query, { $set: record }, { upsert: true } );
13
+ }
14
+
15
+ export async function find( query = {}, field = {} ) {
16
+ return model.taskProcessedModel.find( query, field );
17
+ }
@@ -1,17 +1,17 @@
1
1
  import model from 'tango-api-schema';
2
2
 
3
3
  export async function create( data ) {
4
- return model.taskProcessedModel.create( data );
4
+ return model.processedchecklistModel.create( data );
5
5
  }
6
6
 
7
7
  export async function findOne( query = {}, field = {} ) {
8
- return model.taskProcessedModel.findOne( query, field );
8
+ return model.processedchecklistModel.findOne( query, field );
9
9
  }
10
10
 
11
11
  export async function updateOne( query = {}, record = {} ) {
12
- return model.taskProcessedModel.updateOne( query, { $set: record }, { upsert: true } );
12
+ return model.processedchecklistModel.updateOne( query, { $set: record }, { upsert: true } );
13
13
  }
14
14
 
15
15
  export async function find( query = {}, field = {} ) {
16
- return model.taskProcessedModel.find( query, field );
16
+ return model.processedchecklistModel.find( query, field );
17
17
  }