tango-app-api-store-builder 1.0.0-beta-22 → 1.0.0-beta-25

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.
@@ -0,0 +1,317 @@
1
+ import * as taskService from '../service/task.service.js';
2
+ import * as processedService from '../service/processedchecklist.service.js';
3
+ import * as storeService from '../service/store.service.js';
4
+ import * as userService from '../service/user.service.js';
5
+ import dayjs from 'dayjs';
6
+ import { logger, fileUpload, signedUrl } from 'tango-app-api-middleware';
7
+ import * as planoTaskService from '../service/planoTask.service.js';
8
+
9
+ async function createUser( data ) {
10
+ try {
11
+ let params = {
12
+ userName: data.userName,
13
+ email: data.email,
14
+ mobileNumber: data?.mobileNumber || '',
15
+ clientId: data.clientId,
16
+ role: 'user',
17
+ password: '5dqFKAJj29PsV6P+kL+3Dw==',
18
+ isActive: true,
19
+ userType: 'client',
20
+ rolespermission: [
21
+ {
22
+ featureName: 'Global',
23
+ modules: [
24
+ {
25
+ name: 'Store',
26
+ isAdd: false,
27
+ isEdit: false,
28
+
29
+ },
30
+ {
31
+ name: 'User',
32
+ isAdd: false,
33
+ isEdit: false,
34
+
35
+ },
36
+ {
37
+ name: 'Camera',
38
+ isAdd: false,
39
+ isEdit: false,
40
+
41
+ },
42
+ {
43
+ name: 'Configuration',
44
+ isAdd: false,
45
+ isEdit: false,
46
+
47
+ },
48
+ {
49
+ name: 'Subscription',
50
+ isAdd: false,
51
+ isEdit: false,
52
+
53
+ },
54
+ {
55
+ name: 'Billing',
56
+ isAdd: false,
57
+ isEdit: false,
58
+
59
+ },
60
+ ],
61
+ },
62
+ {
63
+ featurName: 'TangoEye',
64
+ modules: [
65
+ {
66
+ name: 'ZoneTag',
67
+ isAdd: false,
68
+ isEdit: false,
69
+
70
+ },
71
+ ],
72
+ },
73
+ {
74
+ featurName: 'TangoTrax',
75
+ modules: [
76
+ {
77
+ name: 'checklist',
78
+ isAdd: false,
79
+ isEdit: false,
80
+
81
+ },
82
+ {
83
+ name: 'Task',
84
+ isAdd: false,
85
+ isEdit: false,
86
+
87
+ },
88
+ ],
89
+ },
90
+ ],
91
+ };
92
+ let response = await userService.create( params );
93
+ return response;
94
+ } catch ( e ) {
95
+ logger.error( 'createUser =>', e );
96
+ return false;
97
+ }
98
+ }
99
+
100
+ export async function createTask( req, res ) {
101
+ try {
102
+ let taskDetails = await taskService.find( { isPlano: true, client_id: req.body.clientId } );
103
+ let storeList = req.body.stores.map( ( ele ) => ele.toLowerCase() );
104
+ let userDetails;
105
+ if ( !taskDetails.length ) {
106
+ return res.sendError( 'No data found', 204 );
107
+ }
108
+ await Promise.all( taskDetails.map( async ( task ) => {
109
+ let processedList = await processedService.findOne( { sourceCheckList_id: task._id, checklistStatus: 'submit' } );
110
+ if ( !processedList ) {
111
+ let data = {
112
+ client_id: req.body.clientId,
113
+ date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
114
+ date_string: dayjs().format( 'YYYY-MM-DD' ),
115
+ sourceCheckList_id: task._id,
116
+ checkListName: task.checkListName,
117
+ scheduleStartTime: '12:00 AM',
118
+ scheduleEndTime: '11:59 PM',
119
+ scheduleStartTime_iso: dayjs.utc( '12:00 AM', 'hh:mm A' ).format(),
120
+ scheduleEndTime_iso: dayjs.utc( '11:59 PM', 'hh:mm A' ).format(),
121
+ allowedOverTime: false,
122
+ allowedStoreLocation: false,
123
+ createdBy: task.createdBy,
124
+ createdByName: task.createdByName,
125
+ questionAnswers: [],
126
+ isdeleted: false,
127
+ questionCount: 0,
128
+ storeCount: 0,
129
+ locationCount: 0,
130
+ checkListType: 'task',
131
+ country: '',
132
+ store_id: '',
133
+ storeName: '',
134
+ userId: '',
135
+ userName: '',
136
+ userEmail: '',
137
+ checklistStatus: 'open',
138
+ timeFlagStatus: true,
139
+ timeFlag: 0,
140
+ questionFlag: 0,
141
+ mobileDetectionFlag: 0,
142
+ storeOpenCloseFlag: 0,
143
+ reinitiateStatus: false,
144
+ markasread: false,
145
+ uniformDetectionFlag: 0,
146
+ scheduleRepeatedType: 'daily',
147
+ approvalStatus: false,
148
+ approvalEnable: false,
149
+ redoStatus: false,
150
+ isPlano: true,
151
+ };
152
+ let query = [
153
+ {
154
+ $addFields: {
155
+ store: { $toLower: '$storeName' },
156
+ },
157
+ },
158
+ {
159
+ $match: {
160
+ clientId: req.body.clientId,
161
+ store: { $in: storeList },
162
+ },
163
+ },
164
+ ];
165
+
166
+ let storeDetails = await storeService.aggregate( query );
167
+ if ( req.body.userEmail ) {
168
+ let query = [
169
+ {
170
+ $addFields: {
171
+ emailLower: { $toLower: '$email' },
172
+ },
173
+ },
174
+ {
175
+ $match: {
176
+ clientId: req.body.clientId,
177
+ emailLower: req.body.userEmail,
178
+ },
179
+ },
180
+ ];
181
+ userDetails = await userService.aggregate( query );
182
+ if ( !userDetails.length ) {
183
+ let userData = {
184
+ clientId: req.body.clientId,
185
+ mobileNumber: '',
186
+ email: req.body.userEmail,
187
+ userName: req.body.userEmail.split( '@' )[0],
188
+ };
189
+ userDetails = await createUser( userData );
190
+ } else {
191
+ userDetails = userDetails[0];
192
+ }
193
+ }
194
+ if ( !req.body.userEmail ) {
195
+ await Promise.all( storeDetails.map( async ( store ) => {
196
+ userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email } );
197
+ if ( !userDetails ) {
198
+ let userData = {
199
+ clientId: req.body.clientId,
200
+ mobileNumber: store?.spocDetails?.[0]?.contact,
201
+ email: store?.spocDetails?.[0]?.email,
202
+ userName: store?.spocDetails?.[0]?.name,
203
+ };
204
+ userDetails = await createUser( userData );
205
+ }
206
+ let taskData = { ...data };
207
+ taskData.store_id = store.storeId;
208
+ taskData.storeName = store.storeName;
209
+ taskData.userId = userDetails._id;
210
+ taskData.userName = userDetails.userName;
211
+ taskData.userEmail = userDetails.email;
212
+ await processedService.create( taskData );
213
+ } ) );
214
+ }
215
+ }
216
+ } ) );
217
+
218
+ return res.sendSuccess( 'Task created successfully' );
219
+ } catch ( e ) {
220
+ logger.error( { functionName: 'createTask', error: e } );
221
+ return res.sendError( e, 500 );
222
+ }
223
+ }
224
+
225
+ export async function getTaskDetails( req, res ) {
226
+ try {
227
+ if ( !req.query.storeId ) {
228
+ return res.sendError( 'Store id is required' );
229
+ }
230
+ let date = req.query?.date || dayjs().format( 'YYYY-MM-DD' );
231
+ let getDetails = await processedService.find( { store_id: req.query.storeId, date_string: date, isPlano: true, checklistStatus: 'open' }, { checkListName: 1 } );
232
+ return res.sendSuccess( getDetails );
233
+ } catch ( e ) {
234
+ logger.error( { functionName: 'getTaskDetails', error: e } );
235
+ return res.sendError( e, 500 );
236
+ }
237
+ }
238
+
239
+ export async function uploadImage( req, res ) {
240
+ try {
241
+ if ( !req.body.taskId ) {
242
+ return res.sendError( 'task id is required', 400 );
243
+ }
244
+ if ( !req.body.qno ) {
245
+ return res.sendError( 'Qno is required', 400 );
246
+ }
247
+ if ( !req.files.file ) {
248
+ return res.sendError( 'Please upload a file', 400 );
249
+ }
250
+
251
+ let params = {
252
+ Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
253
+ Key: `${req.body.taskId}/${req.body.qno}/${dayjs().format()}`,
254
+ fileName: req.files.file.name,
255
+ ContentType: req.files.file.mimeType,
256
+ body: req.files.file.data,
257
+ };
258
+ let fileRes = await fileUpload( params );
259
+ if ( fileRes.Key ) {
260
+ params = {
261
+ Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
262
+ file_path: fileRes.Key,
263
+ };
264
+
265
+ let imageUrl = await signedUrl( params );
266
+ return res.sendSuccess( { url: imageUrl, path: fileRes.Key } );
267
+ }
268
+ return res.sendError( 'Something went wrong', 500 );
269
+ } catch ( e ) {
270
+ logger.error( { functionName: 'uploadImage', error: e } );
271
+ return res.sendError( e, 500 );
272
+ }
273
+ }
274
+
275
+ export async function updateStatus( req, res ) {
276
+ try {
277
+ if ( !req.body.taskId ) {
278
+ return res.sendError( 'No data found', 204 );
279
+ }
280
+ if ( !req.body.status ) {
281
+ return res.sendError( 'Status is required' );
282
+ }
283
+ let taskDetails = await processedService.findOne( { _id: req.body.taskId } );
284
+ if ( !taskDetails ) {
285
+ return res.sendError( 'No data found', 204 );
286
+ }
287
+ taskDetails.checklistStatus = req.body.status;
288
+ taskDetails.save();
289
+ return res.sendSuccess( 'Task status updated successfully' );
290
+ } catch ( e ) {
291
+ logger.error( { functionName: 'storeLayout', error: e } );
292
+ return res.sendError( e, 500 );
293
+ }
294
+ }
295
+
296
+ export async function updateAnswers( req, res ) {
297
+ try {
298
+ if ( !req.body.fixtureId ) {
299
+ return res.sendError( 'No data found', 204 );
300
+ }
301
+
302
+ let data = {
303
+ fixtureId: req.body.fixtureId,
304
+ answers: req.body.answers,
305
+ status: req.body.answers?.find( ( ans ) => !ans.answer ) ? 'incomplete' : 'complete',
306
+ planoId: req.body.planoId,
307
+ floorId: req.body.floorId,
308
+ type: req.body.type,
309
+ };
310
+
311
+ await planoTaskService.updateOne( { fixtureId: req.body.fixtureId, type: req.body.type }, data );
312
+ return res.sendSuccess( 'Fixture details updated successfully' );
313
+ } catch ( e ) {
314
+ logger.error( { functionName: 'updateAnswers', error: e } );
315
+ return res.sendError( e, 500 );
316
+ }
317
+ }
@@ -25,6 +25,9 @@ storeBuilderRouter
25
25
  .post( '/FixtureShelfDetails', validate( validateDtos.fixtureShelfProduct ), storeBuilderController.fixtureShelfProductv1 )
26
26
  .post( '/scan', storeBuilderController.scanv1 )
27
27
  .post( '/updateMissing', storeBuilderController.updateMissing )
28
- .post( '/bulkFixtureUpload', storeBuilderController.bulkFixtureUpload );
28
+ .post( '/bulkFixtureUpload', storeBuilderController.bulkFixtureUpload )
29
+ .post( '/uploadImage', storeBuilderController.uploadImage )
30
+ .post( '/storeFixturesTask', storeBuilderController.storeFixturesTask );
31
+
29
32
 
30
33
 
@@ -0,0 +1,12 @@
1
+ import express from 'express';
2
+ // import { isAllowedSessionHandler } from 'tango-app-api-middleware';
3
+ import * as taskController from '../controllers/task.controller.js';
4
+
5
+ export const taskRouter = express.Router();
6
+
7
+ taskRouter
8
+ .post( '/createTask', taskController.createTask )
9
+ .get( '/taskDetails', taskController.getTaskDetails )
10
+ .post( '/uploadImage', taskController.uploadImage )
11
+ .post( '/updateStatus', taskController.updateStatus )
12
+ .post( '/updateAnswers', taskController.updateAnswers );
@@ -23,3 +23,7 @@ export async function updateOne( query, record ) {
23
23
  export async function create( data ) {
24
24
  return model.fixtureShelfModel.create( data );
25
25
  }
26
+
27
+ export async function count( data ) {
28
+ return model.fixtureShelfModel.countDocuments( data );
29
+ }
@@ -0,0 +1,17 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export async function create( data ) {
4
+ return model.planoTaskCompliance.create( data );
5
+ }
6
+
7
+ export async function updateOne( query={}, record={} ) {
8
+ return model.planoTaskCompliance.updateOne( query, { $set: record }, { upsert: true } );
9
+ }
10
+
11
+ export async function count( data ) {
12
+ return model.planoTaskCompliance.countDocuments( data );
13
+ }
14
+
15
+ export async function findOne( query={}, field={} ) {
16
+ return model.planoTaskCompliance.findOne( query, field );
17
+ }
@@ -0,0 +1,13 @@
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 find( query = {}, field = {} ) {
12
+ return model.taskProcessedModel.find( query, field );
13
+ }
@@ -0,0 +1,6 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export async function find( query = {}, field={} ) {
4
+ return await model.taskConfigModel.find( query, field );
5
+ }
6
+
@@ -0,0 +1,14 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export async function findOne( query = {}, field={} ) {
4
+ return await model.userModel.findOne( query, field );
5
+ }
6
+
7
+ export const aggregate = async ( query = {} ) => {
8
+ return model.userModel.aggregate( query );
9
+ };
10
+
11
+ export async function create( data ) {
12
+ return model.userModel.create( data );
13
+ }
14
+