tango-app-api-store-builder 1.0.15 → 1.0.16
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as floorService from '../service/storeBuilder.service.js';
|
|
2
|
-
import { logger, insertOpenSearchData, getOpenSearchData
|
|
2
|
+
import { logger, insertOpenSearchData, getOpenSearchData } from 'tango-app-api-middleware';
|
|
3
3
|
// import * as storeService from '../service/store.service.js';
|
|
4
4
|
import * as planoService from '../service/planogram.service.js';
|
|
5
5
|
import * as storeFixtureService from '../service/storeFixture.service.js';
|
|
@@ -18,67 +18,64 @@ import mongoose from 'mongoose';
|
|
|
18
18
|
import * as planoRevisionService from '../service/planoRevision.service.js';
|
|
19
19
|
import * as planoVmDuplicateService from '../service/planoVmDuplicate.service.js';
|
|
20
20
|
import * as vmTypeService from '../service/vmType.service.js';
|
|
21
|
-
|
|
22
|
-
import * as processedChecklistService from '../service/processedchecklist.service.js';
|
|
23
|
-
|
|
24
|
-
export async function getplanoFeedback(req, res) {
|
|
21
|
+
export async function getplanoFeedback( req, res ) {
|
|
25
22
|
try {
|
|
26
|
-
const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : ['layout', 'fixture', 'vm'];
|
|
23
|
+
const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : [ 'layout', 'fixture', 'vm' ];
|
|
27
24
|
const filterByStatus = req.body.filterByStatus || [];
|
|
28
25
|
const filterByApprovalStatus = req.body.filterByApprovalStatus || '';
|
|
29
26
|
const resultMap = {};
|
|
30
27
|
const commentMap = {};
|
|
31
28
|
await Promise.all(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
29
|
+
taskTypes.map( async ( type, index ) => {
|
|
30
|
+
const pipeline = buildPipelineByType( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask );
|
|
31
|
+
|
|
32
|
+
let data = await planoTaskService.aggregate( pipeline );
|
|
33
|
+
if ( filterByApprovalStatus && filterByApprovalStatus?.length ) {
|
|
34
|
+
if ( type == 'fixture' ) {
|
|
35
|
+
let pendingData = [];
|
|
36
|
+
let agreeData = [];
|
|
37
|
+
let disAgreeData = [];
|
|
38
|
+
if ( filterByApprovalStatus.includes( 'pending' ) ) {
|
|
39
|
+
pendingData = data.filter( ( element ) => {
|
|
40
|
+
return element?.approvalStatus == 'pending';
|
|
41
|
+
} );
|
|
42
|
+
} if ( filterByApprovalStatus.includes( 'agree' ) ) {
|
|
43
|
+
agreeData = data.filter( ( element ) => {
|
|
44
|
+
return element?.answers?.[0]?.status == 'agree';
|
|
45
|
+
} );
|
|
46
|
+
} if ( filterByApprovalStatus.includes( 'disagree' ) ) {
|
|
47
|
+
disAgreeData = data.filter( ( element ) => {
|
|
48
|
+
return element?.answers?.[0]?.status == 'disagree';
|
|
49
|
+
} );
|
|
50
|
+
}
|
|
51
|
+
data = [ ...pendingData, ...agreeData, ...disAgreeData ];
|
|
52
|
+
} else {
|
|
53
|
+
data.forEach( ( element ) => {
|
|
54
|
+
element.answers?.forEach( ( ans ) => {
|
|
55
|
+
ans.issues = ans.issues?.filter(
|
|
56
|
+
( issue ) => issue.Details && issue.Details.length > 0,
|
|
57
|
+
);
|
|
58
|
+
} );
|
|
59
|
+
element.answers = element.answers?.filter(
|
|
60
|
+
( ans ) => ans.issues && ans.issues.length > 0,
|
|
60
61
|
);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
} );
|
|
63
|
+
}
|
|
64
|
+
data = data.filter(
|
|
65
|
+
( element ) => element.answers && element.answers.length > 0,
|
|
66
|
+
);
|
|
66
67
|
}
|
|
67
|
-
data = data.filter(
|
|
68
|
-
(element) => element.answers && element.answers.length > 0,
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
68
|
|
|
72
69
|
|
|
73
|
-
|
|
70
|
+
resultMap[type] = data;
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
const comments = await planoGlobalCommentService.find( {
|
|
73
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
74
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
75
|
+
taskType: type,
|
|
76
|
+
} );
|
|
77
|
+
commentMap[type] = comments;
|
|
78
|
+
} ),
|
|
82
79
|
);
|
|
83
80
|
|
|
84
81
|
const response = {
|
|
@@ -90,8 +87,8 @@ export async function getplanoFeedback(req, res) {
|
|
|
90
87
|
vmComment: commentMap['vm'] || [],
|
|
91
88
|
};
|
|
92
89
|
|
|
93
|
-
response.fixtureData = await Promise.all(response.fixtureData.map(async (ele) => {
|
|
94
|
-
if (ele?.FixtureData && ele?.FixtureData?._id) {
|
|
90
|
+
response.fixtureData = await Promise.all( response.fixtureData.map( async ( ele ) => {
|
|
91
|
+
if ( ele?.FixtureData && ele?.FixtureData?._id ) {
|
|
95
92
|
// if ( !ele?.FixtureData._id ) {
|
|
96
93
|
// return res.sendError( 'Fixture Id is required', 400 );
|
|
97
94
|
// }
|
|
@@ -113,10 +110,10 @@ export async function getplanoFeedback(req, res) {
|
|
|
113
110
|
};
|
|
114
111
|
|
|
115
112
|
|
|
116
|
-
let aiDetails = await getOpenSearchData(JSON.parse(process.env.OPENSEARCH).planoAIValidation, query);
|
|
117
|
-
if (aiDetails.statusCode == 200) {
|
|
113
|
+
let aiDetails = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).planoAIValidation, query );
|
|
114
|
+
if ( aiDetails.statusCode == 200 ) {
|
|
118
115
|
let data = {};
|
|
119
|
-
if (aiDetails?.body?.hits?.hits.length) {
|
|
116
|
+
if ( aiDetails?.body?.hits?.hits.length ) {
|
|
120
117
|
data = aiDetails?.body?.hits?.hits?.[0]?._source;
|
|
121
118
|
delete data.isEmpty;
|
|
122
119
|
delete data.fixtureFound;
|
|
@@ -125,52 +122,52 @@ export async function getplanoFeedback(req, res) {
|
|
|
125
122
|
}
|
|
126
123
|
}
|
|
127
124
|
return ele;
|
|
128
|
-
}));
|
|
125
|
+
} ) );
|
|
129
126
|
|
|
130
|
-
res.sendSuccess(response);
|
|
131
|
-
} catch (e) {
|
|
132
|
-
logger.error({ functionName: 'getplanoFeedback', error: e, message: req.body });
|
|
133
|
-
return res.sendError(e, 500);
|
|
127
|
+
res.sendSuccess( response );
|
|
128
|
+
} catch ( e ) {
|
|
129
|
+
logger.error( { functionName: 'getplanoFeedback', error: e, message: req.body } );
|
|
130
|
+
return res.sendError( e, 500 );
|
|
134
131
|
}
|
|
135
132
|
}
|
|
136
|
-
export async function getplanoFeedbackv1(req, res) {
|
|
133
|
+
export async function getplanoFeedbackv1( req, res ) {
|
|
137
134
|
try {
|
|
138
|
-
const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : ['layout', 'fixture', 'vm'];
|
|
135
|
+
const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : [ 'layout', 'fixture', 'vm' ];
|
|
139
136
|
const filterByStatus = req.body.filterByStatus || [];
|
|
140
137
|
const filterByApprovalStatus = req.body.filterByApprovalStatus || '';
|
|
141
138
|
const resultMap = {};
|
|
142
139
|
const commentMap = {};
|
|
143
140
|
await Promise.all(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
141
|
+
taskTypes.map( async ( type, index ) => {
|
|
142
|
+
const pipeline = buildPipelineByType1( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask );
|
|
143
|
+
|
|
144
|
+
let data = await planoTaskService.aggregate( pipeline );
|
|
145
|
+
if ( filterByApprovalStatus && filterByApprovalStatus !== '' ) {
|
|
146
|
+
data.forEach( ( element ) => {
|
|
147
|
+
element.answers?.forEach( ( ans ) => {
|
|
148
|
+
ans.issues = ans.issues?.filter(
|
|
149
|
+
( issue ) => issue.Details && issue.Details.length > 0,
|
|
150
|
+
);
|
|
151
|
+
} );
|
|
152
|
+
element.answers = element.answers?.filter(
|
|
153
|
+
( ans ) => ans.issues && ans.issues.length > 0,
|
|
153
154
|
);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
} );
|
|
156
|
+
data = data.filter(
|
|
157
|
+
( element ) => element.answers && element.answers.length > 0,
|
|
157
158
|
);
|
|
158
|
-
}
|
|
159
|
-
data = data.filter(
|
|
160
|
-
(element) => element.answers && element.answers.length > 0,
|
|
161
|
-
);
|
|
162
|
-
}
|
|
159
|
+
}
|
|
163
160
|
|
|
164
161
|
|
|
165
|
-
|
|
162
|
+
resultMap[type] = data;
|
|
166
163
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
164
|
+
const comments = await planoGlobalCommentService.find( {
|
|
165
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
166
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
167
|
+
taskType: type,
|
|
168
|
+
} );
|
|
169
|
+
commentMap[type] = comments;
|
|
170
|
+
} ),
|
|
174
171
|
);
|
|
175
172
|
|
|
176
173
|
const response = {
|
|
@@ -182,41 +179,41 @@ export async function getplanoFeedbackv1(req, res) {
|
|
|
182
179
|
vmComment: commentMap['vm'] || [],
|
|
183
180
|
};
|
|
184
181
|
|
|
185
|
-
res.sendSuccess(response);
|
|
186
|
-
} catch (e) {
|
|
187
|
-
logger.error({ functionName: 'getplanoFeedback', error: e, message: req.body });
|
|
188
|
-
return res.sendError(e, 500);
|
|
182
|
+
res.sendSuccess( response );
|
|
183
|
+
} catch ( e ) {
|
|
184
|
+
logger.error( { functionName: 'getplanoFeedback', error: e, message: req.body } );
|
|
185
|
+
return res.sendError( e, 500 );
|
|
189
186
|
}
|
|
190
187
|
}
|
|
191
188
|
|
|
192
|
-
function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0) {
|
|
189
|
+
function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0 ) {
|
|
193
190
|
const matchStage = {
|
|
194
191
|
$match: {
|
|
195
|
-
planoId: new mongoose.Types.ObjectId(planoId),
|
|
196
|
-
floorId: new mongoose.Types.ObjectId(floorId),
|
|
192
|
+
planoId: new mongoose.Types.ObjectId( planoId ),
|
|
193
|
+
floorId: new mongoose.Types.ObjectId( floorId ),
|
|
197
194
|
type: type,
|
|
198
|
-
...(taskId && { taskId: new mongoose.Types.ObjectId(taskId) }),
|
|
199
|
-
...(filterByStatus?.length ? { status: { $in: filterByStatus } } : {}),
|
|
195
|
+
...( taskId && { taskId: new mongoose.Types.ObjectId( taskId ) } ),
|
|
196
|
+
...( filterByStatus?.length ? { status: { $in: filterByStatus } } : {} ),
|
|
200
197
|
},
|
|
201
198
|
};
|
|
202
199
|
|
|
203
200
|
|
|
204
201
|
const conditionalMatchExpr = showtask ?
|
|
205
202
|
{
|
|
206
|
-
$eq: ['$_id', '$$taskId'],
|
|
203
|
+
$eq: [ '$_id', '$$taskId' ],
|
|
207
204
|
} :
|
|
208
205
|
{
|
|
209
206
|
$and: [
|
|
210
207
|
{
|
|
211
|
-
$eq: ['$_id', '$$taskId'],
|
|
208
|
+
$eq: [ '$_id', '$$taskId' ],
|
|
212
209
|
},
|
|
213
210
|
{
|
|
214
211
|
$or: [
|
|
215
|
-
{ $eq: ['$redoStatus', true] },
|
|
212
|
+
{ $eq: [ '$redoStatus', true ] },
|
|
216
213
|
{
|
|
217
214
|
$and: [
|
|
218
|
-
{ $eq: ['$redoStatus', false] },
|
|
219
|
-
{ $eq: ['$checklistStatus', 'submit'] },
|
|
215
|
+
{ $eq: [ '$redoStatus', false ] },
|
|
216
|
+
{ $eq: [ '$checklistStatus', 'submit' ] },
|
|
220
217
|
],
|
|
221
218
|
},
|
|
222
219
|
],
|
|
@@ -257,7 +254,7 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
|
|
|
257
254
|
let: { fixtureId: '$fixtureId' },
|
|
258
255
|
pipeline: [
|
|
259
256
|
{
|
|
260
|
-
$match: { $expr: { $eq: ['$_id', '$$fixtureId'] } },
|
|
257
|
+
$match: { $expr: { $eq: [ '$_id', '$$fixtureId' ] } },
|
|
261
258
|
},
|
|
262
259
|
],
|
|
263
260
|
as: 'FixtureData',
|
|
@@ -272,7 +269,7 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
|
|
|
272
269
|
let: { fixtureId: '$FixtureData._id' },
|
|
273
270
|
pipeline: [
|
|
274
271
|
{
|
|
275
|
-
$match: { $expr: { $eq: ['$fixtureId', '$$fixtureId'] } },
|
|
272
|
+
$match: { $expr: { $eq: [ '$fixtureId', '$$fixtureId' ] } },
|
|
276
273
|
},
|
|
277
274
|
],
|
|
278
275
|
as: 'Fixtureshelves',
|
|
@@ -284,21 +281,9 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
|
|
|
284
281
|
'FixtureData.shelfConfig': '$Fixtureshelves',
|
|
285
282
|
},
|
|
286
283
|
},
|
|
287
|
-
|
|
288
|
-
{
|
|
289
|
-
$set: {
|
|
290
|
-
'FixtureData.shelfConfig': {
|
|
291
|
-
$sortArray: {
|
|
292
|
-
input: '$FixtureData.shelfConfig',
|
|
293
|
-
sortBy: { shelfNumber: 1 },
|
|
294
|
-
},
|
|
295
|
-
},
|
|
296
|
-
},
|
|
297
|
-
}
|
|
298
|
-
|
|
299
284
|
];
|
|
300
285
|
|
|
301
|
-
const vmStages = ['vm', 'vmRollout'].includes(type) ? [
|
|
286
|
+
const vmStages = [ 'vm', 'vmRollout' ].includes( type ) ? [
|
|
302
287
|
{
|
|
303
288
|
$unwind: { path: '$FixtureData.vmConfig', preserveNullAndEmptyArrays: true },
|
|
304
289
|
},
|
|
@@ -308,7 +293,7 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
|
|
|
308
293
|
let: { vmId: '$FixtureData.vmConfig.vmId' },
|
|
309
294
|
pipeline: [
|
|
310
295
|
{
|
|
311
|
-
$match: { $expr: { $eq: ['$_id', '$$vmId'] } },
|
|
296
|
+
$match: { $expr: { $eq: [ '$_id', '$$vmId' ] } },
|
|
312
297
|
},
|
|
313
298
|
{
|
|
314
299
|
$project: { vmName: 1, vmType: 1 },
|
|
@@ -345,7 +330,7 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
|
|
|
345
330
|
collectedVmConfigs: {
|
|
346
331
|
$push: {
|
|
347
332
|
$cond: [
|
|
348
|
-
{ $ne: ['$FixtureData.vmConfig', {}] },
|
|
333
|
+
{ $ne: [ '$FixtureData.vmConfig', {} ] },
|
|
349
334
|
'$FixtureData.vmConfig',
|
|
350
335
|
'$$REMOVE',
|
|
351
336
|
],
|
|
@@ -366,8 +351,8 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
|
|
|
366
351
|
in: {
|
|
367
352
|
$cond: [
|
|
368
353
|
{ $isArray: '$$this' },
|
|
369
|
-
{ $concatArrays: ['$$value', '$$this'] },
|
|
370
|
-
{ $concatArrays: ['$$value', ['$$this']] },
|
|
354
|
+
{ $concatArrays: [ '$$value', '$$this' ] },
|
|
355
|
+
{ $concatArrays: [ '$$value', [ '$$this' ] ] },
|
|
371
356
|
],
|
|
372
357
|
},
|
|
373
358
|
},
|
|
@@ -388,89 +373,89 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
|
|
|
388
373
|
...vmStages,
|
|
389
374
|
{ $sort: { _id: -1 } },
|
|
390
375
|
];
|
|
391
|
-
if (filterByApprovalStatus && filterByApprovalStatus != '' && type !== 'fixture') {
|
|
376
|
+
if ( filterByApprovalStatus && filterByApprovalStatus != '' && type !== 'fixture' ) {
|
|
392
377
|
pipeline = [];
|
|
393
|
-
pipeline.push(matchStage);
|
|
378
|
+
pipeline.push( matchStage );
|
|
394
379
|
pipeline.push(
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
{ $eq: ['$$detail.status', 'pending'] } :
|
|
419
|
-
{ $ne: ['$$detail.status', 'pending'] },
|
|
380
|
+
{
|
|
381
|
+
$addFields: {
|
|
382
|
+
answers: {
|
|
383
|
+
$map: {
|
|
384
|
+
input: '$answers',
|
|
385
|
+
as: 'ans',
|
|
386
|
+
in: {
|
|
387
|
+
$mergeObjects: [
|
|
388
|
+
'$$ans',
|
|
389
|
+
{
|
|
390
|
+
issues: {
|
|
391
|
+
$map: {
|
|
392
|
+
input: '$$ans.issues',
|
|
393
|
+
as: 'issue',
|
|
394
|
+
in: {
|
|
395
|
+
$mergeObjects: [
|
|
396
|
+
'$$issue',
|
|
397
|
+
{
|
|
398
|
+
Details: {
|
|
399
|
+
$filter: {
|
|
400
|
+
input: '$$issue.Details',
|
|
401
|
+
as: 'detail',
|
|
402
|
+
cond: filterByApprovalStatus === 'pending' ?
|
|
403
|
+
{ $eq: [ '$$detail.status', 'pending' ] } :
|
|
404
|
+
{ $ne: [ '$$detail.status', 'pending' ] },
|
|
405
|
+
},
|
|
420
406
|
},
|
|
421
407
|
},
|
|
422
|
-
|
|
423
|
-
|
|
408
|
+
],
|
|
409
|
+
},
|
|
424
410
|
},
|
|
425
411
|
},
|
|
426
412
|
},
|
|
427
|
-
|
|
428
|
-
|
|
413
|
+
],
|
|
414
|
+
},
|
|
429
415
|
},
|
|
430
416
|
},
|
|
431
417
|
},
|
|
432
418
|
},
|
|
433
|
-
},
|
|
434
419
|
);
|
|
435
|
-
pipeline.push(taskLookup);
|
|
436
|
-
pipeline.push(unwindTask);
|
|
437
|
-
pipeline.push(...commonLookups);
|
|
438
|
-
pipeline.push(...vmStages);
|
|
439
|
-
pipeline.push({ $sort: { _id: -1 } });
|
|
420
|
+
pipeline.push( taskLookup );
|
|
421
|
+
pipeline.push( unwindTask );
|
|
422
|
+
pipeline.push( ...commonLookups );
|
|
423
|
+
pipeline.push( ...vmStages );
|
|
424
|
+
pipeline.push( { $sort: { _id: -1 } } );
|
|
440
425
|
}
|
|
441
426
|
|
|
442
427
|
|
|
443
428
|
return pipeline;
|
|
444
429
|
}
|
|
445
430
|
|
|
446
|
-
function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0) {
|
|
431
|
+
function buildPipelineByType1( type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0 ) {
|
|
447
432
|
const matchStage = {
|
|
448
433
|
$match: {
|
|
449
|
-
planoId: new mongoose.Types.ObjectId(planoId),
|
|
450
|
-
floorId: new mongoose.Types.ObjectId(floorId),
|
|
434
|
+
planoId: new mongoose.Types.ObjectId( planoId ),
|
|
435
|
+
floorId: new mongoose.Types.ObjectId( floorId ),
|
|
451
436
|
type: type,
|
|
452
|
-
...(taskId && { taskId: new mongoose.Types.ObjectId(taskId) }),
|
|
453
|
-
...(filterByStatus?.length ? { status: { $in: filterByStatus } } : {}),
|
|
437
|
+
...( taskId && { taskId: new mongoose.Types.ObjectId( taskId ) } ),
|
|
438
|
+
...( filterByStatus?.length ? { status: { $in: filterByStatus } } : {} ),
|
|
454
439
|
},
|
|
455
440
|
};
|
|
456
441
|
|
|
457
442
|
|
|
458
443
|
const conditionalMatchExpr = showtask ?
|
|
459
444
|
{
|
|
460
|
-
$eq: ['$_id', '$$taskId'],
|
|
445
|
+
$eq: [ '$_id', '$$taskId' ],
|
|
461
446
|
} :
|
|
462
447
|
{
|
|
463
448
|
$and: [
|
|
464
449
|
{
|
|
465
|
-
$eq: ['$_id', '$$taskId'],
|
|
450
|
+
$eq: [ '$_id', '$$taskId' ],
|
|
466
451
|
},
|
|
467
452
|
{
|
|
468
453
|
$or: [
|
|
469
|
-
{ $eq: ['$redoStatus', true] },
|
|
454
|
+
{ $eq: [ '$redoStatus', true ] },
|
|
470
455
|
{
|
|
471
456
|
$and: [
|
|
472
|
-
{ $eq: ['$redoStatus', false] },
|
|
473
|
-
{ $eq: ['$checklistStatus', 'submit'] },
|
|
457
|
+
{ $eq: [ '$redoStatus', false ] },
|
|
458
|
+
{ $eq: [ '$checklistStatus', 'submit' ] },
|
|
474
459
|
],
|
|
475
460
|
},
|
|
476
461
|
],
|
|
@@ -511,7 +496,7 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
|
|
|
511
496
|
let: { fixtureId: '$fixtureId' },
|
|
512
497
|
pipeline: [
|
|
513
498
|
{
|
|
514
|
-
$match: { $expr: { $eq: ['$_id', '$$fixtureId'] } },
|
|
499
|
+
$match: { $expr: { $eq: [ '$_id', '$$fixtureId' ] } },
|
|
515
500
|
},
|
|
516
501
|
],
|
|
517
502
|
as: 'FixtureData',
|
|
@@ -526,7 +511,7 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
|
|
|
526
511
|
let: { fixtureId: '$FixtureData._id' },
|
|
527
512
|
pipeline: [
|
|
528
513
|
{
|
|
529
|
-
$match: { $expr: { $eq: ['$fixtureId', '$$fixtureId'] } },
|
|
514
|
+
$match: { $expr: { $eq: [ '$fixtureId', '$$fixtureId' ] } },
|
|
530
515
|
},
|
|
531
516
|
],
|
|
532
517
|
as: 'Fixtureshelves',
|
|
@@ -540,7 +525,7 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
|
|
|
540
525
|
},
|
|
541
526
|
];
|
|
542
527
|
|
|
543
|
-
const vmStages = ['vm', 'vmRollout'].includes(type) ? [
|
|
528
|
+
const vmStages = [ 'vm', 'vmRollout' ].includes( type ) ? [
|
|
544
529
|
{
|
|
545
530
|
$unwind: { path: '$FixtureData.vmConfig', preserveNullAndEmptyArrays: true },
|
|
546
531
|
},
|
|
@@ -550,7 +535,7 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
|
|
|
550
535
|
let: { vmId: '$FixtureData.vmConfig.vmId' },
|
|
551
536
|
pipeline: [
|
|
552
537
|
{
|
|
553
|
-
$match: { $expr: { $eq: ['$_id', '$$vmId'] } },
|
|
538
|
+
$match: { $expr: { $eq: [ '$_id', '$$vmId' ] } },
|
|
554
539
|
},
|
|
555
540
|
{
|
|
556
541
|
$project: { vmName: 1, vmType: 1 },
|
|
@@ -587,7 +572,7 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
|
|
|
587
572
|
collectedVmConfigs: {
|
|
588
573
|
$push: {
|
|
589
574
|
$cond: [
|
|
590
|
-
{ $ne: ['$FixtureData.vmConfig', {}] },
|
|
575
|
+
{ $ne: [ '$FixtureData.vmConfig', {} ] },
|
|
591
576
|
'$FixtureData.vmConfig',
|
|
592
577
|
'$$REMOVE',
|
|
593
578
|
],
|
|
@@ -608,8 +593,8 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
|
|
|
608
593
|
in: {
|
|
609
594
|
$cond: [
|
|
610
595
|
{ $isArray: '$$this' },
|
|
611
|
-
{ $concatArrays: ['$$value', '$$this'] },
|
|
612
|
-
{ $concatArrays: ['$$value', ['$$this']] },
|
|
596
|
+
{ $concatArrays: [ '$$value', '$$this' ] },
|
|
597
|
+
{ $concatArrays: [ '$$value', [ '$$this' ] ] },
|
|
613
598
|
],
|
|
614
599
|
},
|
|
615
600
|
},
|
|
@@ -630,136 +615,136 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
|
|
|
630
615
|
...vmStages,
|
|
631
616
|
{ $sort: { _id: -1 } },
|
|
632
617
|
];
|
|
633
|
-
if (filterByApprovalStatus && filterByApprovalStatus != '') {
|
|
618
|
+
if ( filterByApprovalStatus && filterByApprovalStatus != '' ) {
|
|
634
619
|
pipeline = [];
|
|
635
|
-
pipeline.push(matchStage);
|
|
620
|
+
pipeline.push( matchStage );
|
|
636
621
|
pipeline.push(
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
{ $eq: ['$$detail.status', 'pending'] } :
|
|
661
|
-
{ $ne: ['$$detail.status', 'pending'] },
|
|
622
|
+
{
|
|
623
|
+
$addFields: {
|
|
624
|
+
answers: {
|
|
625
|
+
$map: {
|
|
626
|
+
input: '$answers',
|
|
627
|
+
as: 'ans',
|
|
628
|
+
in: {
|
|
629
|
+
$mergeObjects: [
|
|
630
|
+
'$$ans',
|
|
631
|
+
{
|
|
632
|
+
issues: {
|
|
633
|
+
$map: {
|
|
634
|
+
input: '$$ans.issues',
|
|
635
|
+
as: 'issue',
|
|
636
|
+
in: {
|
|
637
|
+
$mergeObjects: [
|
|
638
|
+
'$$issue',
|
|
639
|
+
{
|
|
640
|
+
Details: {
|
|
641
|
+
$filter: {
|
|
642
|
+
input: '$$issue.Details',
|
|
643
|
+
as: 'detail',
|
|
644
|
+
cond: filterByApprovalStatus === 'pending' ?
|
|
645
|
+
{ $eq: [ '$$detail.status', 'pending' ] } :
|
|
646
|
+
{ $ne: [ '$$detail.status', 'pending' ] },
|
|
647
|
+
},
|
|
662
648
|
},
|
|
663
649
|
},
|
|
664
|
-
|
|
665
|
-
|
|
650
|
+
],
|
|
651
|
+
},
|
|
666
652
|
},
|
|
667
653
|
},
|
|
668
654
|
},
|
|
669
|
-
|
|
670
|
-
|
|
655
|
+
],
|
|
656
|
+
},
|
|
671
657
|
},
|
|
672
658
|
},
|
|
673
659
|
},
|
|
674
660
|
},
|
|
675
|
-
},
|
|
676
661
|
);
|
|
677
|
-
pipeline.push(taskLookup);
|
|
678
|
-
pipeline.push(unwindTask);
|
|
679
|
-
pipeline.push(...commonLookups);
|
|
680
|
-
pipeline.push(...vmStages);
|
|
681
|
-
pipeline.push({ $sort: { _id: -1 } });
|
|
662
|
+
pipeline.push( taskLookup );
|
|
663
|
+
pipeline.push( unwindTask );
|
|
664
|
+
pipeline.push( ...commonLookups );
|
|
665
|
+
pipeline.push( ...vmStages );
|
|
666
|
+
pipeline.push( { $sort: { _id: -1 } } );
|
|
682
667
|
}
|
|
683
668
|
|
|
684
669
|
|
|
685
670
|
return pipeline;
|
|
686
671
|
}
|
|
687
672
|
|
|
688
|
-
export async function getStoreFixturesfeedback(req, res) {
|
|
673
|
+
export async function getStoreFixturesfeedback( req, res ) {
|
|
689
674
|
try {
|
|
690
675
|
let query = [];
|
|
691
676
|
|
|
692
677
|
|
|
693
|
-
query.push({
|
|
678
|
+
query.push( {
|
|
694
679
|
$match: {
|
|
695
|
-
planoId: new mongoose.Types.ObjectId(req.body.planoId),
|
|
696
|
-
floorId: new mongoose.Types.ObjectId(req.body.floorId),
|
|
680
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
681
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
697
682
|
type: { $ne: 'layout' },
|
|
698
683
|
},
|
|
699
684
|
},
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
},
|
|
685
|
+
{
|
|
686
|
+
$lookup: {
|
|
687
|
+
from: 'processedtasks',
|
|
688
|
+
let: { 'taskId': '$taskId' },
|
|
689
|
+
pipeline: [
|
|
690
|
+
{
|
|
691
|
+
$match: {
|
|
692
|
+
$expr: {
|
|
693
|
+
$and: [
|
|
694
|
+
{ $eq: [ '$_id', '$$taskId' ] },
|
|
695
|
+
],
|
|
712
696
|
},
|
|
713
697
|
},
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
$project: {
|
|
701
|
+
'userName': 1,
|
|
702
|
+
'createdAt': 1,
|
|
703
|
+
'createdByName': 1,
|
|
704
|
+
'submitTime_string': 1,
|
|
721
705
|
},
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
706
|
+
},
|
|
707
|
+
],
|
|
708
|
+
as: 'taskData',
|
|
709
|
+
},
|
|
725
710
|
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
},
|
|
711
|
+
}, { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: true } },
|
|
712
|
+
{
|
|
713
|
+
$lookup: {
|
|
714
|
+
from: 'fixtureconfigs',
|
|
715
|
+
let: { 'fixtureId': '$fixtureId' },
|
|
716
|
+
pipeline: [
|
|
717
|
+
{
|
|
718
|
+
$match: {
|
|
719
|
+
$expr: {
|
|
720
|
+
$and: [
|
|
721
|
+
{ $eq: [ '$_id', '$$fixtureId' ] },
|
|
722
|
+
],
|
|
739
723
|
},
|
|
740
724
|
},
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
},
|
|
745
|
-
{
|
|
746
|
-
$unwind: { path: '$FixtureData', preserveNullAndEmptyArrays: true },
|
|
725
|
+
},
|
|
726
|
+
],
|
|
727
|
+
as: 'FixtureData',
|
|
747
728
|
},
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
$unwind: { path: '$FixtureData', preserveNullAndEmptyArrays: true },
|
|
732
|
+
},
|
|
748
733
|
);
|
|
749
734
|
|
|
750
735
|
|
|
751
|
-
let findPlanoCompliance = await planoTaskService.aggregate(query);
|
|
752
|
-
res.sendSuccess({ count: findPlanoCompliance.length, data: findPlanoCompliance });
|
|
753
|
-
} catch (e) {
|
|
754
|
-
logger.error({ functionName: 'getplanoFeedbackFixture', error: e, message: req.body });
|
|
755
|
-
return res.sendError(e, 500);
|
|
736
|
+
let findPlanoCompliance = await planoTaskService.aggregate( query );
|
|
737
|
+
res.sendSuccess( { count: findPlanoCompliance.length, data: findPlanoCompliance } );
|
|
738
|
+
} catch ( e ) {
|
|
739
|
+
logger.error( { functionName: 'getplanoFeedbackFixture', error: e, message: req.body } );
|
|
740
|
+
return res.sendError( e, 500 );
|
|
756
741
|
}
|
|
757
742
|
}
|
|
758
|
-
export async function updateStorePlano(req, res) {
|
|
743
|
+
export async function updateStorePlano( req, res ) {
|
|
759
744
|
try {
|
|
760
745
|
const { floorId, data } = req.body;
|
|
761
746
|
|
|
762
|
-
const floorData = await floorService.findOne({ _id: new mongoose.Types.ObjectId(floorId) });
|
|
747
|
+
const floorData = await floorService.findOne( { _id: new mongoose.Types.ObjectId( floorId ) } );
|
|
763
748
|
|
|
764
749
|
const additionalMeta = {
|
|
765
750
|
clientId: '11',
|
|
@@ -769,78 +754,78 @@ export async function updateStorePlano(req, res) {
|
|
|
769
754
|
floorId: floorData.toObject()._id,
|
|
770
755
|
};
|
|
771
756
|
|
|
772
|
-
const layoutPolygon = JSON.parse(JSON.stringify(data.layoutPolygon));
|
|
757
|
+
const layoutPolygon = JSON.parse( JSON.stringify( data.layoutPolygon ) );
|
|
773
758
|
|
|
774
|
-
layoutPolygon.forEach((element) => {
|
|
759
|
+
layoutPolygon.forEach( ( element ) => {
|
|
775
760
|
delete element.fixtures;
|
|
776
|
-
});
|
|
761
|
+
} );
|
|
777
762
|
|
|
778
763
|
await floorService.updateOne(
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
764
|
+
{ _id: new mongoose.Types.ObjectId( floorId ) },
|
|
765
|
+
{
|
|
766
|
+
layoutPolygon: layoutPolygon,
|
|
767
|
+
...( req.body?.editMode === true && { isEdited: true } ),
|
|
768
|
+
},
|
|
784
769
|
);
|
|
785
770
|
|
|
786
771
|
// get fixtures
|
|
787
|
-
const currentWallFixtures = data.layoutPolygon.flatMap((element) =>
|
|
788
|
-
(element.fixtures || []).map((fixture) => fixture),
|
|
772
|
+
const currentWallFixtures = data.layoutPolygon.flatMap( ( element ) =>
|
|
773
|
+
( element.fixtures || [] ).map( ( fixture ) => fixture ),
|
|
789
774
|
);
|
|
790
775
|
const currentFloorFixtures = data.centerFixture || [];
|
|
791
|
-
const currentFixtures = [...currentWallFixtures, ...currentFloorFixtures];
|
|
776
|
+
const currentFixtures = [ ...currentWallFixtures, ...currentFloorFixtures ];
|
|
792
777
|
|
|
793
|
-
const wallOtherElements = data.layoutPolygon.flatMap((element) =>
|
|
794
|
-
(element.otherElements || []).map((el) => el),
|
|
778
|
+
const wallOtherElements = data.layoutPolygon.flatMap( ( element ) =>
|
|
779
|
+
( element.otherElements || [] ).map( ( el ) => el ),
|
|
795
780
|
);
|
|
796
781
|
const floorOtherElements = data.otherElements || [];
|
|
797
|
-
const currentOtherElements = [...wallOtherElements, ...floorOtherElements];
|
|
782
|
+
const currentOtherElements = [ ...wallOtherElements, ...floorOtherElements ];
|
|
798
783
|
|
|
799
|
-
const existingFixtures = await storeFixtureService.find({
|
|
800
|
-
floorId: new mongoose.Types.ObjectId(floorId),
|
|
784
|
+
const existingFixtures = await storeFixtureService.find( {
|
|
785
|
+
floorId: new mongoose.Types.ObjectId( floorId ),
|
|
801
786
|
fixtureType: { $ne: 'other' },
|
|
802
|
-
});
|
|
787
|
+
} );
|
|
803
788
|
|
|
804
|
-
const existingOtherElements = await storeFixtureService.find({
|
|
805
|
-
floorId: new mongoose.Types.ObjectId(floorId),
|
|
789
|
+
const existingOtherElements = await storeFixtureService.find( {
|
|
790
|
+
floorId: new mongoose.Types.ObjectId( floorId ),
|
|
806
791
|
fixtureType: 'other',
|
|
807
|
-
});
|
|
792
|
+
} );
|
|
808
793
|
|
|
809
|
-
const currentOtherElementsIds = new Set(currentOtherElements.map((f) => f._id));
|
|
794
|
+
const currentOtherElementsIds = new Set( currentOtherElements.map( ( f ) => f._id ) );
|
|
810
795
|
|
|
811
796
|
const removedOtherElements = existingOtherElements.filter(
|
|
812
|
-
|
|
797
|
+
( f ) => f._id && !currentOtherElementsIds.has( f._id.toString() ),
|
|
813
798
|
);
|
|
814
799
|
|
|
815
|
-
if (removedOtherElements.length) {
|
|
816
|
-
const otherElementIds = removedOtherElements.map((ele) => ele.toObject()._id);
|
|
817
|
-
await storeFixtureService.deleteMany({ _id: { $in: otherElementIds } });
|
|
800
|
+
if ( removedOtherElements.length ) {
|
|
801
|
+
const otherElementIds = removedOtherElements.map( ( ele ) => ele.toObject()._id );
|
|
802
|
+
await storeFixtureService.deleteMany( { _id: { $in: otherElementIds } } );
|
|
818
803
|
}
|
|
819
804
|
|
|
820
|
-
const currentFixtureIds = new Set(currentFixtures.map((f) => f._id));
|
|
805
|
+
const currentFixtureIds = new Set( currentFixtures.map( ( f ) => f._id ) );
|
|
821
806
|
const removedFixtures = existingFixtures.filter(
|
|
822
|
-
|
|
807
|
+
( f ) => f._id && !currentFixtureIds.has( f._id.toString() ),
|
|
823
808
|
);
|
|
824
809
|
|
|
825
|
-
if (removedFixtures.length) {
|
|
826
|
-
const fixtureIds = removedFixtures.map((fixture) => fixture.toObject()._id);
|
|
810
|
+
if ( removedFixtures.length ) {
|
|
811
|
+
const fixtureIds = removedFixtures.map( ( fixture ) => fixture.toObject()._id );
|
|
827
812
|
|
|
828
|
-
await storeFixtureService.deleteMany({ _id: { $in: fixtureIds } });
|
|
829
|
-
await fixtureShelfService.deleteMany({ fixtureId: { $in: fixtureIds } });
|
|
813
|
+
await storeFixtureService.deleteMany( { _id: { $in: fixtureIds } } );
|
|
814
|
+
await fixtureShelfService.deleteMany( { fixtureId: { $in: fixtureIds } } );
|
|
830
815
|
}
|
|
831
816
|
|
|
832
817
|
const newWallFixtures = currentWallFixtures.filter(
|
|
833
|
-
|
|
818
|
+
( fixture ) => fixture?._id?.startsWith( 'new' ),
|
|
834
819
|
);
|
|
835
820
|
const newFloorFixtures = currentFloorFixtures.filter(
|
|
836
|
-
|
|
821
|
+
( fixture ) => fixture?._id?.startsWith( 'new' ),
|
|
837
822
|
);
|
|
838
823
|
|
|
839
|
-
const newFixtures = [...newWallFixtures, ...newFloorFixtures];
|
|
824
|
+
const newFixtures = [ ...newWallFixtures, ...newFloorFixtures ];
|
|
840
825
|
|
|
841
826
|
// ❗ async changed here
|
|
842
|
-
if (newFixtures.length) {
|
|
843
|
-
for (let i = 0; i < newFixtures.length; i++) {
|
|
827
|
+
if ( newFixtures.length ) {
|
|
828
|
+
for ( let i = 0; i < newFixtures.length; i++ ) {
|
|
844
829
|
const fixture = newFixtures[i];
|
|
845
830
|
|
|
846
831
|
delete fixture._id;
|
|
@@ -849,9 +834,9 @@ export async function updateStorePlano(req, res) {
|
|
|
849
834
|
...fixture,
|
|
850
835
|
};
|
|
851
836
|
|
|
852
|
-
const createdFixture = await storeFixtureService.create(fixturePayload);
|
|
837
|
+
const createdFixture = await storeFixtureService.create( fixturePayload );
|
|
853
838
|
|
|
854
|
-
for (let j = 0; j < fixture.shelfConfig.length; j++) {
|
|
839
|
+
for ( let j = 0; j < fixture.shelfConfig.length; j++ ) {
|
|
855
840
|
const shelf = fixture.shelfConfig[j];
|
|
856
841
|
|
|
857
842
|
delete shelf._id;
|
|
@@ -861,26 +846,26 @@ export async function updateStorePlano(req, res) {
|
|
|
861
846
|
fixtureId: createdFixture.toObject()._id,
|
|
862
847
|
};
|
|
863
848
|
|
|
864
|
-
await fixtureShelfService.create(shelfPayload);
|
|
849
|
+
await fixtureShelfService.create( shelfPayload );
|
|
865
850
|
}
|
|
866
851
|
}
|
|
867
852
|
}
|
|
868
853
|
|
|
869
854
|
const newOtherElements = currentOtherElements.filter(
|
|
870
|
-
|
|
855
|
+
( ele ) => ele?._id?.startsWith( 'new' ),
|
|
871
856
|
);
|
|
872
857
|
|
|
873
858
|
// ❗ async changed here
|
|
874
|
-
for (let i = 0; i < currentOtherElements.length; i++) {
|
|
859
|
+
for ( let i = 0; i < currentOtherElements.length; i++ ) {
|
|
875
860
|
const ele = currentOtherElements[i];
|
|
876
|
-
if (ele?._id && mongoose.Types.ObjectId.isValid(ele._id)) {
|
|
877
|
-
await storeFixtureService.upsertOne({ _id: new mongoose.Types.ObjectId(ele._id) }, ele);
|
|
861
|
+
if ( ele?._id && mongoose.Types.ObjectId.isValid( ele._id ) ) {
|
|
862
|
+
await storeFixtureService.upsertOne( { _id: new mongoose.Types.ObjectId( ele._id ) }, ele );
|
|
878
863
|
}
|
|
879
864
|
}
|
|
880
865
|
|
|
881
866
|
// ❗ async changed here
|
|
882
|
-
if (newOtherElements.length) {
|
|
883
|
-
for (let i = 0; i < newOtherElements.length; i++) {
|
|
867
|
+
if ( newOtherElements.length ) {
|
|
868
|
+
for ( let i = 0; i < newOtherElements.length; i++ ) {
|
|
884
869
|
const ele = newOtherElements[i];
|
|
885
870
|
delete ele._id;
|
|
886
871
|
|
|
@@ -889,27 +874,28 @@ export async function updateStorePlano(req, res) {
|
|
|
889
874
|
...additionalMeta,
|
|
890
875
|
};
|
|
891
876
|
|
|
892
|
-
await storeFixtureService.create(payload);
|
|
877
|
+
await storeFixtureService.create( payload );
|
|
893
878
|
}
|
|
894
879
|
}
|
|
895
880
|
|
|
896
|
-
|
|
881
|
+
// ❗ async changed here
|
|
882
|
+
for ( let i = 0; i < currentFixtures.length; i++ ) {
|
|
897
883
|
const fixture = currentFixtures[i];
|
|
898
884
|
|
|
899
|
-
if (mongoose.Types.ObjectId.isValid(fixture._id)) {
|
|
885
|
+
if ( mongoose.Types.ObjectId.isValid( fixture._id ) ) {
|
|
900
886
|
const updatedFixture = await storeFixtureService.upsertOne(
|
|
901
|
-
|
|
902
|
-
|
|
887
|
+
{ _id: new mongoose.Types.ObjectId( fixture._id ) },
|
|
888
|
+
fixture,
|
|
903
889
|
);
|
|
904
890
|
|
|
905
891
|
await storeFixtureService.removeKeys(
|
|
906
|
-
|
|
907
|
-
|
|
892
|
+
{ fixtureType: 'floor', _id: fixture._id },
|
|
893
|
+
{ $unset: { associatedElementType: '', associatedElementNumber: '' } },
|
|
908
894
|
);
|
|
909
895
|
|
|
910
|
-
await fixtureShelfService.deleteMany({ fixtureId: new mongoose.Types.ObjectId(fixture._id) });
|
|
896
|
+
await fixtureShelfService.deleteMany( { fixtureId: new mongoose.Types.ObjectId( fixture._id ) } );
|
|
911
897
|
|
|
912
|
-
for (let j = 0; j < fixture.shelfConfig.length; j++) {
|
|
898
|
+
for ( let j = 0; j < fixture.shelfConfig.length; j++ ) {
|
|
913
899
|
const shelf = fixture.shelfConfig[j];
|
|
914
900
|
|
|
915
901
|
delete shelf._id;
|
|
@@ -920,109 +906,109 @@ export async function updateStorePlano(req, res) {
|
|
|
920
906
|
fixtureId: updatedFixture.toObject()._id,
|
|
921
907
|
};
|
|
922
908
|
|
|
923
|
-
await fixtureShelfService.create(shelfPayload);
|
|
909
|
+
await fixtureShelfService.create( shelfPayload );
|
|
924
910
|
}
|
|
925
911
|
}
|
|
926
912
|
}
|
|
927
913
|
|
|
928
|
-
|
|
914
|
+
updateFixtureNumber( floorId );
|
|
915
|
+
|
|
929
916
|
await planoService.updateOne(
|
|
930
|
-
|
|
931
|
-
|
|
917
|
+
{ _id: floorData.toObject()?.planoId },
|
|
918
|
+
{ $set: { updatedAt: new Date() } },
|
|
932
919
|
);
|
|
933
920
|
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
logger.error({ functionName: 'updateStorePlano', error: e });
|
|
939
|
-
return res.sendError(e, 500);
|
|
921
|
+
res.sendSuccess( 'Updated Successfully' );
|
|
922
|
+
} catch ( e ) {
|
|
923
|
+
logger.error( { functionName: 'updateStorePlano', error: e } );
|
|
924
|
+
return res.sendError( e, 500 );
|
|
940
925
|
}
|
|
941
926
|
}
|
|
942
927
|
|
|
943
|
-
async function updateFixtureNumber(floorId){
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
fixtureDetails.sort((a, b) => {
|
|
947
|
-
if (a.associatedElementNumber !== b.associatedElementNumber) {
|
|
928
|
+
async function updateFixtureNumber( floorId ) {
|
|
929
|
+
try {
|
|
930
|
+
let fixtureDetails = await storeFixtureService.findAndSort( { floorId: new mongoose.Types.ObjectId( floorId ), fixtureType: { $ne: 'other' } }, {}, { fixtureType: -1, associatedElementNumber: 1 } );
|
|
931
|
+
fixtureDetails.sort( ( a, b ) => {
|
|
932
|
+
if ( a.associatedElementNumber !== b.associatedElementNumber ) {
|
|
948
933
|
return a.associatedElementNumber - b.associatedElementNumber;
|
|
949
934
|
}
|
|
950
935
|
|
|
951
936
|
return a.associatedElementFixtureNumber - b.associatedElementFixtureNumber;
|
|
952
|
-
});
|
|
953
|
-
|
|
937
|
+
} );
|
|
954
938
|
let fixtureNumber = 0;
|
|
955
|
-
|
|
956
|
-
for (let fixture of fixtureDetails) {
|
|
939
|
+
for ( let fixture of fixtureDetails ) {
|
|
957
940
|
fixtureNumber++;
|
|
958
|
-
storeFixtureService.updateOne({ _id: fixture._id }, { fixtureNumber: fixtureNumber });
|
|
941
|
+
storeFixtureService.updateOne( { _id: fixture._id }, { fixtureNumber: fixtureNumber } );
|
|
959
942
|
}
|
|
943
|
+
} catch ( e ) {
|
|
944
|
+
logger.error( { functionName: 'updateFixtureNumber', error: e } );
|
|
945
|
+
}
|
|
960
946
|
}
|
|
961
947
|
|
|
962
948
|
|
|
963
|
-
export async function fixtureList(req, res) {
|
|
949
|
+
export async function fixtureList( req, res ) {
|
|
964
950
|
try {
|
|
965
|
-
let findData = await fixtureLibraryService.find({ clientId: req.query.clientId });
|
|
966
|
-
if (findData.length === 0) {
|
|
967
|
-
return res.sendError('nodata found', 204);
|
|
951
|
+
let findData = await fixtureLibraryService.find( { clientId: req.query.clientId } );
|
|
952
|
+
if ( findData.length === 0 ) {
|
|
953
|
+
return res.sendError( 'nodata found', 204 );
|
|
968
954
|
}
|
|
969
|
-
res.sendSuccess(findData);
|
|
970
|
-
} catch (e) {
|
|
971
|
-
logger.error({ functionName: 'fixtureList', error: e });
|
|
972
|
-
return res.sendError(e, 500);
|
|
955
|
+
res.sendSuccess( findData );
|
|
956
|
+
} catch ( e ) {
|
|
957
|
+
logger.error( { functionName: 'fixtureList', error: e } );
|
|
958
|
+
return res.sendError( e, 500 );
|
|
973
959
|
}
|
|
974
960
|
}
|
|
975
|
-
export async function templateList(req, res) {
|
|
961
|
+
export async function templateList( req, res ) {
|
|
976
962
|
try {
|
|
977
|
-
let findData = await fixtureConfigService.find({ clientId: req.query.clientId, fixtureLibraryId: new mongoose.Types.ObjectId(req.query.fixtureId) });
|
|
978
|
-
if (findData.length === 0) {
|
|
979
|
-
return res.sendError('nodata found', 204);
|
|
963
|
+
let findData = await fixtureConfigService.find( { clientId: req.query.clientId, fixtureLibraryId: new mongoose.Types.ObjectId( req.query.fixtureId ) } );
|
|
964
|
+
if ( findData.length === 0 ) {
|
|
965
|
+
return res.sendError( 'nodata found', 204 );
|
|
980
966
|
}
|
|
981
|
-
res.sendSuccess(findData);
|
|
982
|
-
} catch (e) {
|
|
983
|
-
logger.error({ functionName: 'templateList', error: e });
|
|
984
|
-
return res.sendError(e, 500);
|
|
967
|
+
res.sendSuccess( findData );
|
|
968
|
+
} catch ( e ) {
|
|
969
|
+
logger.error( { functionName: 'templateList', error: e } );
|
|
970
|
+
return res.sendError( e, 500 );
|
|
985
971
|
}
|
|
986
972
|
}
|
|
987
|
-
export async function fixtureBrandsList(req, res) {
|
|
973
|
+
export async function fixtureBrandsList( req, res ) {
|
|
988
974
|
try {
|
|
989
|
-
let findData = await planoproductCategoryService.find({ clientId: req.query.clientId });
|
|
990
|
-
if (findData.length === 0) {
|
|
991
|
-
return res.sendError('nodata found', 204);
|
|
975
|
+
let findData = await planoproductCategoryService.find( { clientId: req.query.clientId } );
|
|
976
|
+
if ( findData.length === 0 ) {
|
|
977
|
+
return res.sendError( 'nodata found', 204 );
|
|
992
978
|
}
|
|
993
|
-
res.sendSuccess(findData);
|
|
994
|
-
} catch (e) {
|
|
995
|
-
logger.error({ functionName: 'fixtureBrandsList', error: e });
|
|
996
|
-
return res.sendError(e, 500);
|
|
979
|
+
res.sendSuccess( findData );
|
|
980
|
+
} catch ( e ) {
|
|
981
|
+
logger.error( { functionName: 'fixtureBrandsList', error: e } );
|
|
982
|
+
return res.sendError( e, 500 );
|
|
997
983
|
}
|
|
998
984
|
}
|
|
999
985
|
|
|
1000
|
-
export async function fixtureVMList(req, res) {
|
|
986
|
+
export async function fixtureVMList( req, res ) {
|
|
1001
987
|
try {
|
|
1002
|
-
let findData = await planoVmService.find({ clientId: req.query.clientId });
|
|
1003
|
-
if (findData.length === 0) {
|
|
1004
|
-
return res.sendError('nodata found', 204);
|
|
988
|
+
let findData = await planoVmService.find( { clientId: req.query.clientId } );
|
|
989
|
+
if ( findData.length === 0 ) {
|
|
990
|
+
return res.sendError( 'nodata found', 204 );
|
|
1005
991
|
}
|
|
1006
|
-
res.sendSuccess(findData);
|
|
1007
|
-
} catch (e) {
|
|
1008
|
-
logger.error({ functionName: 'fixtureVMList', error: e });
|
|
1009
|
-
return res.sendError(e, 500);
|
|
992
|
+
res.sendSuccess( findData );
|
|
993
|
+
} catch ( e ) {
|
|
994
|
+
logger.error( { functionName: 'fixtureVMList', error: e } );
|
|
995
|
+
return res.sendError( e, 500 );
|
|
1010
996
|
}
|
|
1011
997
|
}
|
|
1012
998
|
|
|
1013
|
-
export async function fixtureVMListv1(req, res) {
|
|
999
|
+
export async function fixtureVMListv1( req, res ) {
|
|
1014
1000
|
try {
|
|
1015
|
-
let findData = await planoVmDuplicateService.find({ clientId: req.query.clientId });
|
|
1016
|
-
if (findData.length === 0) {
|
|
1017
|
-
return res.sendError('nodata found', 204);
|
|
1001
|
+
let findData = await planoVmDuplicateService.find( { clientId: req.query.clientId } );
|
|
1002
|
+
if ( findData.length === 0 ) {
|
|
1003
|
+
return res.sendError( 'nodata found', 204 );
|
|
1018
1004
|
}
|
|
1019
|
-
res.sendSuccess(findData);
|
|
1020
|
-
} catch (e) {
|
|
1021
|
-
logger.error({ functionName: 'fixtureVMListv1', error: e });
|
|
1022
|
-
return res.sendError(e, 500);
|
|
1005
|
+
res.sendSuccess( findData );
|
|
1006
|
+
} catch ( e ) {
|
|
1007
|
+
logger.error( { functionName: 'fixtureVMListv1', error: e } );
|
|
1008
|
+
return res.sendError( e, 500 );
|
|
1023
1009
|
}
|
|
1024
1010
|
}
|
|
1025
|
-
export async function updateFixtureStatus(req, res) {
|
|
1011
|
+
export async function updateFixtureStatus( req, res ) {
|
|
1026
1012
|
try {
|
|
1027
1013
|
let comments = {
|
|
1028
1014
|
userId: req.user._id,
|
|
@@ -1032,152 +1018,149 @@ export async function updateFixtureStatus(req, res) {
|
|
|
1032
1018
|
comment: req.body.comments,
|
|
1033
1019
|
};
|
|
1034
1020
|
|
|
1035
|
-
if (req.body.taskType.includes('fixture')) {
|
|
1021
|
+
if ( req.body.taskType.includes( 'fixture' ) ) {
|
|
1036
1022
|
await planoTaskService.updateOnefilters(
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
},
|
|
1044
|
-
[
|
|
1045
|
-
{ 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
|
|
1023
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1024
|
+
{
|
|
1025
|
+
$set: { 'answers.$[ans].status': req.body.type },
|
|
1026
|
+
},
|
|
1027
|
+
[
|
|
1028
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
1046
1029
|
|
|
1047
|
-
|
|
1030
|
+
],
|
|
1048
1031
|
);
|
|
1049
1032
|
await planoTaskService.updateOnefilters(
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1033
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1034
|
+
{
|
|
1035
|
+
$push: { 'answers.$[ans].comments': comments },
|
|
1036
|
+
},
|
|
1037
|
+
[
|
|
1038
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
1039
|
+
] );
|
|
1057
1040
|
|
|
1058
|
-
await planoTaskService.updateOne({ _id: req.body._id }, { approvalStatus: 'approved', taskType: 'initial' });
|
|
1041
|
+
await planoTaskService.updateOne( { _id: req.body._id }, { approvalStatus: 'approved', taskType: 'initial' } );
|
|
1059
1042
|
let fixtureTask = await planoTaskService.find(
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1043
|
+
{
|
|
1044
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
1045
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
1046
|
+
type: 'fixture',
|
|
1047
|
+
},
|
|
1065
1048
|
);
|
|
1066
|
-
if (fixtureTask.length > 0) {
|
|
1067
|
-
let allTaskDone = fixtureTask.filter((data) => !data?.answers?.[0]?.status || data?.answers?.[0]?.status == 'disagree');
|
|
1068
|
-
if (allTaskDone.length === 0) {
|
|
1069
|
-
await floorService.updateOne({ _id: new mongoose.Types.ObjectId(req.body.floorId) }, { planoProgress: 100 });
|
|
1049
|
+
if ( fixtureTask.length > 0 ) {
|
|
1050
|
+
let allTaskDone = fixtureTask.filter( ( data ) => !data?.answers?.[0]?.status || data?.answers?.[0]?.status == 'disagree' );
|
|
1051
|
+
if ( allTaskDone.length === 0 ) {
|
|
1052
|
+
await floorService.updateOne( { _id: new mongoose.Types.ObjectId( req.body.floorId ) }, { planoProgress: 100 } );
|
|
1070
1053
|
}
|
|
1071
1054
|
}
|
|
1072
1055
|
} else {
|
|
1073
1056
|
let updateResponse = await planoTaskService.updateOnefilters(
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
if (updateResponse && updateResponse.answers.length > 0) {
|
|
1085
|
-
let findissuse = updateResponse.answers[0].issues.filter((data) => data._id == req.body.issueId);
|
|
1086
|
-
let findDetails = findissuse[0].Details.filter((det) => det.status === 'agree');
|
|
1087
|
-
if (findissuse[0].Details.length === findDetails.length) {
|
|
1057
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1058
|
+
{
|
|
1059
|
+
$set: { 'answers.$[ans].issues.$[iss].Details.$[det].status': req.body.type },
|
|
1060
|
+
},
|
|
1061
|
+
[
|
|
1062
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
1063
|
+
{ 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
|
|
1064
|
+
{ 'det._id': new mongoose.Types.ObjectId( req.body.DetailsId ) },
|
|
1065
|
+
|
|
1066
|
+
] );
|
|
1067
|
+
if ( updateResponse && updateResponse.answers.length > 0 ) {
|
|
1068
|
+
let findissuse = updateResponse.answers[0].issues.filter( ( data ) => data._id == req.body.issueId );
|
|
1069
|
+
let findDetails = findissuse[0].Details.filter( ( det ) => det.status === 'agree' );
|
|
1070
|
+
if ( findissuse[0].Details.length === findDetails.length ) {
|
|
1088
1071
|
await planoTaskService.updateOnefilters(
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1072
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1073
|
+
{
|
|
1074
|
+
$set: { 'answers.$[ans].issues.$[iss].status': 'completed' },
|
|
1075
|
+
},
|
|
1076
|
+
[
|
|
1077
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
1078
|
+
{ 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
|
|
1079
|
+
] );
|
|
1097
1080
|
}
|
|
1098
|
-
let findoneplanoData = await planoTaskService.findOne({ _id: new mongoose.Types.ObjectId(req.body._id) });
|
|
1099
|
-
let totalApproved = findoneplanoData.answers[0].issues.filter((data) => data.status === 'pending');
|
|
1100
|
-
if (totalApproved.length === 0) {
|
|
1081
|
+
let findoneplanoData = await planoTaskService.findOne( { _id: new mongoose.Types.ObjectId( req.body._id ) } );
|
|
1082
|
+
let totalApproved = findoneplanoData.answers[0].issues.filter( ( data ) => data.status === 'pending' );
|
|
1083
|
+
if ( totalApproved.length === 0 ) {
|
|
1101
1084
|
await planoTaskService.updateOne(
|
|
1102
|
-
{
|
|
1103
|
-
_id: new mongoose.Types.ObjectId(req.body._id),
|
|
1104
|
-
},
|
|
1105
|
-
{
|
|
1106
|
-
'status': 'complete',
|
|
1107
|
-
},
|
|
1108
|
-
);
|
|
1109
|
-
if (req.body.taskType === 'layout') {
|
|
1110
|
-
await planoTaskService.updateMany(
|
|
1111
1085
|
{
|
|
1112
|
-
|
|
1113
|
-
floorId: new mongoose.Types.ObjectId(req.body.floorId),
|
|
1114
|
-
type: 'layout',
|
|
1086
|
+
_id: new mongoose.Types.ObjectId( req.body._id ),
|
|
1115
1087
|
},
|
|
1116
1088
|
{
|
|
1117
1089
|
'status': 'complete',
|
|
1118
1090
|
},
|
|
1091
|
+
);
|
|
1092
|
+
if ( req.body.taskType === 'layout' ) {
|
|
1093
|
+
await planoTaskService.updateMany(
|
|
1094
|
+
{
|
|
1095
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
1096
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
1097
|
+
type: 'layout',
|
|
1098
|
+
},
|
|
1099
|
+
{
|
|
1100
|
+
'status': 'complete',
|
|
1101
|
+
},
|
|
1119
1102
|
);
|
|
1120
1103
|
}
|
|
1121
1104
|
}
|
|
1122
1105
|
}
|
|
1123
1106
|
|
|
1124
|
-
if (req.body.taskType === 'layout') {
|
|
1107
|
+
if ( req.body.taskType === 'layout' ) {
|
|
1125
1108
|
await planoTaskService.updateOnefilters(
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1109
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1110
|
+
{
|
|
1111
|
+
$push: { 'answers.$[ans].issues.$[iss].Details.$[det].comments': comments },
|
|
1112
|
+
},
|
|
1113
|
+
[
|
|
1114
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
1115
|
+
{ 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
|
|
1116
|
+
{ 'det._id': new mongoose.Types.ObjectId( req.body.DetailsId ) },
|
|
1134
1117
|
|
|
1135
|
-
|
|
1118
|
+
] );
|
|
1136
1119
|
} else {
|
|
1137
1120
|
await planoTaskService.updateOnefilters(
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1121
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1122
|
+
{
|
|
1123
|
+
$push: { 'answers.$[ans].issues.$[iss].comments': comments },
|
|
1124
|
+
},
|
|
1125
|
+
[
|
|
1126
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
1127
|
+
{ 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
|
|
1128
|
+
] );
|
|
1146
1129
|
}
|
|
1147
1130
|
let vmTask = await planoTaskService.find(
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1131
|
+
{
|
|
1132
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
1133
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
1134
|
+
type: 'vm',
|
|
1135
|
+
},
|
|
1153
1136
|
|
|
1154
1137
|
);
|
|
1155
|
-
if (vmTask.length > 0) {
|
|
1156
|
-
let allTaskDone = vmTask.filter((data) => data.status === 'incomplete');
|
|
1157
|
-
if (allTaskDone.length === 0) {
|
|
1158
|
-
await floorService.updateOne({ _id: new mongoose.Types.ObjectId(req.body.floorId) }, { planoProgress: 100 });
|
|
1138
|
+
if ( vmTask.length > 0 ) {
|
|
1139
|
+
let allTaskDone = vmTask.filter( ( data ) => data.status === 'incomplete' );
|
|
1140
|
+
if ( allTaskDone.length === 0 ) {
|
|
1141
|
+
await floorService.updateOne( { _id: new mongoose.Types.ObjectId( req.body.floorId ) }, { planoProgress: 100 } );
|
|
1159
1142
|
}
|
|
1160
1143
|
}
|
|
1161
1144
|
}
|
|
1162
|
-
res.sendSuccess('updated successfully');
|
|
1163
|
-
} catch (e) {
|
|
1164
|
-
logger.error({ functionName: 'updateFixtureStatus', error: e });
|
|
1165
|
-
return res.sendError(e, 500);
|
|
1145
|
+
res.sendSuccess( 'updated successfully' );
|
|
1146
|
+
} catch ( e ) {
|
|
1147
|
+
logger.error( { functionName: 'updateFixtureStatus', error: e } );
|
|
1148
|
+
return res.sendError( e, 500 );
|
|
1166
1149
|
}
|
|
1167
1150
|
}
|
|
1168
1151
|
|
|
1169
|
-
export async function updateApprovalStatus(req, res) {
|
|
1152
|
+
export async function updateApprovalStatus( req, res ) {
|
|
1170
1153
|
try {
|
|
1171
1154
|
await planoTaskService.updateOnefilters(
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
res.sendSuccess('updated successfully');
|
|
1175
|
-
} catch (e) {
|
|
1176
|
-
logger.error({ functionName: 'updateApprovalStatus', error: e });
|
|
1177
|
-
return res.sendError(e, 500);
|
|
1155
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1156
|
+
{ $set: { approvalStatus: 'approved' } } );
|
|
1157
|
+
res.sendSuccess( 'updated successfully' );
|
|
1158
|
+
} catch ( e ) {
|
|
1159
|
+
logger.error( { functionName: 'updateApprovalStatus', error: e } );
|
|
1160
|
+
return res.sendError( e, 500 );
|
|
1178
1161
|
}
|
|
1179
1162
|
}
|
|
1180
|
-
export async function updateRolloutStatus(req, res) {
|
|
1163
|
+
export async function updateRolloutStatus( req, res ) {
|
|
1181
1164
|
try {
|
|
1182
1165
|
let comments = {
|
|
1183
1166
|
userId: req.user._id,
|
|
@@ -1187,153 +1170,153 @@ export async function updateRolloutStatus(req, res) {
|
|
|
1187
1170
|
comment: req.body.comments,
|
|
1188
1171
|
};
|
|
1189
1172
|
|
|
1190
|
-
if (req.body.issueId && req.body.DetailsId) {
|
|
1173
|
+
if ( req.body.issueId && req.body.DetailsId ) {
|
|
1191
1174
|
let updateResponse = await planoTaskService.updateOnefilters(
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1175
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1176
|
+
{
|
|
1177
|
+
$set: {
|
|
1178
|
+
'answers.$[ans].issues.$[iss].Details.$[det].status': req.body.type,
|
|
1179
|
+
'answers.$[ans].issues.$[iss].Details.$[det].adminStatus': req.body.type === 'agree' ? 'approved' : 'Unapproved',
|
|
1180
|
+
},
|
|
1197
1181
|
},
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
{ 'det._id': new mongoose.Types.ObjectId(req.body.DetailsId) },
|
|
1182
|
+
[
|
|
1183
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
1184
|
+
{ 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
|
|
1185
|
+
{ 'det._id': new mongoose.Types.ObjectId( req.body.DetailsId ) },
|
|
1203
1186
|
|
|
1204
|
-
|
|
1187
|
+
],
|
|
1205
1188
|
);
|
|
1206
|
-
if (updateResponse && updateResponse.answers.length > 0) {
|
|
1207
|
-
let findissuse = updateResponse.answers[0].issues.filter((data) => data._id == req.body.issueId);
|
|
1208
|
-
let findDetails = findissuse[0].Details.filter((det) => det.status === 'agree');
|
|
1209
|
-
if (findissuse[0].Details.length === findDetails.length) {
|
|
1189
|
+
if ( updateResponse && updateResponse.answers.length > 0 ) {
|
|
1190
|
+
let findissuse = updateResponse.answers[0].issues.filter( ( data ) => data._id == req.body.issueId );
|
|
1191
|
+
let findDetails = findissuse[0].Details.filter( ( det ) => det.status === 'agree' );
|
|
1192
|
+
if ( findissuse[0].Details.length === findDetails.length ) {
|
|
1210
1193
|
await planoTaskService.updateOnefilters(
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1194
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1195
|
+
{
|
|
1196
|
+
$set: { 'answers.$[ans].issues.$[iss].status': 'completed' },
|
|
1197
|
+
},
|
|
1198
|
+
[
|
|
1199
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
1200
|
+
{ 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
|
|
1201
|
+
] );
|
|
1219
1202
|
}
|
|
1220
|
-
let findoneplanoData = await planoTaskService.findOne({ _id: new mongoose.Types.ObjectId(req.body._id) });
|
|
1221
|
-
let totalApproved = findoneplanoData.answers[0].issues.filter((data) => data.status === 'pending');
|
|
1222
|
-
if (totalApproved.length === 0) {
|
|
1203
|
+
let findoneplanoData = await planoTaskService.findOne( { _id: new mongoose.Types.ObjectId( req.body._id ) } );
|
|
1204
|
+
let totalApproved = findoneplanoData.answers[0].issues.filter( ( data ) => data.status === 'pending' );
|
|
1205
|
+
if ( totalApproved.length === 0 ) {
|
|
1223
1206
|
await planoTaskService.updateOne(
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1207
|
+
{
|
|
1208
|
+
_id: new mongoose.Types.ObjectId( req.body._id ),
|
|
1209
|
+
},
|
|
1210
|
+
{
|
|
1211
|
+
'status': 'complete',
|
|
1212
|
+
'approvalStatus': 'approved',
|
|
1213
|
+
},
|
|
1231
1214
|
);
|
|
1232
1215
|
let data = {};
|
|
1233
|
-
if (req.body.taskType == 'vmRollout') {
|
|
1216
|
+
if ( req.body.taskType == 'vmRollout' ) {
|
|
1234
1217
|
data['isVmEdited'] = false;
|
|
1235
1218
|
} else {
|
|
1236
1219
|
data['isMerchEdited'] = false;
|
|
1237
1220
|
}
|
|
1238
|
-
await storeFixtureService.updateOne({ _id: updateResponse.fixtureId }, data);
|
|
1221
|
+
await storeFixtureService.updateOne( { _id: updateResponse.fixtureId }, data );
|
|
1239
1222
|
}
|
|
1240
1223
|
}
|
|
1241
1224
|
await planoTaskService.updateOnefilters(
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1225
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1226
|
+
{
|
|
1227
|
+
$push: { 'answers.$[ans].issues.$[iss].comments': comments },
|
|
1228
|
+
},
|
|
1229
|
+
[
|
|
1230
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
1231
|
+
{ 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
|
|
1232
|
+
],
|
|
1250
1233
|
);
|
|
1251
1234
|
} else {
|
|
1252
1235
|
let updateResponse = await planoTaskService.updateOnefilters(
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1236
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1237
|
+
{
|
|
1238
|
+
$set: {
|
|
1239
|
+
'answers.$[ans].status': req.body.type,
|
|
1240
|
+
},
|
|
1257
1241
|
},
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
],
|
|
1242
|
+
[
|
|
1243
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
1244
|
+
],
|
|
1262
1245
|
);
|
|
1263
1246
|
await planoTaskService.updateOnefilters(
|
|
1264
|
-
|
|
1265
|
-
{
|
|
1266
|
-
$push: { 'answers.$[ans].comments': comments },
|
|
1267
|
-
},
|
|
1268
|
-
[
|
|
1269
|
-
{ 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
|
|
1270
|
-
],
|
|
1271
|
-
);
|
|
1272
|
-
if (req.body.type == 'agree') {
|
|
1273
|
-
await planoTaskService.updateOne(
|
|
1274
|
-
{
|
|
1275
|
-
_id: new mongoose.Types.ObjectId(req.body._id),
|
|
1276
|
-
},
|
|
1247
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1277
1248
|
{
|
|
1278
|
-
'
|
|
1249
|
+
$push: { 'answers.$[ans].comments': comments },
|
|
1279
1250
|
},
|
|
1251
|
+
[
|
|
1252
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
1253
|
+
],
|
|
1254
|
+
);
|
|
1255
|
+
if ( req.body.type == 'agree' ) {
|
|
1256
|
+
await planoTaskService.updateOne(
|
|
1257
|
+
{
|
|
1258
|
+
_id: new mongoose.Types.ObjectId( req.body._id ),
|
|
1259
|
+
},
|
|
1260
|
+
{
|
|
1261
|
+
'approvalStatus': 'approved',
|
|
1262
|
+
},
|
|
1280
1263
|
);
|
|
1281
1264
|
let data = {};
|
|
1282
|
-
if (req.body.taskType == 'vmRollout') {
|
|
1265
|
+
if ( req.body.taskType == 'vmRollout' ) {
|
|
1283
1266
|
data['isVmEdited'] = false;
|
|
1284
1267
|
} else {
|
|
1285
1268
|
data['isMerchEdited'] = false;
|
|
1286
1269
|
}
|
|
1287
|
-
await storeFixtureService.updateOne({ _id: updateResponse.fixtureId }, data);
|
|
1270
|
+
await storeFixtureService.updateOne( { _id: updateResponse.fixtureId }, data );
|
|
1288
1271
|
}
|
|
1289
1272
|
}
|
|
1290
1273
|
|
|
1291
|
-
res.sendSuccess('updated successfully');
|
|
1292
|
-
} catch (e) {
|
|
1293
|
-
logger.error({ functionName: 'updateFixtureStatus', error: e });
|
|
1294
|
-
return res.sendError(e, 500);
|
|
1274
|
+
res.sendSuccess( 'updated successfully' );
|
|
1275
|
+
} catch ( e ) {
|
|
1276
|
+
logger.error( { functionName: 'updateFixtureStatus', error: e } );
|
|
1277
|
+
return res.sendError( e, 500 );
|
|
1295
1278
|
}
|
|
1296
1279
|
}
|
|
1297
1280
|
|
|
1298
1281
|
|
|
1299
|
-
export async function updateStoreFixture(req, res) {
|
|
1282
|
+
export async function updateStoreFixture( req, res ) {
|
|
1300
1283
|
try {
|
|
1301
1284
|
const { fixtureId, data } = req.body;
|
|
1302
1285
|
|
|
1303
1286
|
let configId;
|
|
1304
1287
|
|
|
1305
|
-
const currentFixture = await storeFixtureService.findOne({ _id: new mongoose.Types.ObjectId(fixtureId) });
|
|
1288
|
+
const currentFixture = await storeFixtureService.findOne( { _id: new mongoose.Types.ObjectId( fixtureId ) } );
|
|
1306
1289
|
let currentFixtureDoc = currentFixture.toObject();
|
|
1307
|
-
if (
|
|
1308
|
-
let shelfDetails = await fixtureShelfService.find({ fixtureId: fixtureId });
|
|
1309
|
-
data.shelfConfig.forEach((ele) => {
|
|
1310
|
-
let findShelfProduct = shelfDetails.find((shelf) => shelf.shelfNumber == ele.shelfNumber);
|
|
1311
|
-
if (!ele?.zone) {
|
|
1290
|
+
if ( req?.body?.taskType?.includes( 'fixture' ) || data?.taskType?.includes( 'fixture' ) ) {
|
|
1291
|
+
let shelfDetails = await fixtureShelfService.find( { fixtureId: fixtureId } );
|
|
1292
|
+
data.shelfConfig.forEach( ( ele ) => {
|
|
1293
|
+
let findShelfProduct = shelfDetails.find( ( shelf ) => shelf.shelfNumber == ele.shelfNumber );
|
|
1294
|
+
if ( !ele?.zone ) {
|
|
1312
1295
|
ele.zone = findShelfProduct?.zone ?? 'Bottom';
|
|
1313
1296
|
}
|
|
1314
|
-
if (!ele?.productBrandName) {
|
|
1297
|
+
if ( !ele?.productBrandName ) {
|
|
1315
1298
|
ele.productBrandName = findShelfProduct?.productBrandName ?? [];
|
|
1316
1299
|
}
|
|
1317
|
-
if (!ele?.productCategory) {
|
|
1300
|
+
if ( !ele?.productCategory ) {
|
|
1318
1301
|
ele.productCategory = findShelfProduct?.productCategory ?? [];
|
|
1319
1302
|
}
|
|
1320
|
-
if (!ele?.productSubCategory) {
|
|
1303
|
+
if ( !ele?.productSubCategory ) {
|
|
1321
1304
|
ele.productSubCategory = findShelfProduct?.productSubCategory ?? [];
|
|
1322
1305
|
}
|
|
1323
|
-
});
|
|
1306
|
+
} );
|
|
1324
1307
|
let vmConfig = [];
|
|
1325
|
-
for (let vm of data.vmConfig) {
|
|
1326
|
-
let checkvmType = await vmTypeService.findOne({ vmType: vm.vmType });
|
|
1327
|
-
if (!checkvmType) {
|
|
1308
|
+
for ( let vm of data.vmConfig ) {
|
|
1309
|
+
let checkvmType = await vmTypeService.findOne( { vmType: vm.vmType } );
|
|
1310
|
+
if ( !checkvmType ) {
|
|
1328
1311
|
let vmData = {
|
|
1329
1312
|
vmType: vm.vmType,
|
|
1330
|
-
imageUrls: [vm.vmImage],
|
|
1313
|
+
imageUrls: [ vm.vmImage ],
|
|
1331
1314
|
clientId: '11',
|
|
1332
1315
|
};
|
|
1333
|
-
checkvmType = await vmTypeService.create(vmData);
|
|
1316
|
+
checkvmType = await vmTypeService.create( vmData );
|
|
1334
1317
|
}
|
|
1335
|
-
let vmDetails = await planoVmService.findOne({ ...(vm.vmName) ? { vmName: vm.vmName } : { _id: vm.vmId } });
|
|
1336
|
-
if (!vmDetails) {
|
|
1318
|
+
let vmDetails = await planoVmService.findOne( { ...( vm.vmName ) ? { vmName: vm.vmName } : { _id: vm.vmId } } );
|
|
1319
|
+
if ( !vmDetails ) {
|
|
1337
1320
|
let planovmData = {
|
|
1338
1321
|
vmType: vm.vmType,
|
|
1339
1322
|
vmName: vm.vmName,
|
|
@@ -1349,9 +1332,9 @@ export async function updateStoreFixture(req, res) {
|
|
|
1349
1332
|
},
|
|
1350
1333
|
vmImageUrl: vm.vmImage,
|
|
1351
1334
|
};
|
|
1352
|
-
vmDetails = await planoVmService.create(planovmData);
|
|
1335
|
+
vmDetails = await planoVmService.create( planovmData );
|
|
1353
1336
|
}
|
|
1354
|
-
vmConfig.push({ ...vm, vmId: vmDetails._id });
|
|
1337
|
+
vmConfig.push( { ...vm, vmId: vmDetails._id } );
|
|
1355
1338
|
}
|
|
1356
1339
|
data.vmConfig = vmConfig;
|
|
1357
1340
|
let groupName = {
|
|
@@ -1360,12 +1343,12 @@ export async function updateStoreFixture(req, res) {
|
|
|
1360
1343
|
'Vincent Chase': 'VC Eye',
|
|
1361
1344
|
'OwnDays': 'OD Eye',
|
|
1362
1345
|
};
|
|
1363
|
-
let header = (data?.header?.label && data?.header?.label != 'Unknown') ? groupName?.[data?.header?.label] ? groupName?.[data?.header?.label] : data?.header?.label : currentFixture.header?.label;
|
|
1346
|
+
let header = ( data?.header?.label && data?.header?.label != 'Unknown' ) ? groupName?.[data?.header?.label] ? groupName?.[data?.header?.label] : data?.header?.label : currentFixture.header?.label;
|
|
1364
1347
|
let mapKey = `${data.fixtureCategory}${currentFixtureDoc.fixtureWidth.value}${currentFixtureDoc.fixtureWidth.unit}${header}`;
|
|
1365
|
-
mapKey += data.shelfConfig.map((ele) => `${ele.shelfNumber}=${ele.productBrandName.toString()}`).join('+');
|
|
1366
|
-
data?.vmConfig?.forEach((ele) => {
|
|
1348
|
+
mapKey += data.shelfConfig.map( ( ele ) => `${ele.shelfNumber}=${ele.productBrandName.toString()}` ).join( '+' );
|
|
1349
|
+
data?.vmConfig?.forEach( ( ele ) => {
|
|
1367
1350
|
mapKey += `${ele.vmName}${ele.startYPosition}${ele.endYPosition}${ele.xZone}${ele.yZone}`;
|
|
1368
|
-
});
|
|
1351
|
+
} );
|
|
1369
1352
|
let query = [
|
|
1370
1353
|
{
|
|
1371
1354
|
$addFields: {
|
|
@@ -1393,13 +1376,13 @@ export async function updateStoreFixture(req, res) {
|
|
|
1393
1376
|
},
|
|
1394
1377
|
},
|
|
1395
1378
|
];
|
|
1396
|
-
let [fixturesubTemplate, fixtureMasterTemplate] = await Promise.all([
|
|
1397
|
-
await fixtureConfigService.aggregate(query),
|
|
1398
|
-
await fixtureConfigService.aggregate(masterQuery),
|
|
1399
|
-
]);
|
|
1379
|
+
let [ fixturesubTemplate, fixtureMasterTemplate ] = await Promise.all( [
|
|
1380
|
+
await fixtureConfigService.aggregate( query ),
|
|
1381
|
+
await fixtureConfigService.aggregate( masterQuery ),
|
|
1382
|
+
] );
|
|
1400
1383
|
|
|
1401
|
-
if (!fixturesubTemplate.length) {
|
|
1402
|
-
let tempGroupName = (data?.header?.label && data?.header?.label != 'Unknown') ? groupName?.[data?.header?.label] ? groupName?.[data?.header?.label] : data?.header?.label : currentFixture.templateGroupName;
|
|
1384
|
+
if ( !fixturesubTemplate.length ) {
|
|
1385
|
+
let tempGroupName = ( data?.header?.label && data?.header?.label != 'Unknown' ) ? groupName?.[data?.header?.label] ? groupName?.[data?.header?.label] : data?.header?.label : currentFixture.templateGroupName;
|
|
1403
1386
|
let templateIndex = 1;
|
|
1404
1387
|
let templateData = {
|
|
1405
1388
|
...currentFixtureDoc,
|
|
@@ -1412,20 +1395,20 @@ export async function updateStoreFixture(req, res) {
|
|
|
1412
1395
|
};
|
|
1413
1396
|
delete templateData._id;
|
|
1414
1397
|
delete templateData.masterTemplateId;
|
|
1415
|
-
if (!fixtureMasterTemplate.length) {
|
|
1398
|
+
if ( !fixtureMasterTemplate.length ) {
|
|
1416
1399
|
let masterTemplate = {
|
|
1417
1400
|
...templateData,
|
|
1418
1401
|
fixtureName: `${templateData.header.label}-${templateData.fixtureCategory}`,
|
|
1419
1402
|
templateType: 'master',
|
|
1420
1403
|
crestMapKey: masterMapKey,
|
|
1421
1404
|
};
|
|
1422
|
-
fixtureMasterTemplate = await fixtureConfigService.create(masterTemplate);
|
|
1405
|
+
fixtureMasterTemplate = await fixtureConfigService.create( masterTemplate );
|
|
1423
1406
|
} else {
|
|
1424
1407
|
fixtureMasterTemplate = fixtureMasterTemplate[0];
|
|
1425
1408
|
let tempQuery = [
|
|
1426
1409
|
{
|
|
1427
1410
|
$match: {
|
|
1428
|
-
masterTemplateId: new mongoose.Types.ObjectId(fixtureMasterTemplate._id),
|
|
1411
|
+
masterTemplateId: new mongoose.Types.ObjectId( fixtureMasterTemplate._id ),
|
|
1429
1412
|
},
|
|
1430
1413
|
},
|
|
1431
1414
|
{
|
|
@@ -1435,16 +1418,16 @@ export async function updateStoreFixture(req, res) {
|
|
|
1435
1418
|
},
|
|
1436
1419
|
},
|
|
1437
1420
|
];
|
|
1438
|
-
let getMaxTemp = await fixtureConfigService.aggregate(tempQuery);
|
|
1421
|
+
let getMaxTemp = await fixtureConfigService.aggregate( tempQuery );
|
|
1439
1422
|
templateIndex = getMaxTemp?.[0]?.tempId + 1;
|
|
1440
1423
|
}
|
|
1441
|
-
templateData.fixtureName
|
|
1442
|
-
|
|
1424
|
+
templateData.fixtureName= `${header}-${data.fixtureCategory}-variant-${templateIndex}`,
|
|
1425
|
+
templateData.templateType = 'sub';
|
|
1443
1426
|
templateData.masterTemplateId = fixtureMasterTemplate._id;
|
|
1444
1427
|
templateData.templateIndex = templateIndex;
|
|
1445
1428
|
templateData.createdAt = new Date();
|
|
1446
1429
|
templateData.updatedAt = new Date();
|
|
1447
|
-
let subTemplate = await fixtureConfigService.create(templateData);
|
|
1430
|
+
let subTemplate = await fixtureConfigService.create( templateData );
|
|
1448
1431
|
configId = subTemplate._id;
|
|
1449
1432
|
|
|
1450
1433
|
data.fixtureConfigId = subTemplate._id;
|
|
@@ -1460,72 +1443,72 @@ export async function updateStoreFixture(req, res) {
|
|
|
1460
1443
|
|
|
1461
1444
|
let fixtureCapacity = 0;
|
|
1462
1445
|
|
|
1463
|
-
data.shelfConfig.forEach((shelf) => {
|
|
1446
|
+
data.shelfConfig.forEach( ( shelf ) => {
|
|
1464
1447
|
const { productBrandName: brand, productCategory: category, productSubCategory: subCategory } = shelf;
|
|
1465
1448
|
|
|
1466
|
-
if (typeof shelf?.productPerShelf === 'number') {
|
|
1467
|
-
if (shelf?.shelfType === 'shelf') {
|
|
1449
|
+
if ( typeof shelf?.productPerShelf === 'number' ) {
|
|
1450
|
+
if ( shelf?.shelfType === 'shelf' ) {
|
|
1468
1451
|
fixtureCapacity += shelf.productPerShelf;
|
|
1469
1452
|
}
|
|
1470
1453
|
|
|
1471
|
-
if (shelf?.shelfType === 'tray') {
|
|
1472
|
-
fixtureCapacity += (shelf?.productPerShelf * shelf?.trayRows);
|
|
1454
|
+
if ( shelf?.shelfType === 'tray' ) {
|
|
1455
|
+
fixtureCapacity += ( shelf?.productPerShelf * shelf?.trayRows );
|
|
1473
1456
|
}
|
|
1474
1457
|
}
|
|
1475
1458
|
|
|
1476
|
-
if (Array.isArray(brand)) {
|
|
1477
|
-
brand.forEach((b) => productBrandName.add(b));
|
|
1459
|
+
if ( Array.isArray( brand ) ) {
|
|
1460
|
+
brand.forEach( ( b ) => productBrandName.add( b ) );
|
|
1478
1461
|
}
|
|
1479
1462
|
|
|
1480
|
-
if (Array.isArray(category)) {
|
|
1481
|
-
category.forEach((c) => productCategory.add(c));
|
|
1463
|
+
if ( Array.isArray( category ) ) {
|
|
1464
|
+
category.forEach( ( c ) => productCategory.add( c ) );
|
|
1482
1465
|
}
|
|
1483
1466
|
|
|
1484
|
-
if (Array.isArray(subCategory)) {
|
|
1485
|
-
subCategory.forEach((s) => productSubCategory.add(s));
|
|
1467
|
+
if ( Array.isArray( subCategory ) ) {
|
|
1468
|
+
subCategory.forEach( ( s ) => productSubCategory.add( s ) );
|
|
1486
1469
|
}
|
|
1487
|
-
});
|
|
1470
|
+
} );
|
|
1488
1471
|
|
|
1489
1472
|
|
|
1490
|
-
if (data?.fixtureConfigId && currentFixtureDoc.fixtureConfigId.toString() !== data.fixtureConfigId) {
|
|
1491
|
-
const newTemplate = await fixtureConfigService.findOne({ _id: data.fixtureConfigId });
|
|
1473
|
+
if ( data?.fixtureConfigId && currentFixtureDoc.fixtureConfigId.toString() !== data.fixtureConfigId ) {
|
|
1474
|
+
const newTemplate = await fixtureConfigService.findOne( { _id: data.fixtureConfigId } );
|
|
1492
1475
|
currentFixtureDoc = {
|
|
1493
1476
|
...currentFixtureDoc,
|
|
1494
1477
|
...newTemplate.toObject(),
|
|
1495
1478
|
fixtureConfigId: newTemplate.toObject()._id,
|
|
1496
1479
|
fixtureCapacity: fixtureCapacity,
|
|
1497
|
-
productBrandName: [...productBrandName],
|
|
1498
|
-
productCategory: [...productCategory],
|
|
1499
|
-
productSubCategory: [...productSubCategory],
|
|
1480
|
+
productBrandName: [ ...productBrandName ],
|
|
1481
|
+
productCategory: [ ...productCategory ],
|
|
1482
|
+
productSubCategory: [ ...productSubCategory ],
|
|
1500
1483
|
};
|
|
1501
1484
|
} else {
|
|
1502
1485
|
currentFixtureDoc = {
|
|
1503
1486
|
...currentFixtureDoc,
|
|
1504
1487
|
...data,
|
|
1505
1488
|
fixtureCapacity: fixtureCapacity,
|
|
1506
|
-
productBrandName: [...productBrandName],
|
|
1507
|
-
productCategory: [...productCategory],
|
|
1508
|
-
productSubCategory: [...productSubCategory],
|
|
1489
|
+
productBrandName: [ ...productBrandName ],
|
|
1490
|
+
productCategory: [ ...productCategory ],
|
|
1491
|
+
productSubCategory: [ ...productSubCategory ],
|
|
1509
1492
|
};
|
|
1510
1493
|
}
|
|
1511
1494
|
|
|
1512
|
-
if (data.productResolutionLevel == 'L1') {
|
|
1513
|
-
currentFixtureDoc.productBrandName = [...new Set(data.productBrandName.map((ele) => ele))];
|
|
1514
|
-
currentFixtureDoc.productCategory = [...new Set(data.productCategory.map((ele) => ele))];
|
|
1515
|
-
currentFixtureDoc.productSubCategory = [...new Set(data.productSubCategory.map((ele) => ele))];
|
|
1495
|
+
if ( data.productResolutionLevel == 'L1' ) {
|
|
1496
|
+
currentFixtureDoc.productBrandName = [ ...new Set( data.productBrandName.map( ( ele ) => ele ) ) ];
|
|
1497
|
+
currentFixtureDoc.productCategory = [ ...new Set( data.productCategory.map( ( ele ) => ele ) ) ];
|
|
1498
|
+
currentFixtureDoc.productSubCategory = [ ...new Set( data.productSubCategory.map( ( ele ) => ele ) ) ];
|
|
1516
1499
|
}
|
|
1517
1500
|
|
|
1518
1501
|
|
|
1519
1502
|
delete currentFixtureDoc._id;
|
|
1520
1503
|
|
|
1521
1504
|
|
|
1522
|
-
await storeFixtureService.updateOne({ _id: new mongoose.Types.ObjectId(fixtureId) }, currentFixtureDoc);
|
|
1505
|
+
await storeFixtureService.updateOne( { _id: new mongoose.Types.ObjectId( fixtureId ) }, currentFixtureDoc );
|
|
1523
1506
|
|
|
1524
|
-
if (data?.shelfConfig?.length) {
|
|
1525
|
-
await fixtureShelfService.deleteMany({ fixtureId: new mongoose.Types.ObjectId(fixtureId) });
|
|
1507
|
+
if ( data?.shelfConfig?.length ) {
|
|
1508
|
+
await fixtureShelfService.deleteMany( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) } );
|
|
1526
1509
|
|
|
1527
1510
|
|
|
1528
|
-
data.shelfConfig.forEach(async (shelf) => {
|
|
1511
|
+
data.shelfConfig.forEach( async ( shelf ) => {
|
|
1529
1512
|
delete shelf?._id;
|
|
1530
1513
|
const additionalMeta = {
|
|
1531
1514
|
clientId: currentFixture.clientId,
|
|
@@ -1536,12 +1519,11 @@ export async function updateStoreFixture(req, res) {
|
|
|
1536
1519
|
fixtureId: currentFixture._id,
|
|
1537
1520
|
};
|
|
1538
1521
|
|
|
1539
|
-
await fixtureShelfService.create({ ...additionalMeta, ...shelf });
|
|
1540
|
-
});
|
|
1522
|
+
await fixtureShelfService.create( { ...additionalMeta, ...shelf } );
|
|
1523
|
+
} );
|
|
1541
1524
|
}
|
|
1542
|
-
await planoService.updateOne({ _id: currentFixtureDoc?.planoId }, { $set: { updatedAt: new Date() } });
|
|
1543
|
-
|
|
1544
|
-
if (data?.userAction === 'editWithAi' || data?.userAction === 'editWithPlano') {
|
|
1525
|
+
await planoService.updateOne( { _id: currentFixtureDoc?.planoId }, { $set: { updatedAt: new Date() } } );
|
|
1526
|
+
if ( data?.taskType?.includes( 'fixture' ) ) {
|
|
1545
1527
|
let comments = {
|
|
1546
1528
|
userId: req.user._id,
|
|
1547
1529
|
userName: req.user.userName,
|
|
@@ -1549,151 +1531,85 @@ export async function updateStoreFixture(req, res) {
|
|
|
1549
1531
|
responsetype: 'agree',
|
|
1550
1532
|
comment: '',
|
|
1551
1533
|
};
|
|
1552
|
-
await planoTaskService.updateOne({ planoId: currentFixture.planoId, floorId: currentFixture.floorId, fixtureId: currentFixture._id }, { 'answers.0.status': 'agree', 'approvalStatus': 'approved'
|
|
1553
|
-
|
|
1534
|
+
await planoTaskService.updateOne( { planoId: currentFixture.planoId, floorId: currentFixture.floorId, fixtureId: currentFixture._id }, { 'answers.0.status': 'agree', 'approvalStatus': 'approved' } );
|
|
1554
1535
|
await planoTaskService.updateOnefilters(
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1536
|
+
{ planoId: new mongoose.Types.ObjectId( currentFixture.planoId ), floorId: new mongoose.Types.ObjectId( currentFixture.floorId ), fixtureId: new mongoose.Types.ObjectId( currentFixture._id ) },
|
|
1537
|
+
{
|
|
1538
|
+
$push: { 'answers.0.comments': comments },
|
|
1539
|
+
},
|
|
1559
1540
|
);
|
|
1560
|
-
|
|
1561
1541
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
const op_id = `${data?.storeName}_${data?.storeDate}_${data?._id}`
|
|
1565
|
-
await updateAIFeedbackInOpenSearch(data, op_id);
|
|
1542
|
+
if ( req.body?.editMode ) {
|
|
1543
|
+
await floorService.updateOne( { _id: new mongoose.Types.ObjectId( currentFixture.floorId ) }, { isEdited: true } );
|
|
1566
1544
|
}
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
res.sendSuccess({ message: 'Updated Successfully', ...(configId && { id: configId }) });
|
|
1572
|
-
} catch (e) {
|
|
1573
|
-
logger.error({ functionName: 'updateStoreFixture', error: e });
|
|
1574
|
-
return res.sendError(e, 500);
|
|
1545
|
+
res.sendSuccess( { message: 'Updated Successfully', ...( configId && { id: configId } ) } );
|
|
1546
|
+
} catch ( e ) {
|
|
1547
|
+
logger.error( { functionName: 'updateStoreFixture', error: e } );
|
|
1548
|
+
return res.sendError( e, 500 );
|
|
1575
1549
|
}
|
|
1576
1550
|
}
|
|
1577
1551
|
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
try {
|
|
1581
|
-
let openSearchDetails = await getOpenSearchById(JSON.parse(process.env.OPENSEARCH).planoAIValidation, id);
|
|
1582
|
-
if (openSearchDetails && openSearchDetails.statusCode == 200 && openSearchDetails?.body?._source) {
|
|
1583
|
-
|
|
1584
|
-
const doc = {
|
|
1585
|
-
"fixtureId": fixtureData._id,
|
|
1586
|
-
"fixtureCapacity": fixtureData.fixtureCapacity,
|
|
1587
|
-
"fixtureType": fixtureData.fixtureType,
|
|
1588
|
-
"fixtureCategory": fixtureData.fixtureCategory,
|
|
1589
|
-
"header": {
|
|
1590
|
-
"label": fixtureData.header.label,
|
|
1591
|
-
},
|
|
1592
|
-
"vmConfig": fixtureData?.vmConfig.map(vm => {
|
|
1593
|
-
return {
|
|
1594
|
-
"vmType": vm.vmType,
|
|
1595
|
-
"startYPosition": vm.startYPosition,
|
|
1596
|
-
"endYPosition": vm.endYPosition,
|
|
1597
|
-
"xZone": vm.xZone,
|
|
1598
|
-
"yZone": vm.yZone,
|
|
1599
|
-
"vmImage": vm.vmImage,
|
|
1600
|
-
"vmName": vm.vmName,
|
|
1601
|
-
}
|
|
1602
|
-
}) ?? [
|
|
1603
|
-
|
|
1604
|
-
],
|
|
1605
|
-
"shelfConfig": fixtureData?.shelfConfig.map(s => {
|
|
1606
|
-
return {
|
|
1607
|
-
"shelfNumber": s.shelfNumber,
|
|
1608
|
-
"shelfType": s.shelfType,
|
|
1609
|
-
"productPerShelf": s.productPerShelf,
|
|
1610
|
-
"trayRows": s.trayRows
|
|
1611
|
-
}
|
|
1612
|
-
}) ?? [],
|
|
1613
|
-
"fixtureImage": fixtureData.fixtureImage,
|
|
1614
|
-
"storeDate": fixtureData.storeDate
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
const document = {
|
|
1618
|
-
doc: doc,
|
|
1619
|
-
};
|
|
1620
|
-
|
|
1621
|
-
let updateResult = await updateOpenSearchData(JSON.parse(process.env.OPENSEARCH).planoAIValidation, id, document);
|
|
1622
|
-
|
|
1623
|
-
if (updateResult?.statusCode == 200) {
|
|
1624
|
-
return true;
|
|
1625
|
-
}
|
|
1626
|
-
return false
|
|
1627
|
-
} else {
|
|
1628
|
-
return false
|
|
1629
|
-
}
|
|
1630
|
-
} catch (e) {
|
|
1631
|
-
logger.error({ error: e, function: 'updateAIFeedbackInOpenSearch' });
|
|
1632
|
-
return false
|
|
1633
|
-
}
|
|
1634
|
-
};
|
|
1635
|
-
|
|
1636
|
-
export async function updateredostatus(req, res) {
|
|
1552
|
+
export async function updateredostatus( req, res ) {
|
|
1637
1553
|
try {
|
|
1638
|
-
if (req.body.type === 'layout') {
|
|
1554
|
+
if ( req.body.type === 'layout' ) {
|
|
1639
1555
|
await planoTaskService.updateOne(
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1556
|
+
{
|
|
1557
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
1558
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
1559
|
+
type: req.body.type,
|
|
1560
|
+
},
|
|
1561
|
+
{
|
|
1562
|
+
'answers.$[].issues.$[].status': 'completed',
|
|
1563
|
+
'answers.$[].issues.$[].Details.$[].status': 'agree',
|
|
1564
|
+
'status': 'complete',
|
|
1565
|
+
},
|
|
1650
1566
|
);
|
|
1651
1567
|
} else {
|
|
1652
1568
|
await planoTaskService.updateOne(
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1569
|
+
{
|
|
1570
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
1571
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
1572
|
+
fixtureId: new mongoose.Types.ObjectId( req.body.fixtureId ),
|
|
1573
|
+
type: req.body.type,
|
|
1574
|
+
},
|
|
1575
|
+
{
|
|
1576
|
+
'answers.$[].issues.$[].status': 'completed',
|
|
1577
|
+
'answers.$[].issues.$[].Details.$[].status': 'agree',
|
|
1578
|
+
'status': 'complete',
|
|
1579
|
+
},
|
|
1664
1580
|
);
|
|
1665
1581
|
}
|
|
1666
|
-
res.sendSuccess('updated successfully');
|
|
1667
|
-
} catch (e) {
|
|
1668
|
-
logger.error({ functionName: 'updateredostatus', error: e });
|
|
1669
|
-
return res.sendError(e, 500);
|
|
1582
|
+
res.sendSuccess( 'updated successfully' );
|
|
1583
|
+
} catch ( e ) {
|
|
1584
|
+
logger.error( { functionName: 'updateredostatus', error: e } );
|
|
1585
|
+
return res.sendError( e, 500 );
|
|
1670
1586
|
}
|
|
1671
1587
|
}
|
|
1672
1588
|
|
|
1673
1589
|
|
|
1674
|
-
export async function updateGlobalComment(req, res) {
|
|
1590
|
+
export async function updateGlobalComment( req, res ) {
|
|
1675
1591
|
try {
|
|
1676
1592
|
let payload = {
|
|
1677
1593
|
userId: req.user._id,
|
|
1678
1594
|
userName: req.user.userName,
|
|
1679
1595
|
comment: req.body.comment,
|
|
1680
1596
|
responsetype: req.body.responsetype,
|
|
1681
|
-
planoId: new mongoose.Types.ObjectId(req.body.planoId),
|
|
1682
|
-
floorId: new mongoose.Types.ObjectId(req.body.floorId),
|
|
1597
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
1598
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
1683
1599
|
taskType: req.body.taskType,
|
|
1684
1600
|
clientId: req.body.clientId,
|
|
1685
1601
|
taskId: req.body.taskId,
|
|
1686
1602
|
};
|
|
1687
|
-
await planoGlobalCommentService.create(payload);
|
|
1688
|
-
await insertOpenSearchData(JSON.parse(process.env.OPENSEARCH).planoglobalcomments, payload);
|
|
1603
|
+
await planoGlobalCommentService.create( payload );
|
|
1604
|
+
await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).planoglobalcomments, payload );
|
|
1689
1605
|
|
|
1690
|
-
res.sendSuccess('updated successfully');
|
|
1691
|
-
} catch (e) {
|
|
1692
|
-
logger.error({ functionName: 'updateGlobalComment', error: e });
|
|
1693
|
-
return res.sendError(e, 500);
|
|
1606
|
+
res.sendSuccess( 'updated successfully' );
|
|
1607
|
+
} catch ( e ) {
|
|
1608
|
+
logger.error( { functionName: 'updateGlobalComment', error: e } );
|
|
1609
|
+
return res.sendError( e, 500 );
|
|
1694
1610
|
}
|
|
1695
1611
|
}
|
|
1696
|
-
export async function getGlobalComment(req, res) {
|
|
1612
|
+
export async function getGlobalComment( req, res ) {
|
|
1697
1613
|
try {
|
|
1698
1614
|
// let layoutComment = await planoGlobalCommentService.find( {
|
|
1699
1615
|
// planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
@@ -1702,147 +1618,147 @@ export async function getGlobalComment(req, res) {
|
|
|
1702
1618
|
// } );
|
|
1703
1619
|
|
|
1704
1620
|
let taskId = [];
|
|
1705
|
-
if (req.body?.taskId) {
|
|
1706
|
-
taskId.push(new mongoose.Types.ObjectId(req.body.taskId));
|
|
1621
|
+
if ( req.body?.taskId ) {
|
|
1622
|
+
taskId.push( new mongoose.Types.ObjectId( req.body.taskId ) );
|
|
1707
1623
|
}
|
|
1708
1624
|
|
|
1709
|
-
if (req.body?.refTaskId) {
|
|
1710
|
-
taskId.push(new mongoose.Types.ObjectId(req.body.refTaskId));
|
|
1625
|
+
if ( req.body?.refTaskId ) {
|
|
1626
|
+
taskId.push( new mongoose.Types.ObjectId( req.body.refTaskId ) );
|
|
1711
1627
|
}
|
|
1712
1628
|
|
|
1713
|
-
let layoutComment = await planoGlobalCommentService.find({
|
|
1714
|
-
planoId: new mongoose.Types.ObjectId(req.body.planoId),
|
|
1715
|
-
floorId: new mongoose.Types.ObjectId(req.body.floorId),
|
|
1716
|
-
...(taskId.length && { taskId: { $in: taskId } }),
|
|
1629
|
+
let layoutComment = await planoGlobalCommentService.find( {
|
|
1630
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
1631
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
1632
|
+
...( taskId.length && { taskId: { $in: taskId } } ),
|
|
1717
1633
|
taskType: req.body.taskType,
|
|
1718
|
-
});
|
|
1634
|
+
} );
|
|
1719
1635
|
|
|
1720
|
-
res.sendSuccess(layoutComment);
|
|
1721
|
-
} catch (e) {
|
|
1722
|
-
logger.error({ functionName: 'getGlobalComment', error: e });
|
|
1723
|
-
return res.sendError(e, 500);
|
|
1636
|
+
res.sendSuccess( layoutComment );
|
|
1637
|
+
} catch ( e ) {
|
|
1638
|
+
logger.error( { functionName: 'getGlobalComment', error: e } );
|
|
1639
|
+
return res.sendError( e, 500 );
|
|
1724
1640
|
}
|
|
1725
1641
|
}
|
|
1726
1642
|
|
|
1727
|
-
export async function getAllPlanoRevisions(req, res) {
|
|
1643
|
+
export async function getAllPlanoRevisions( req, res ) {
|
|
1728
1644
|
try {
|
|
1729
1645
|
const { clientId } = req.body;
|
|
1730
1646
|
|
|
1731
|
-
if (!clientId) {
|
|
1732
|
-
return res.sendError('Client Id is required', 400);
|
|
1647
|
+
if ( !clientId ) {
|
|
1648
|
+
return res.sendError( 'Client Id is required', 400 );
|
|
1733
1649
|
}
|
|
1734
1650
|
|
|
1735
1651
|
const revisions = await planoRevisionService.find(
|
|
1736
|
-
|
|
1737
|
-
|
|
1652
|
+
{ clientId },
|
|
1653
|
+
{ storeName: 1, storeId: 1, planoId: 1, floorId: 1, createdAt: 1 },
|
|
1738
1654
|
);
|
|
1739
1655
|
|
|
1740
|
-
res.sendSuccess(revisions);
|
|
1741
|
-
} catch (e) {
|
|
1742
|
-
logger.error({ functionName: 'getAllPlanoRevisions', error: e });
|
|
1743
|
-
res.sendError('Failed to fetch plano revisions', 500);
|
|
1656
|
+
res.sendSuccess( revisions );
|
|
1657
|
+
} catch ( e ) {
|
|
1658
|
+
logger.error( { functionName: 'getAllPlanoRevisions', error: e } );
|
|
1659
|
+
res.sendError( 'Failed to fetch plano revisions', 500 );
|
|
1744
1660
|
}
|
|
1745
1661
|
}
|
|
1746
1662
|
|
|
1747
|
-
export async function createPlanoRevision(req, res) {
|
|
1663
|
+
export async function createPlanoRevision( req, res ) {
|
|
1748
1664
|
try {
|
|
1749
1665
|
const { storeName, storeId, clientId, planoId, floorId, floorData } = req.body;
|
|
1750
1666
|
|
|
1751
|
-
if (!storeName || !storeId || !clientId || !planoId || !floorId || !floorData) {
|
|
1752
|
-
return res.sendError('Missing required fields', 400);
|
|
1667
|
+
if ( !storeName || !storeId || !clientId || !planoId || !floorId || !floorData ) {
|
|
1668
|
+
return res.sendError( 'Missing required fields', 400 );
|
|
1753
1669
|
}
|
|
1754
1670
|
|
|
1755
|
-
const newRevision = await planoRevisionService.create({
|
|
1671
|
+
const newRevision = await planoRevisionService.create( {
|
|
1756
1672
|
storeName,
|
|
1757
1673
|
storeId,
|
|
1758
1674
|
clientId,
|
|
1759
1675
|
planoId,
|
|
1760
1676
|
floorId,
|
|
1761
1677
|
floorData,
|
|
1762
|
-
});
|
|
1678
|
+
} );
|
|
1763
1679
|
|
|
1764
|
-
res.sendSuccess(newRevision);
|
|
1765
|
-
} catch (e) {
|
|
1766
|
-
logger.error({ functionName: 'createPlanoRevision', error: e });
|
|
1767
|
-
res.sendError('Failed to create plano revision', 500);
|
|
1680
|
+
res.sendSuccess( newRevision );
|
|
1681
|
+
} catch ( e ) {
|
|
1682
|
+
logger.error( { functionName: 'createPlanoRevision', error: e } );
|
|
1683
|
+
res.sendError( 'Failed to create plano revision', 500 );
|
|
1768
1684
|
}
|
|
1769
1685
|
}
|
|
1770
1686
|
|
|
1771
|
-
export async function getPlanoRevisionById(req, res) {
|
|
1687
|
+
export async function getPlanoRevisionById( req, res ) {
|
|
1772
1688
|
try {
|
|
1773
1689
|
const { id } = req.params;
|
|
1774
1690
|
|
|
1775
|
-
if (!id) {
|
|
1776
|
-
return res.sendError('Revision ID is required', 400);
|
|
1691
|
+
if ( !id ) {
|
|
1692
|
+
return res.sendError( 'Revision ID is required', 400 );
|
|
1777
1693
|
}
|
|
1778
1694
|
|
|
1779
1695
|
const revision = await planoRevisionService.findOne(
|
|
1780
|
-
|
|
1696
|
+
{ _id: id },
|
|
1781
1697
|
);
|
|
1782
1698
|
|
|
1783
|
-
if (!revision) {
|
|
1784
|
-
return res.sendError('Plano revision not found', 404);
|
|
1699
|
+
if ( !revision ) {
|
|
1700
|
+
return res.sendError( 'Plano revision not found', 404 );
|
|
1785
1701
|
}
|
|
1786
1702
|
|
|
1787
|
-
res.sendSuccess(revision);
|
|
1788
|
-
} catch (e) {
|
|
1789
|
-
logger.error({ functionName: 'getPlanoRevisionById', error: e });
|
|
1790
|
-
res.sendError('Failed to fetch plano revision', 500);
|
|
1703
|
+
res.sendSuccess( revision );
|
|
1704
|
+
} catch ( e ) {
|
|
1705
|
+
logger.error( { functionName: 'getPlanoRevisionById', error: e } );
|
|
1706
|
+
res.sendError( 'Failed to fetch plano revision', 500 );
|
|
1791
1707
|
}
|
|
1792
1708
|
}
|
|
1793
|
-
export async function getRolloutFeedback(req, res) {
|
|
1709
|
+
export async function getRolloutFeedback( req, res ) {
|
|
1794
1710
|
try {
|
|
1795
|
-
const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : ['merchRollout', 'vmRollout'];
|
|
1711
|
+
const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : [ 'merchRollout', 'vmRollout' ];
|
|
1796
1712
|
const filterByStatus = req.body.filterByStatus || [];
|
|
1797
1713
|
const filterByApprovalStatus = req.body.filterByApprovalStatus || '';
|
|
1798
1714
|
const resultMap = {};
|
|
1799
1715
|
const commentMap = {};
|
|
1800
|
-
if (req.body.redo) {
|
|
1801
|
-
let taskDetails = await planoTaskService.findOne({ taskId: req.body.taskId, fixtureId: req.body.fixtureId });
|
|
1802
|
-
if (!taskDetails) {
|
|
1716
|
+
if ( req.body.redo ) {
|
|
1717
|
+
let taskDetails = await planoTaskService.findOne( { taskId: req.body.taskId, fixtureId: req.body.fixtureId } );
|
|
1718
|
+
if ( !taskDetails ) {
|
|
1803
1719
|
req.body.taskId = req.body.refTaskId;
|
|
1804
1720
|
}
|
|
1805
1721
|
}
|
|
1806
1722
|
await Promise.all(
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1723
|
+
taskTypes.map( async ( type, index ) => {
|
|
1724
|
+
const pipeline = buildPipelineByType( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask, req.body.taskId );
|
|
1725
|
+
|
|
1726
|
+
let data = await planoTaskService.aggregate( pipeline );
|
|
1727
|
+
if ( filterByApprovalStatus && filterByApprovalStatus !== '' ) {
|
|
1728
|
+
data.forEach( ( element ) => {
|
|
1729
|
+
element.answers?.forEach( ( ans ) => {
|
|
1730
|
+
ans.issues = ans.issues?.filter(
|
|
1731
|
+
( issue ) => issue.Details && issue.Details.length > 0,
|
|
1732
|
+
);
|
|
1733
|
+
} );
|
|
1734
|
+
element.answers = element.answers?.filter(
|
|
1735
|
+
( ans ) => ans.issues && ans.issues.length > 0,
|
|
1816
1736
|
);
|
|
1817
|
-
});
|
|
1818
|
-
|
|
1819
|
-
|
|
1737
|
+
} );
|
|
1738
|
+
data = data.filter(
|
|
1739
|
+
( element ) => element.answers && element.answers.length > 0,
|
|
1820
1740
|
);
|
|
1821
|
-
}
|
|
1822
|
-
data = data.filter(
|
|
1823
|
-
(element) => element.answers && element.answers.length > 0,
|
|
1824
|
-
);
|
|
1825
|
-
}
|
|
1741
|
+
}
|
|
1826
1742
|
|
|
1827
1743
|
|
|
1828
|
-
|
|
1744
|
+
resultMap[type] = data;
|
|
1829
1745
|
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1746
|
+
let taskId = [];
|
|
1747
|
+
if ( req.body.taskId ) {
|
|
1748
|
+
taskId.push( new mongoose.Types.ObjectId( req.body.taskId ) );
|
|
1749
|
+
}
|
|
1750
|
+
if ( req.body.refTaskId ) {
|
|
1751
|
+
taskId.push( new mongoose.Types.ObjectId( req.body.refTaskId ) );
|
|
1752
|
+
}
|
|
1837
1753
|
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1754
|
+
const comments = await planoGlobalCommentService.find( {
|
|
1755
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
1756
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
1757
|
+
...( taskId.length && { taskId: { $in: taskId } } ),
|
|
1758
|
+
taskType: type,
|
|
1759
|
+
} );
|
|
1760
|
+
commentMap[type] = comments;
|
|
1761
|
+
} ),
|
|
1846
1762
|
);
|
|
1847
1763
|
const response = {
|
|
1848
1764
|
merchRolloutData: resultMap['merchRollout'] || [],
|
|
@@ -1851,39 +1767,39 @@ export async function getRolloutFeedback(req, res) {
|
|
|
1851
1767
|
vmRolloutComment: commentMap['vmRollout'] || [],
|
|
1852
1768
|
};
|
|
1853
1769
|
|
|
1854
|
-
res.sendSuccess(response);
|
|
1855
|
-
} catch (e) {
|
|
1856
|
-
logger.error({ functionName: 'getRolloutFeedback', error: e });
|
|
1857
|
-
return res.sendError(e, 500);
|
|
1770
|
+
res.sendSuccess( response );
|
|
1771
|
+
} catch ( e ) {
|
|
1772
|
+
logger.error( { functionName: 'getRolloutFeedback', error: e } );
|
|
1773
|
+
return res.sendError( e, 500 );
|
|
1858
1774
|
}
|
|
1859
1775
|
}
|
|
1860
1776
|
|
|
1861
1777
|
|
|
1862
|
-
export async function getRolloutFeedbackv2(req, res) {
|
|
1778
|
+
export async function getRolloutFeedbackv2( req, res ) {
|
|
1863
1779
|
try {
|
|
1864
|
-
const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : ['merchRollout', 'vmRollout'];
|
|
1780
|
+
const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : [ 'merchRollout', 'vmRollout' ];
|
|
1865
1781
|
const filterByStatus = req.body.filterByStatus || [];
|
|
1866
1782
|
const filterByApprovalStatus = req.body.filterByApprovalStatus || '';
|
|
1867
1783
|
const resultMap = {};
|
|
1868
1784
|
const commentMap = {};
|
|
1869
1785
|
await Promise.all(
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1786
|
+
taskTypes.map( async ( type, index ) => {
|
|
1787
|
+
const pipeline = pipelineStage( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask );
|
|
1788
|
+
const data = await processedTaskService.aggregate( pipeline );
|
|
1789
|
+
resultMap[type] = data;
|
|
1790
|
+
} ) );
|
|
1875
1791
|
const response = {
|
|
1876
1792
|
merchRolloutData: resultMap['merchRollout'] || [],
|
|
1877
1793
|
vmRolloutData: resultMap['vmRollout'] || [],
|
|
1878
1794
|
merchRolloutComment: commentMap['merchRollout'] || [],
|
|
1879
1795
|
vmRolloutComment: commentMap['vmRollout'] || [],
|
|
1880
1796
|
};
|
|
1881
|
-
if (filterByStatus.length || filterByApprovalStatus) {
|
|
1882
|
-
let data = response[`${req.body.type}RolloutData`].filter((ele) => ele.storeFixtureList.length);
|
|
1883
|
-
if (filterByStatus.length == 1) {
|
|
1884
|
-
data = data.filter((type) => {
|
|
1885
|
-
let fixtureList = type.storeFixtureList.filter((ele) => filterByStatus.includes(ele.status));
|
|
1886
|
-
if (filterByStatus.includes('complete')) {
|
|
1797
|
+
if ( filterByStatus.length || filterByApprovalStatus ) {
|
|
1798
|
+
let data = response[`${req.body.type}RolloutData`].filter( ( ele ) => ele.storeFixtureList.length );
|
|
1799
|
+
if ( filterByStatus.length == 1 ) {
|
|
1800
|
+
data = data.filter( ( type ) => {
|
|
1801
|
+
let fixtureList = type.storeFixtureList.filter( ( ele ) => filterByStatus.includes( ele.status ) );
|
|
1802
|
+
if ( filterByStatus.includes( 'complete' ) ) {
|
|
1887
1803
|
return type.storeFixtureList.length == fixtureList.length;
|
|
1888
1804
|
} else {
|
|
1889
1805
|
return fixtureList.length;
|
|
@@ -1891,69 +1807,69 @@ export async function getRolloutFeedbackv2(req, res) {
|
|
|
1891
1807
|
},
|
|
1892
1808
|
);
|
|
1893
1809
|
}
|
|
1894
|
-
if (filterByApprovalStatus) {
|
|
1895
|
-
if (filterByApprovalStatus === 'pending') {
|
|
1896
|
-
data = data.filter((type) => {
|
|
1897
|
-
let fixtureList = type.storeFixtureList.filter((ele) => {
|
|
1898
|
-
if (ele.status === 'complete' && !ele.answers?.[0]?.issues.length && !ele.answers?.[0]?.status) {
|
|
1810
|
+
if ( filterByApprovalStatus ) {
|
|
1811
|
+
if ( filterByApprovalStatus === 'pending' ) {
|
|
1812
|
+
data = data.filter( ( type ) => {
|
|
1813
|
+
let fixtureList = type.storeFixtureList.filter( ( ele ) => {
|
|
1814
|
+
if ( ele.status === 'complete' && !ele.answers?.[0]?.issues.length && !ele.answers?.[0]?.status ) {
|
|
1899
1815
|
return true;
|
|
1900
1816
|
} else {
|
|
1901
|
-
return ele.answers?.some((ans) =>
|
|
1902
|
-
ans.issues?.some((issue) =>
|
|
1903
|
-
issue?.Details?.some((detail) => detail.status === 'pending'),
|
|
1817
|
+
return ele.answers?.some( ( ans ) =>
|
|
1818
|
+
ans.issues?.some( ( issue ) =>
|
|
1819
|
+
issue?.Details?.some( ( detail ) => detail.status === 'pending' ),
|
|
1904
1820
|
),
|
|
1905
1821
|
);
|
|
1906
1822
|
}
|
|
1907
|
-
});
|
|
1823
|
+
} );
|
|
1908
1824
|
|
|
1909
1825
|
return fixtureList.length;
|
|
1910
|
-
});
|
|
1826
|
+
} );
|
|
1911
1827
|
} else {
|
|
1912
|
-
data = data.filter((type) => {
|
|
1913
|
-
let fixtureList = type.storeFixtureList.filter((ele) => {
|
|
1914
|
-
if (ele.status === 'complete' && !ele.answers?.[0]?.issues.length && ele.answers?.[0]?.status) {
|
|
1828
|
+
data = data.filter( ( type ) => {
|
|
1829
|
+
let fixtureList = type.storeFixtureList.filter( ( ele ) => {
|
|
1830
|
+
if ( ele.status === 'complete' && !ele.answers?.[0]?.issues.length && ele.answers?.[0]?.status ) {
|
|
1915
1831
|
return true;
|
|
1916
1832
|
} else {
|
|
1917
|
-
return ele.answers?.some((ans) =>
|
|
1918
|
-
ans.issues?.some((issue) =>
|
|
1919
|
-
issue?.Details?.some((detail) => detail.status !== 'pending'),
|
|
1833
|
+
return ele.answers?.some( ( ans ) =>
|
|
1834
|
+
ans.issues?.some( ( issue ) =>
|
|
1835
|
+
issue?.Details?.some( ( detail ) => detail.status !== 'pending' ),
|
|
1920
1836
|
),
|
|
1921
1837
|
);
|
|
1922
1838
|
}
|
|
1923
|
-
});
|
|
1839
|
+
} );
|
|
1924
1840
|
|
|
1925
1841
|
return fixtureList.length;
|
|
1926
|
-
});
|
|
1842
|
+
} );
|
|
1927
1843
|
}
|
|
1928
1844
|
}
|
|
1929
1845
|
response[`${req.body.type}RolloutData`] = data;
|
|
1930
1846
|
}
|
|
1931
|
-
response.vmRolloutData = await Promise.all(response.vmRolloutData.map(async (ele) => {
|
|
1932
|
-
ele.storeFixtureList = await Promise.all(ele.storeFixtureList.map(async (fixt) => {
|
|
1933
|
-
if (fixt?.FixtureData?.vmConfig?.length) {
|
|
1934
|
-
fixt.FixtureData.vmConfig = await Promise.all(fixt?.FixtureData?.vmConfig?.map(async (config) => {
|
|
1935
|
-
let vmDetails = await planoVmService.findOne({ _id: config.vmId }, { vmType: 1, vmName: 1 });
|
|
1847
|
+
response.vmRolloutData = await Promise.all( response.vmRolloutData.map( async ( ele ) => {
|
|
1848
|
+
ele.storeFixtureList = await Promise.all( ele.storeFixtureList.map( async ( fixt ) => {
|
|
1849
|
+
if ( fixt?.FixtureData?.vmConfig?.length ) {
|
|
1850
|
+
fixt.FixtureData.vmConfig = await Promise.all( fixt?.FixtureData?.vmConfig?.map( async ( config ) => {
|
|
1851
|
+
let vmDetails = await planoVmService.findOne( { _id: config.vmId }, { vmType: 1, vmName: 1 } );
|
|
1936
1852
|
return { ...config, vmType: vmDetails.vmType, vmName: vmDetails.vmName };
|
|
1937
|
-
}));
|
|
1853
|
+
} ) );
|
|
1938
1854
|
}
|
|
1939
1855
|
return fixt;
|
|
1940
|
-
}));
|
|
1856
|
+
} ) );
|
|
1941
1857
|
return ele;
|
|
1942
|
-
}));
|
|
1943
|
-
res.sendSuccess(response);
|
|
1944
|
-
} catch (e) {
|
|
1945
|
-
logger.error({ functionName: 'getRolloutFeedbackv2', error: e });
|
|
1946
|
-
return res.sendError(e, 500);
|
|
1858
|
+
} ) );
|
|
1859
|
+
res.sendSuccess( response );
|
|
1860
|
+
} catch ( e ) {
|
|
1861
|
+
logger.error( { functionName: 'getRolloutFeedbackv2', error: e } );
|
|
1862
|
+
return res.sendError( e, 500 );
|
|
1947
1863
|
}
|
|
1948
1864
|
}
|
|
1949
1865
|
|
|
1950
1866
|
|
|
1951
|
-
function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0) {
|
|
1952
|
-
let matchStage = [{
|
|
1867
|
+
function pipelineStage( type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0 ) {
|
|
1868
|
+
let matchStage = [ {
|
|
1953
1869
|
$match: {
|
|
1954
1870
|
'planoType': type,
|
|
1955
|
-
'planoId': new mongoose.Types.ObjectId(planoId),
|
|
1956
|
-
'floorId': new mongoose.Types.ObjectId(floorId),
|
|
1871
|
+
'planoId': new mongoose.Types.ObjectId( planoId ),
|
|
1872
|
+
'floorId': new mongoose.Types.ObjectId( floorId ),
|
|
1957
1873
|
},
|
|
1958
1874
|
},
|
|
1959
1875
|
|
|
@@ -1981,7 +1897,7 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
|
|
|
1981
1897
|
$match: {
|
|
1982
1898
|
$expr: {
|
|
1983
1899
|
$and: [
|
|
1984
|
-
{ $eq: ['$taskId', '$$taskId'] },
|
|
1900
|
+
{ $eq: [ '$taskId', '$$taskId' ] },
|
|
1985
1901
|
],
|
|
1986
1902
|
},
|
|
1987
1903
|
},
|
|
@@ -2005,7 +1921,7 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
|
|
|
2005
1921
|
{
|
|
2006
1922
|
$match: {
|
|
2007
1923
|
$expr: {
|
|
2008
|
-
$eq: ['$taskId', '$$taskId'],
|
|
1924
|
+
$eq: [ '$taskId', '$$taskId' ],
|
|
2009
1925
|
},
|
|
2010
1926
|
},
|
|
2011
1927
|
},
|
|
@@ -2023,7 +1939,7 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
|
|
|
2023
1939
|
let: { fixtureId: '$planoData.fixtureId' },
|
|
2024
1940
|
pipeline: [
|
|
2025
1941
|
{
|
|
2026
|
-
$match: { $expr: { $eq: ['$_id', '$$fixtureId'] } },
|
|
1942
|
+
$match: { $expr: { $eq: [ '$_id', '$$fixtureId' ] } },
|
|
2027
1943
|
},
|
|
2028
1944
|
],
|
|
2029
1945
|
as: 'FixtureData',
|
|
@@ -2038,7 +1954,7 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
|
|
|
2038
1954
|
let: { fixtureId: '$FixtureData._id' },
|
|
2039
1955
|
pipeline: [
|
|
2040
1956
|
{
|
|
2041
|
-
$match: { $expr: { $eq: ['$fixtureId', '$$fixtureId'] } },
|
|
1957
|
+
$match: { $expr: { $eq: [ '$fixtureId', '$$fixtureId' ] } },
|
|
2042
1958
|
},
|
|
2043
1959
|
],
|
|
2044
1960
|
as: 'Fixtureshelves',
|
|
@@ -2073,16 +1989,16 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
|
|
|
2073
1989
|
$and: [
|
|
2074
1990
|
{
|
|
2075
1991
|
$or: [
|
|
2076
|
-
{ $eq: ['$redoStatus', true] },
|
|
1992
|
+
{ $eq: [ '$redoStatus', true ] },
|
|
2077
1993
|
{
|
|
2078
1994
|
$and: [
|
|
2079
|
-
{ $eq: ['$redoStatus', false] },
|
|
2080
|
-
{ $eq: ['$checklistStatus', 'submit'] },
|
|
1995
|
+
{ $eq: [ '$redoStatus', false ] },
|
|
1996
|
+
{ $eq: [ '$checklistStatus', 'submit' ] },
|
|
2081
1997
|
],
|
|
2082
1998
|
},
|
|
2083
1999
|
],
|
|
2084
2000
|
},
|
|
2085
|
-
{ $ne: [{ $ifNull: ['$FixtureData.fixtureName', null] }, null] },
|
|
2001
|
+
{ $ne: [ { $ifNull: [ '$FixtureData.fixtureName', null ] }, null ] },
|
|
2086
2002
|
// { $gt: [ { $size: { $ifNull: [ '$FixtureData' ] } }, 0 ] },
|
|
2087
2003
|
// { $gt: [ { $size: { $ifNull: [ '$FixtureData.shelfConfig', [] ] } }, 0 ] },
|
|
2088
2004
|
],
|
|
@@ -2129,48 +2045,3 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
|
|
|
2129
2045
|
|
|
2130
2046
|
return pipeline;
|
|
2131
2047
|
}
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
export async function getPlanoStoreVideoPageParams(req, res) {
|
|
2135
|
-
try {
|
|
2136
|
-
const { storeId } = req.body;
|
|
2137
|
-
|
|
2138
|
-
if (!storeId) {
|
|
2139
|
-
return res.sendError('Store ID Missing.', 400);
|
|
2140
|
-
}
|
|
2141
|
-
|
|
2142
|
-
const checkListRes = await planoStaticService.findOne({ type: 'storeVideoChecklist' }, { checklistIds: 1 });
|
|
2143
|
-
|
|
2144
|
-
if (checkListRes?.checklistIds?.length <= 0) {
|
|
2145
|
-
return res.sendError('No checklist ids found', 400);
|
|
2146
|
-
}
|
|
2147
|
-
|
|
2148
|
-
const checklistData = await processedChecklistService.findOne(
|
|
2149
|
-
{
|
|
2150
|
-
sourceCheckList_id: {
|
|
2151
|
-
$in: checkListRes?.checklistIds ?? [],
|
|
2152
|
-
},
|
|
2153
|
-
checklistStatus: "submit",
|
|
2154
|
-
store_id: storeId,
|
|
2155
|
-
checkListType: "custom",
|
|
2156
|
-
}, {}, { sort: { _id: -1 } }
|
|
2157
|
-
);
|
|
2158
|
-
|
|
2159
|
-
if (!checklistData) {
|
|
2160
|
-
return res.sendError('No checklist data found', 400);
|
|
2161
|
-
}
|
|
2162
|
-
|
|
2163
|
-
const response = {
|
|
2164
|
-
storeId: storeId,
|
|
2165
|
-
ChecklistDate: checklistData?.date_string,
|
|
2166
|
-
checklistType: checklistData?.checkListType,
|
|
2167
|
-
checklistStatus: checklistData?.checklistStatus,
|
|
2168
|
-
sourceCheckList_id: checklistData?.sourceCheckList_id,
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
|
-
res.sendSuccess(response);
|
|
2172
|
-
} catch (e) {
|
|
2173
|
-
logger.error({ functionName: 'getPlanoStoreVideoPageParams', error: e });
|
|
2174
|
-
res.sendError('Failed to fetch plano store video page params', 500);
|
|
2175
|
-
}
|
|
2176
|
-
}
|