tango-app-api-store-builder 1.0.14 → 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,28 +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
|
|
897
|
-
for (let i = 0; i < currentFixtures.length; i++) {
|
|
882
|
+
for ( let i = 0; i < currentFixtures.length; i++ ) {
|
|
898
883
|
const fixture = currentFixtures[i];
|
|
899
884
|
|
|
900
|
-
if (mongoose.Types.ObjectId.isValid(fixture._id)) {
|
|
885
|
+
if ( mongoose.Types.ObjectId.isValid( fixture._id ) ) {
|
|
901
886
|
const updatedFixture = await storeFixtureService.upsertOne(
|
|
902
|
-
|
|
903
|
-
|
|
887
|
+
{ _id: new mongoose.Types.ObjectId( fixture._id ) },
|
|
888
|
+
fixture,
|
|
904
889
|
);
|
|
905
890
|
|
|
906
891
|
await storeFixtureService.removeKeys(
|
|
907
|
-
|
|
908
|
-
|
|
892
|
+
{ fixtureType: 'floor', _id: fixture._id },
|
|
893
|
+
{ $unset: { associatedElementType: '', associatedElementNumber: '' } },
|
|
909
894
|
);
|
|
910
895
|
|
|
911
|
-
await fixtureShelfService.deleteMany({ fixtureId: new mongoose.Types.ObjectId(fixture._id) });
|
|
896
|
+
await fixtureShelfService.deleteMany( { fixtureId: new mongoose.Types.ObjectId( fixture._id ) } );
|
|
912
897
|
|
|
913
|
-
for (let j = 0; j < fixture.shelfConfig.length; j++) {
|
|
898
|
+
for ( let j = 0; j < fixture.shelfConfig.length; j++ ) {
|
|
914
899
|
const shelf = fixture.shelfConfig[j];
|
|
915
900
|
|
|
916
901
|
delete shelf._id;
|
|
@@ -921,87 +906,109 @@ export async function updateStorePlano(req, res) {
|
|
|
921
906
|
fixtureId: updatedFixture.toObject()._id,
|
|
922
907
|
};
|
|
923
908
|
|
|
924
|
-
await fixtureShelfService.create(shelfPayload);
|
|
909
|
+
await fixtureShelfService.create( shelfPayload );
|
|
925
910
|
}
|
|
926
911
|
}
|
|
927
912
|
}
|
|
928
913
|
|
|
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
|
-
res.sendSuccess('Updated Successfully');
|
|
935
|
-
} catch (e) {
|
|
936
|
-
logger.error({ functionName: 'updateStorePlano', error: e });
|
|
937
|
-
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 );
|
|
938
925
|
}
|
|
939
926
|
}
|
|
940
927
|
|
|
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 ) {
|
|
933
|
+
return a.associatedElementNumber - b.associatedElementNumber;
|
|
934
|
+
}
|
|
941
935
|
|
|
942
|
-
|
|
936
|
+
return a.associatedElementFixtureNumber - b.associatedElementFixtureNumber;
|
|
937
|
+
} );
|
|
938
|
+
let fixtureNumber = 0;
|
|
939
|
+
for ( let fixture of fixtureDetails ) {
|
|
940
|
+
fixtureNumber++;
|
|
941
|
+
storeFixtureService.updateOne( { _id: fixture._id }, { fixtureNumber: fixtureNumber } );
|
|
942
|
+
}
|
|
943
|
+
} catch ( e ) {
|
|
944
|
+
logger.error( { functionName: 'updateFixtureNumber', error: e } );
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
export async function fixtureList( req, res ) {
|
|
943
950
|
try {
|
|
944
|
-
let findData = await fixtureLibraryService.find({ clientId: req.query.clientId });
|
|
945
|
-
if (findData.length === 0) {
|
|
946
|
-
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 );
|
|
947
954
|
}
|
|
948
|
-
res.sendSuccess(findData);
|
|
949
|
-
} catch (e) {
|
|
950
|
-
logger.error({ functionName: 'fixtureList', error: e });
|
|
951
|
-
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 );
|
|
952
959
|
}
|
|
953
960
|
}
|
|
954
|
-
export async function templateList(req, res) {
|
|
961
|
+
export async function templateList( req, res ) {
|
|
955
962
|
try {
|
|
956
|
-
let findData = await fixtureConfigService.find({ clientId: req.query.clientId, fixtureLibraryId: new mongoose.Types.ObjectId(req.query.fixtureId) });
|
|
957
|
-
if (findData.length === 0) {
|
|
958
|
-
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 );
|
|
959
966
|
}
|
|
960
|
-
res.sendSuccess(findData);
|
|
961
|
-
} catch (e) {
|
|
962
|
-
logger.error({ functionName: 'templateList', error: e });
|
|
963
|
-
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 );
|
|
964
971
|
}
|
|
965
972
|
}
|
|
966
|
-
export async function fixtureBrandsList(req, res) {
|
|
973
|
+
export async function fixtureBrandsList( req, res ) {
|
|
967
974
|
try {
|
|
968
|
-
let findData = await planoproductCategoryService.find({ clientId: req.query.clientId });
|
|
969
|
-
if (findData.length === 0) {
|
|
970
|
-
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 );
|
|
971
978
|
}
|
|
972
|
-
res.sendSuccess(findData);
|
|
973
|
-
} catch (e) {
|
|
974
|
-
logger.error({ functionName: 'fixtureBrandsList', error: e });
|
|
975
|
-
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 );
|
|
976
983
|
}
|
|
977
984
|
}
|
|
978
985
|
|
|
979
|
-
export async function fixtureVMList(req, res) {
|
|
986
|
+
export async function fixtureVMList( req, res ) {
|
|
980
987
|
try {
|
|
981
|
-
let findData = await planoVmService.find({ clientId: req.query.clientId });
|
|
982
|
-
if (findData.length === 0) {
|
|
983
|
-
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 );
|
|
984
991
|
}
|
|
985
|
-
res.sendSuccess(findData);
|
|
986
|
-
} catch (e) {
|
|
987
|
-
logger.error({ functionName: 'fixtureVMList', error: e });
|
|
988
|
-
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 );
|
|
989
996
|
}
|
|
990
997
|
}
|
|
991
998
|
|
|
992
|
-
export async function fixtureVMListv1(req, res) {
|
|
999
|
+
export async function fixtureVMListv1( req, res ) {
|
|
993
1000
|
try {
|
|
994
|
-
let findData = await planoVmDuplicateService.find({ clientId: req.query.clientId });
|
|
995
|
-
if (findData.length === 0) {
|
|
996
|
-
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 );
|
|
997
1004
|
}
|
|
998
|
-
res.sendSuccess(findData);
|
|
999
|
-
} catch (e) {
|
|
1000
|
-
logger.error({ functionName: 'fixtureVMListv1', error: e });
|
|
1001
|
-
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 );
|
|
1002
1009
|
}
|
|
1003
1010
|
}
|
|
1004
|
-
export async function updateFixtureStatus(req, res) {
|
|
1011
|
+
export async function updateFixtureStatus( req, res ) {
|
|
1005
1012
|
try {
|
|
1006
1013
|
let comments = {
|
|
1007
1014
|
userId: req.user._id,
|
|
@@ -1011,152 +1018,149 @@ export async function updateFixtureStatus(req, res) {
|
|
|
1011
1018
|
comment: req.body.comments,
|
|
1012
1019
|
};
|
|
1013
1020
|
|
|
1014
|
-
if (req.body.taskType.includes('fixture')) {
|
|
1021
|
+
if ( req.body.taskType.includes( 'fixture' ) ) {
|
|
1015
1022
|
await planoTaskService.updateOnefilters(
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
},
|
|
1023
|
-
[
|
|
1024
|
-
{ '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 ) },
|
|
1025
1029
|
|
|
1026
|
-
|
|
1030
|
+
],
|
|
1027
1031
|
);
|
|
1028
1032
|
await planoTaskService.updateOnefilters(
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
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
|
+
] );
|
|
1036
1040
|
|
|
1037
|
-
await planoTaskService.updateOne({ _id: req.body._id }, { approvalStatus: 'approved', taskType: 'initial' });
|
|
1041
|
+
await planoTaskService.updateOne( { _id: req.body._id }, { approvalStatus: 'approved', taskType: 'initial' } );
|
|
1038
1042
|
let fixtureTask = await planoTaskService.find(
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1043
|
+
{
|
|
1044
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
1045
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
1046
|
+
type: 'fixture',
|
|
1047
|
+
},
|
|
1044
1048
|
);
|
|
1045
|
-
if (fixtureTask.length > 0) {
|
|
1046
|
-
let allTaskDone = fixtureTask.filter((data) => !data?.answers?.[0]?.status || data?.answers?.[0]?.status == 'disagree');
|
|
1047
|
-
if (allTaskDone.length === 0) {
|
|
1048
|
-
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 } );
|
|
1049
1053
|
}
|
|
1050
1054
|
}
|
|
1051
1055
|
} else {
|
|
1052
1056
|
let updateResponse = await planoTaskService.updateOnefilters(
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
if (updateResponse && updateResponse.answers.length > 0) {
|
|
1064
|
-
let findissuse = updateResponse.answers[0].issues.filter((data) => data._id == req.body.issueId);
|
|
1065
|
-
let findDetails = findissuse[0].Details.filter((det) => det.status === 'agree');
|
|
1066
|
-
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 ) {
|
|
1067
1071
|
await planoTaskService.updateOnefilters(
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
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
|
+
] );
|
|
1076
1080
|
}
|
|
1077
|
-
let findoneplanoData = await planoTaskService.findOne({ _id: new mongoose.Types.ObjectId(req.body._id) });
|
|
1078
|
-
let totalApproved = findoneplanoData.answers[0].issues.filter((data) => data.status === 'pending');
|
|
1079
|
-
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 ) {
|
|
1080
1084
|
await planoTaskService.updateOne(
|
|
1081
|
-
{
|
|
1082
|
-
_id: new mongoose.Types.ObjectId(req.body._id),
|
|
1083
|
-
},
|
|
1084
|
-
{
|
|
1085
|
-
'status': 'complete',
|
|
1086
|
-
},
|
|
1087
|
-
);
|
|
1088
|
-
if (req.body.taskType === 'layout') {
|
|
1089
|
-
await planoTaskService.updateMany(
|
|
1090
1085
|
{
|
|
1091
|
-
|
|
1092
|
-
floorId: new mongoose.Types.ObjectId(req.body.floorId),
|
|
1093
|
-
type: 'layout',
|
|
1086
|
+
_id: new mongoose.Types.ObjectId( req.body._id ),
|
|
1094
1087
|
},
|
|
1095
1088
|
{
|
|
1096
1089
|
'status': 'complete',
|
|
1097
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
|
+
},
|
|
1098
1102
|
);
|
|
1099
1103
|
}
|
|
1100
1104
|
}
|
|
1101
1105
|
}
|
|
1102
1106
|
|
|
1103
|
-
if (req.body.taskType === 'layout') {
|
|
1107
|
+
if ( req.body.taskType === 'layout' ) {
|
|
1104
1108
|
await planoTaskService.updateOnefilters(
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
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 ) },
|
|
1113
1117
|
|
|
1114
|
-
|
|
1118
|
+
] );
|
|
1115
1119
|
} else {
|
|
1116
1120
|
await planoTaskService.updateOnefilters(
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
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
|
+
] );
|
|
1125
1129
|
}
|
|
1126
1130
|
let vmTask = await planoTaskService.find(
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1131
|
+
{
|
|
1132
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
1133
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
1134
|
+
type: 'vm',
|
|
1135
|
+
},
|
|
1132
1136
|
|
|
1133
1137
|
);
|
|
1134
|
-
if (vmTask.length > 0) {
|
|
1135
|
-
let allTaskDone = vmTask.filter((data) => data.status === 'incomplete');
|
|
1136
|
-
if (allTaskDone.length === 0) {
|
|
1137
|
-
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 } );
|
|
1138
1142
|
}
|
|
1139
1143
|
}
|
|
1140
1144
|
}
|
|
1141
|
-
res.sendSuccess('updated successfully');
|
|
1142
|
-
} catch (e) {
|
|
1143
|
-
logger.error({ functionName: 'updateFixtureStatus', error: e });
|
|
1144
|
-
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 );
|
|
1145
1149
|
}
|
|
1146
1150
|
}
|
|
1147
1151
|
|
|
1148
|
-
export async function updateApprovalStatus(req, res) {
|
|
1152
|
+
export async function updateApprovalStatus( req, res ) {
|
|
1149
1153
|
try {
|
|
1150
1154
|
await planoTaskService.updateOnefilters(
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
res.sendSuccess('updated successfully');
|
|
1154
|
-
} catch (e) {
|
|
1155
|
-
logger.error({ functionName: 'updateApprovalStatus', error: e });
|
|
1156
|
-
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 );
|
|
1157
1161
|
}
|
|
1158
1162
|
}
|
|
1159
|
-
export async function updateRolloutStatus(req, res) {
|
|
1163
|
+
export async function updateRolloutStatus( req, res ) {
|
|
1160
1164
|
try {
|
|
1161
1165
|
let comments = {
|
|
1162
1166
|
userId: req.user._id,
|
|
@@ -1166,153 +1170,153 @@ export async function updateRolloutStatus(req, res) {
|
|
|
1166
1170
|
comment: req.body.comments,
|
|
1167
1171
|
};
|
|
1168
1172
|
|
|
1169
|
-
if (req.body.issueId && req.body.DetailsId) {
|
|
1173
|
+
if ( req.body.issueId && req.body.DetailsId ) {
|
|
1170
1174
|
let updateResponse = await planoTaskService.updateOnefilters(
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
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
|
+
},
|
|
1176
1181
|
},
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
{ '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 ) },
|
|
1182
1186
|
|
|
1183
|
-
|
|
1187
|
+
],
|
|
1184
1188
|
);
|
|
1185
|
-
if (updateResponse && updateResponse.answers.length > 0) {
|
|
1186
|
-
let findissuse = updateResponse.answers[0].issues.filter((data) => data._id == req.body.issueId);
|
|
1187
|
-
let findDetails = findissuse[0].Details.filter((det) => det.status === 'agree');
|
|
1188
|
-
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 ) {
|
|
1189
1193
|
await planoTaskService.updateOnefilters(
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
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
|
+
] );
|
|
1198
1202
|
}
|
|
1199
|
-
let findoneplanoData = await planoTaskService.findOne({ _id: new mongoose.Types.ObjectId(req.body._id) });
|
|
1200
|
-
let totalApproved = findoneplanoData.answers[0].issues.filter((data) => data.status === 'pending');
|
|
1201
|
-
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 ) {
|
|
1202
1206
|
await planoTaskService.updateOne(
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1207
|
+
{
|
|
1208
|
+
_id: new mongoose.Types.ObjectId( req.body._id ),
|
|
1209
|
+
},
|
|
1210
|
+
{
|
|
1211
|
+
'status': 'complete',
|
|
1212
|
+
'approvalStatus': 'approved',
|
|
1213
|
+
},
|
|
1210
1214
|
);
|
|
1211
1215
|
let data = {};
|
|
1212
|
-
if (req.body.taskType == 'vmRollout') {
|
|
1216
|
+
if ( req.body.taskType == 'vmRollout' ) {
|
|
1213
1217
|
data['isVmEdited'] = false;
|
|
1214
1218
|
} else {
|
|
1215
1219
|
data['isMerchEdited'] = false;
|
|
1216
1220
|
}
|
|
1217
|
-
await storeFixtureService.updateOne({ _id: updateResponse.fixtureId }, data);
|
|
1221
|
+
await storeFixtureService.updateOne( { _id: updateResponse.fixtureId }, data );
|
|
1218
1222
|
}
|
|
1219
1223
|
}
|
|
1220
1224
|
await planoTaskService.updateOnefilters(
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
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
|
+
],
|
|
1229
1233
|
);
|
|
1230
1234
|
} else {
|
|
1231
1235
|
let updateResponse = await planoTaskService.updateOnefilters(
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1237
|
+
{
|
|
1238
|
+
$set: {
|
|
1239
|
+
'answers.$[ans].status': req.body.type,
|
|
1240
|
+
},
|
|
1236
1241
|
},
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
],
|
|
1242
|
+
[
|
|
1243
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
1244
|
+
],
|
|
1241
1245
|
);
|
|
1242
1246
|
await planoTaskService.updateOnefilters(
|
|
1243
|
-
|
|
1244
|
-
{
|
|
1245
|
-
$push: { 'answers.$[ans].comments': comments },
|
|
1246
|
-
},
|
|
1247
|
-
[
|
|
1248
|
-
{ 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
|
|
1249
|
-
],
|
|
1250
|
-
);
|
|
1251
|
-
if (req.body.type == 'agree') {
|
|
1252
|
-
await planoTaskService.updateOne(
|
|
1253
|
-
{
|
|
1254
|
-
_id: new mongoose.Types.ObjectId(req.body._id),
|
|
1255
|
-
},
|
|
1247
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
1256
1248
|
{
|
|
1257
|
-
'
|
|
1249
|
+
$push: { 'answers.$[ans].comments': comments },
|
|
1258
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
|
+
},
|
|
1259
1263
|
);
|
|
1260
1264
|
let data = {};
|
|
1261
|
-
if (req.body.taskType == 'vmRollout') {
|
|
1265
|
+
if ( req.body.taskType == 'vmRollout' ) {
|
|
1262
1266
|
data['isVmEdited'] = false;
|
|
1263
1267
|
} else {
|
|
1264
1268
|
data['isMerchEdited'] = false;
|
|
1265
1269
|
}
|
|
1266
|
-
await storeFixtureService.updateOne({ _id: updateResponse.fixtureId }, data);
|
|
1270
|
+
await storeFixtureService.updateOne( { _id: updateResponse.fixtureId }, data );
|
|
1267
1271
|
}
|
|
1268
1272
|
}
|
|
1269
1273
|
|
|
1270
|
-
res.sendSuccess('updated successfully');
|
|
1271
|
-
} catch (e) {
|
|
1272
|
-
logger.error({ functionName: 'updateFixtureStatus', error: e });
|
|
1273
|
-
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 );
|
|
1274
1278
|
}
|
|
1275
1279
|
}
|
|
1276
1280
|
|
|
1277
1281
|
|
|
1278
|
-
export async function updateStoreFixture(req, res) {
|
|
1282
|
+
export async function updateStoreFixture( req, res ) {
|
|
1279
1283
|
try {
|
|
1280
1284
|
const { fixtureId, data } = req.body;
|
|
1281
1285
|
|
|
1282
1286
|
let configId;
|
|
1283
1287
|
|
|
1284
|
-
const currentFixture = await storeFixtureService.findOne({ _id: new mongoose.Types.ObjectId(fixtureId) });
|
|
1288
|
+
const currentFixture = await storeFixtureService.findOne( { _id: new mongoose.Types.ObjectId( fixtureId ) } );
|
|
1285
1289
|
let currentFixtureDoc = currentFixture.toObject();
|
|
1286
|
-
if (
|
|
1287
|
-
let shelfDetails = await fixtureShelfService.find({ fixtureId: fixtureId });
|
|
1288
|
-
data.shelfConfig.forEach((ele) => {
|
|
1289
|
-
let findShelfProduct = shelfDetails.find((shelf) => shelf.shelfNumber == ele.shelfNumber);
|
|
1290
|
-
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 ) {
|
|
1291
1295
|
ele.zone = findShelfProduct?.zone ?? 'Bottom';
|
|
1292
1296
|
}
|
|
1293
|
-
if (!ele?.productBrandName) {
|
|
1297
|
+
if ( !ele?.productBrandName ) {
|
|
1294
1298
|
ele.productBrandName = findShelfProduct?.productBrandName ?? [];
|
|
1295
1299
|
}
|
|
1296
|
-
if (!ele?.productCategory) {
|
|
1300
|
+
if ( !ele?.productCategory ) {
|
|
1297
1301
|
ele.productCategory = findShelfProduct?.productCategory ?? [];
|
|
1298
1302
|
}
|
|
1299
|
-
if (!ele?.productSubCategory) {
|
|
1303
|
+
if ( !ele?.productSubCategory ) {
|
|
1300
1304
|
ele.productSubCategory = findShelfProduct?.productSubCategory ?? [];
|
|
1301
1305
|
}
|
|
1302
|
-
});
|
|
1306
|
+
} );
|
|
1303
1307
|
let vmConfig = [];
|
|
1304
|
-
for (let vm of data.vmConfig) {
|
|
1305
|
-
let checkvmType = await vmTypeService.findOne({ vmType: vm.vmType });
|
|
1306
|
-
if (!checkvmType) {
|
|
1308
|
+
for ( let vm of data.vmConfig ) {
|
|
1309
|
+
let checkvmType = await vmTypeService.findOne( { vmType: vm.vmType } );
|
|
1310
|
+
if ( !checkvmType ) {
|
|
1307
1311
|
let vmData = {
|
|
1308
1312
|
vmType: vm.vmType,
|
|
1309
|
-
imageUrls: [vm.vmImage],
|
|
1313
|
+
imageUrls: [ vm.vmImage ],
|
|
1310
1314
|
clientId: '11',
|
|
1311
1315
|
};
|
|
1312
|
-
checkvmType = await vmTypeService.create(vmData);
|
|
1316
|
+
checkvmType = await vmTypeService.create( vmData );
|
|
1313
1317
|
}
|
|
1314
|
-
let vmDetails = await planoVmService.findOne({ ...(vm.vmName) ? { vmName: vm.vmName } : { _id: vm.vmId } });
|
|
1315
|
-
if (!vmDetails) {
|
|
1318
|
+
let vmDetails = await planoVmService.findOne( { ...( vm.vmName ) ? { vmName: vm.vmName } : { _id: vm.vmId } } );
|
|
1319
|
+
if ( !vmDetails ) {
|
|
1316
1320
|
let planovmData = {
|
|
1317
1321
|
vmType: vm.vmType,
|
|
1318
1322
|
vmName: vm.vmName,
|
|
@@ -1328,9 +1332,9 @@ export async function updateStoreFixture(req, res) {
|
|
|
1328
1332
|
},
|
|
1329
1333
|
vmImageUrl: vm.vmImage,
|
|
1330
1334
|
};
|
|
1331
|
-
vmDetails = await planoVmService.create(planovmData);
|
|
1335
|
+
vmDetails = await planoVmService.create( planovmData );
|
|
1332
1336
|
}
|
|
1333
|
-
vmConfig.push({ ...vm, vmId: vmDetails._id });
|
|
1337
|
+
vmConfig.push( { ...vm, vmId: vmDetails._id } );
|
|
1334
1338
|
}
|
|
1335
1339
|
data.vmConfig = vmConfig;
|
|
1336
1340
|
let groupName = {
|
|
@@ -1339,12 +1343,12 @@ export async function updateStoreFixture(req, res) {
|
|
|
1339
1343
|
'Vincent Chase': 'VC Eye',
|
|
1340
1344
|
'OwnDays': 'OD Eye',
|
|
1341
1345
|
};
|
|
1342
|
-
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;
|
|
1343
1347
|
let mapKey = `${data.fixtureCategory}${currentFixtureDoc.fixtureWidth.value}${currentFixtureDoc.fixtureWidth.unit}${header}`;
|
|
1344
|
-
mapKey += data.shelfConfig.map((ele) => `${ele.shelfNumber}=${ele.productBrandName.toString()}`).join('+');
|
|
1345
|
-
data?.vmConfig?.forEach((ele) => {
|
|
1348
|
+
mapKey += data.shelfConfig.map( ( ele ) => `${ele.shelfNumber}=${ele.productBrandName.toString()}` ).join( '+' );
|
|
1349
|
+
data?.vmConfig?.forEach( ( ele ) => {
|
|
1346
1350
|
mapKey += `${ele.vmName}${ele.startYPosition}${ele.endYPosition}${ele.xZone}${ele.yZone}`;
|
|
1347
|
-
});
|
|
1351
|
+
} );
|
|
1348
1352
|
let query = [
|
|
1349
1353
|
{
|
|
1350
1354
|
$addFields: {
|
|
@@ -1372,13 +1376,13 @@ export async function updateStoreFixture(req, res) {
|
|
|
1372
1376
|
},
|
|
1373
1377
|
},
|
|
1374
1378
|
];
|
|
1375
|
-
let [fixturesubTemplate, fixtureMasterTemplate] = await Promise.all([
|
|
1376
|
-
await fixtureConfigService.aggregate(query),
|
|
1377
|
-
await fixtureConfigService.aggregate(masterQuery),
|
|
1378
|
-
]);
|
|
1379
|
+
let [ fixturesubTemplate, fixtureMasterTemplate ] = await Promise.all( [
|
|
1380
|
+
await fixtureConfigService.aggregate( query ),
|
|
1381
|
+
await fixtureConfigService.aggregate( masterQuery ),
|
|
1382
|
+
] );
|
|
1379
1383
|
|
|
1380
|
-
if (!fixturesubTemplate.length) {
|
|
1381
|
-
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;
|
|
1382
1386
|
let templateIndex = 1;
|
|
1383
1387
|
let templateData = {
|
|
1384
1388
|
...currentFixtureDoc,
|
|
@@ -1391,20 +1395,20 @@ export async function updateStoreFixture(req, res) {
|
|
|
1391
1395
|
};
|
|
1392
1396
|
delete templateData._id;
|
|
1393
1397
|
delete templateData.masterTemplateId;
|
|
1394
|
-
if (!fixtureMasterTemplate.length) {
|
|
1398
|
+
if ( !fixtureMasterTemplate.length ) {
|
|
1395
1399
|
let masterTemplate = {
|
|
1396
1400
|
...templateData,
|
|
1397
1401
|
fixtureName: `${templateData.header.label}-${templateData.fixtureCategory}`,
|
|
1398
1402
|
templateType: 'master',
|
|
1399
1403
|
crestMapKey: masterMapKey,
|
|
1400
1404
|
};
|
|
1401
|
-
fixtureMasterTemplate = await fixtureConfigService.create(masterTemplate);
|
|
1405
|
+
fixtureMasterTemplate = await fixtureConfigService.create( masterTemplate );
|
|
1402
1406
|
} else {
|
|
1403
1407
|
fixtureMasterTemplate = fixtureMasterTemplate[0];
|
|
1404
1408
|
let tempQuery = [
|
|
1405
1409
|
{
|
|
1406
1410
|
$match: {
|
|
1407
|
-
masterTemplateId: new mongoose.Types.ObjectId(fixtureMasterTemplate._id),
|
|
1411
|
+
masterTemplateId: new mongoose.Types.ObjectId( fixtureMasterTemplate._id ),
|
|
1408
1412
|
},
|
|
1409
1413
|
},
|
|
1410
1414
|
{
|
|
@@ -1414,16 +1418,16 @@ export async function updateStoreFixture(req, res) {
|
|
|
1414
1418
|
},
|
|
1415
1419
|
},
|
|
1416
1420
|
];
|
|
1417
|
-
let getMaxTemp = await fixtureConfigService.aggregate(tempQuery);
|
|
1421
|
+
let getMaxTemp = await fixtureConfigService.aggregate( tempQuery );
|
|
1418
1422
|
templateIndex = getMaxTemp?.[0]?.tempId + 1;
|
|
1419
1423
|
}
|
|
1420
|
-
templateData.fixtureName
|
|
1421
|
-
|
|
1424
|
+
templateData.fixtureName= `${header}-${data.fixtureCategory}-variant-${templateIndex}`,
|
|
1425
|
+
templateData.templateType = 'sub';
|
|
1422
1426
|
templateData.masterTemplateId = fixtureMasterTemplate._id;
|
|
1423
1427
|
templateData.templateIndex = templateIndex;
|
|
1424
1428
|
templateData.createdAt = new Date();
|
|
1425
1429
|
templateData.updatedAt = new Date();
|
|
1426
|
-
let subTemplate = await fixtureConfigService.create(templateData);
|
|
1430
|
+
let subTemplate = await fixtureConfigService.create( templateData );
|
|
1427
1431
|
configId = subTemplate._id;
|
|
1428
1432
|
|
|
1429
1433
|
data.fixtureConfigId = subTemplate._id;
|
|
@@ -1439,72 +1443,72 @@ export async function updateStoreFixture(req, res) {
|
|
|
1439
1443
|
|
|
1440
1444
|
let fixtureCapacity = 0;
|
|
1441
1445
|
|
|
1442
|
-
data.shelfConfig.forEach((shelf) => {
|
|
1446
|
+
data.shelfConfig.forEach( ( shelf ) => {
|
|
1443
1447
|
const { productBrandName: brand, productCategory: category, productSubCategory: subCategory } = shelf;
|
|
1444
1448
|
|
|
1445
|
-
if (typeof shelf?.productPerShelf === 'number') {
|
|
1446
|
-
if (shelf?.shelfType === 'shelf') {
|
|
1449
|
+
if ( typeof shelf?.productPerShelf === 'number' ) {
|
|
1450
|
+
if ( shelf?.shelfType === 'shelf' ) {
|
|
1447
1451
|
fixtureCapacity += shelf.productPerShelf;
|
|
1448
1452
|
}
|
|
1449
1453
|
|
|
1450
|
-
if (shelf?.shelfType === 'tray') {
|
|
1451
|
-
fixtureCapacity += (shelf?.productPerShelf * shelf?.trayRows);
|
|
1454
|
+
if ( shelf?.shelfType === 'tray' ) {
|
|
1455
|
+
fixtureCapacity += ( shelf?.productPerShelf * shelf?.trayRows );
|
|
1452
1456
|
}
|
|
1453
1457
|
}
|
|
1454
1458
|
|
|
1455
|
-
if (Array.isArray(brand)) {
|
|
1456
|
-
brand.forEach((b) => productBrandName.add(b));
|
|
1459
|
+
if ( Array.isArray( brand ) ) {
|
|
1460
|
+
brand.forEach( ( b ) => productBrandName.add( b ) );
|
|
1457
1461
|
}
|
|
1458
1462
|
|
|
1459
|
-
if (Array.isArray(category)) {
|
|
1460
|
-
category.forEach((c) => productCategory.add(c));
|
|
1463
|
+
if ( Array.isArray( category ) ) {
|
|
1464
|
+
category.forEach( ( c ) => productCategory.add( c ) );
|
|
1461
1465
|
}
|
|
1462
1466
|
|
|
1463
|
-
if (Array.isArray(subCategory)) {
|
|
1464
|
-
subCategory.forEach((s) => productSubCategory.add(s));
|
|
1467
|
+
if ( Array.isArray( subCategory ) ) {
|
|
1468
|
+
subCategory.forEach( ( s ) => productSubCategory.add( s ) );
|
|
1465
1469
|
}
|
|
1466
|
-
});
|
|
1470
|
+
} );
|
|
1467
1471
|
|
|
1468
1472
|
|
|
1469
|
-
if (data?.fixtureConfigId && currentFixtureDoc.fixtureConfigId.toString() !== data.fixtureConfigId) {
|
|
1470
|
-
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 } );
|
|
1471
1475
|
currentFixtureDoc = {
|
|
1472
1476
|
...currentFixtureDoc,
|
|
1473
1477
|
...newTemplate.toObject(),
|
|
1474
1478
|
fixtureConfigId: newTemplate.toObject()._id,
|
|
1475
1479
|
fixtureCapacity: fixtureCapacity,
|
|
1476
|
-
productBrandName: [...productBrandName],
|
|
1477
|
-
productCategory: [...productCategory],
|
|
1478
|
-
productSubCategory: [...productSubCategory],
|
|
1480
|
+
productBrandName: [ ...productBrandName ],
|
|
1481
|
+
productCategory: [ ...productCategory ],
|
|
1482
|
+
productSubCategory: [ ...productSubCategory ],
|
|
1479
1483
|
};
|
|
1480
1484
|
} else {
|
|
1481
1485
|
currentFixtureDoc = {
|
|
1482
1486
|
...currentFixtureDoc,
|
|
1483
1487
|
...data,
|
|
1484
1488
|
fixtureCapacity: fixtureCapacity,
|
|
1485
|
-
productBrandName: [...productBrandName],
|
|
1486
|
-
productCategory: [...productCategory],
|
|
1487
|
-
productSubCategory: [...productSubCategory],
|
|
1489
|
+
productBrandName: [ ...productBrandName ],
|
|
1490
|
+
productCategory: [ ...productCategory ],
|
|
1491
|
+
productSubCategory: [ ...productSubCategory ],
|
|
1488
1492
|
};
|
|
1489
1493
|
}
|
|
1490
1494
|
|
|
1491
|
-
if (data.productResolutionLevel == 'L1') {
|
|
1492
|
-
currentFixtureDoc.productBrandName = [...new Set(data.productBrandName.map((ele) => ele))];
|
|
1493
|
-
currentFixtureDoc.productCategory = [...new Set(data.productCategory.map((ele) => ele))];
|
|
1494
|
-
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 ) ) ];
|
|
1495
1499
|
}
|
|
1496
1500
|
|
|
1497
1501
|
|
|
1498
1502
|
delete currentFixtureDoc._id;
|
|
1499
1503
|
|
|
1500
1504
|
|
|
1501
|
-
await storeFixtureService.updateOne({ _id: new mongoose.Types.ObjectId(fixtureId) }, currentFixtureDoc);
|
|
1505
|
+
await storeFixtureService.updateOne( { _id: new mongoose.Types.ObjectId( fixtureId ) }, currentFixtureDoc );
|
|
1502
1506
|
|
|
1503
|
-
if (data?.shelfConfig?.length) {
|
|
1504
|
-
await fixtureShelfService.deleteMany({ fixtureId: new mongoose.Types.ObjectId(fixtureId) });
|
|
1507
|
+
if ( data?.shelfConfig?.length ) {
|
|
1508
|
+
await fixtureShelfService.deleteMany( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) } );
|
|
1505
1509
|
|
|
1506
1510
|
|
|
1507
|
-
data.shelfConfig.forEach(async (shelf) => {
|
|
1511
|
+
data.shelfConfig.forEach( async ( shelf ) => {
|
|
1508
1512
|
delete shelf?._id;
|
|
1509
1513
|
const additionalMeta = {
|
|
1510
1514
|
clientId: currentFixture.clientId,
|
|
@@ -1515,12 +1519,11 @@ export async function updateStoreFixture(req, res) {
|
|
|
1515
1519
|
fixtureId: currentFixture._id,
|
|
1516
1520
|
};
|
|
1517
1521
|
|
|
1518
|
-
await fixtureShelfService.create({ ...additionalMeta, ...shelf });
|
|
1519
|
-
});
|
|
1522
|
+
await fixtureShelfService.create( { ...additionalMeta, ...shelf } );
|
|
1523
|
+
} );
|
|
1520
1524
|
}
|
|
1521
|
-
await planoService.updateOne({ _id: currentFixtureDoc?.planoId }, { $set: { updatedAt: new Date() } });
|
|
1522
|
-
|
|
1523
|
-
if (data?.userAction === 'editWithAi' || data?.userAction === 'editWithPlano') {
|
|
1525
|
+
await planoService.updateOne( { _id: currentFixtureDoc?.planoId }, { $set: { updatedAt: new Date() } } );
|
|
1526
|
+
if ( data?.taskType?.includes( 'fixture' ) ) {
|
|
1524
1527
|
let comments = {
|
|
1525
1528
|
userId: req.user._id,
|
|
1526
1529
|
userName: req.user.userName,
|
|
@@ -1528,151 +1531,85 @@ export async function updateStoreFixture(req, res) {
|
|
|
1528
1531
|
responsetype: 'agree',
|
|
1529
1532
|
comment: '',
|
|
1530
1533
|
};
|
|
1531
|
-
await planoTaskService.updateOne({ planoId: currentFixture.planoId, floorId: currentFixture.floorId, fixtureId: currentFixture._id }, { 'answers.0.status': 'agree', 'approvalStatus': 'approved'
|
|
1532
|
-
|
|
1534
|
+
await planoTaskService.updateOne( { planoId: currentFixture.planoId, floorId: currentFixture.floorId, fixtureId: currentFixture._id }, { 'answers.0.status': 'agree', 'approvalStatus': 'approved' } );
|
|
1533
1535
|
await planoTaskService.updateOnefilters(
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
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
|
+
},
|
|
1538
1540
|
);
|
|
1539
|
-
|
|
1540
1541
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
const op_id = `${data?.storeName}_${data?.storeDate}_${data?._id}`
|
|
1544
|
-
await updateAIFeedbackInOpenSearch(data, op_id);
|
|
1542
|
+
if ( req.body?.editMode ) {
|
|
1543
|
+
await floorService.updateOne( { _id: new mongoose.Types.ObjectId( currentFixture.floorId ) }, { isEdited: true } );
|
|
1545
1544
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
res.sendSuccess({ message: 'Updated Successfully', ...(configId && { id: configId }) });
|
|
1551
|
-
} catch (e) {
|
|
1552
|
-
logger.error({ functionName: 'updateStoreFixture', error: e });
|
|
1553
|
-
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 );
|
|
1554
1549
|
}
|
|
1555
1550
|
}
|
|
1556
1551
|
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
try {
|
|
1560
|
-
let openSearchDetails = await getOpenSearchById(JSON.parse(process.env.OPENSEARCH).planoAIValidation, id);
|
|
1561
|
-
if (openSearchDetails && openSearchDetails.statusCode == 200 && openSearchDetails?.body?._source) {
|
|
1562
|
-
|
|
1563
|
-
const doc = {
|
|
1564
|
-
"fixtureId": fixtureData._id,
|
|
1565
|
-
"fixtureCapacity": fixtureData.fixtureCapacity,
|
|
1566
|
-
"fixtureType": fixtureData.fixtureType,
|
|
1567
|
-
"fixtureCategory": fixtureData.fixtureCategory,
|
|
1568
|
-
"header": {
|
|
1569
|
-
"label": fixtureData.header.label,
|
|
1570
|
-
},
|
|
1571
|
-
"vmConfig": fixtureData?.vmConfig.map(vm => {
|
|
1572
|
-
return {
|
|
1573
|
-
"vmType": vm.vmType,
|
|
1574
|
-
"startYPosition": vm.startYPosition,
|
|
1575
|
-
"endYPosition": vm.endYPosition,
|
|
1576
|
-
"xZone": vm.xZone,
|
|
1577
|
-
"yZone": vm.yZone,
|
|
1578
|
-
"vmImage": vm.vmImage,
|
|
1579
|
-
"vmName": vm.vmName,
|
|
1580
|
-
}
|
|
1581
|
-
}) ?? [
|
|
1582
|
-
|
|
1583
|
-
],
|
|
1584
|
-
"shelfConfig": fixtureData?.shelfConfig.map(s => {
|
|
1585
|
-
return {
|
|
1586
|
-
"shelfNumber": s.shelfNumber,
|
|
1587
|
-
"shelfType": s.shelfType,
|
|
1588
|
-
"productPerShelf": s.productPerShelf,
|
|
1589
|
-
"trayRows": s.trayRows
|
|
1590
|
-
}
|
|
1591
|
-
}) ?? [],
|
|
1592
|
-
"fixtureImage": fixtureData.fixtureImage,
|
|
1593
|
-
"storeDate": fixtureData.storeDate
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
const document = {
|
|
1597
|
-
doc: doc,
|
|
1598
|
-
};
|
|
1599
|
-
|
|
1600
|
-
let updateResult = await updateOpenSearchData(JSON.parse(process.env.OPENSEARCH).planoAIValidation, id, document);
|
|
1601
|
-
|
|
1602
|
-
if (updateResult?.statusCode == 200) {
|
|
1603
|
-
return true;
|
|
1604
|
-
}
|
|
1605
|
-
return false
|
|
1606
|
-
} else {
|
|
1607
|
-
return false
|
|
1608
|
-
}
|
|
1609
|
-
} catch (e) {
|
|
1610
|
-
logger.error({ error: e, function: 'updateAIFeedbackInOpenSearch' });
|
|
1611
|
-
return false
|
|
1612
|
-
}
|
|
1613
|
-
};
|
|
1614
|
-
|
|
1615
|
-
export async function updateredostatus(req, res) {
|
|
1552
|
+
export async function updateredostatus( req, res ) {
|
|
1616
1553
|
try {
|
|
1617
|
-
if (req.body.type === 'layout') {
|
|
1554
|
+
if ( req.body.type === 'layout' ) {
|
|
1618
1555
|
await planoTaskService.updateOne(
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
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
|
+
},
|
|
1629
1566
|
);
|
|
1630
1567
|
} else {
|
|
1631
1568
|
await planoTaskService.updateOne(
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
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
|
+
},
|
|
1643
1580
|
);
|
|
1644
1581
|
}
|
|
1645
|
-
res.sendSuccess('updated successfully');
|
|
1646
|
-
} catch (e) {
|
|
1647
|
-
logger.error({ functionName: 'updateredostatus', error: e });
|
|
1648
|
-
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 );
|
|
1649
1586
|
}
|
|
1650
1587
|
}
|
|
1651
1588
|
|
|
1652
1589
|
|
|
1653
|
-
export async function updateGlobalComment(req, res) {
|
|
1590
|
+
export async function updateGlobalComment( req, res ) {
|
|
1654
1591
|
try {
|
|
1655
1592
|
let payload = {
|
|
1656
1593
|
userId: req.user._id,
|
|
1657
1594
|
userName: req.user.userName,
|
|
1658
1595
|
comment: req.body.comment,
|
|
1659
1596
|
responsetype: req.body.responsetype,
|
|
1660
|
-
planoId: new mongoose.Types.ObjectId(req.body.planoId),
|
|
1661
|
-
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 ),
|
|
1662
1599
|
taskType: req.body.taskType,
|
|
1663
1600
|
clientId: req.body.clientId,
|
|
1664
1601
|
taskId: req.body.taskId,
|
|
1665
1602
|
};
|
|
1666
|
-
await planoGlobalCommentService.create(payload);
|
|
1667
|
-
await insertOpenSearchData(JSON.parse(process.env.OPENSEARCH).planoglobalcomments, payload);
|
|
1603
|
+
await planoGlobalCommentService.create( payload );
|
|
1604
|
+
await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).planoglobalcomments, payload );
|
|
1668
1605
|
|
|
1669
|
-
res.sendSuccess('updated successfully');
|
|
1670
|
-
} catch (e) {
|
|
1671
|
-
logger.error({ functionName: 'updateGlobalComment', error: e });
|
|
1672
|
-
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 );
|
|
1673
1610
|
}
|
|
1674
1611
|
}
|
|
1675
|
-
export async function getGlobalComment(req, res) {
|
|
1612
|
+
export async function getGlobalComment( req, res ) {
|
|
1676
1613
|
try {
|
|
1677
1614
|
// let layoutComment = await planoGlobalCommentService.find( {
|
|
1678
1615
|
// planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
@@ -1681,147 +1618,147 @@ export async function getGlobalComment(req, res) {
|
|
|
1681
1618
|
// } );
|
|
1682
1619
|
|
|
1683
1620
|
let taskId = [];
|
|
1684
|
-
if (req.body?.taskId) {
|
|
1685
|
-
taskId.push(new mongoose.Types.ObjectId(req.body.taskId));
|
|
1621
|
+
if ( req.body?.taskId ) {
|
|
1622
|
+
taskId.push( new mongoose.Types.ObjectId( req.body.taskId ) );
|
|
1686
1623
|
}
|
|
1687
1624
|
|
|
1688
|
-
if (req.body?.refTaskId) {
|
|
1689
|
-
taskId.push(new mongoose.Types.ObjectId(req.body.refTaskId));
|
|
1625
|
+
if ( req.body?.refTaskId ) {
|
|
1626
|
+
taskId.push( new mongoose.Types.ObjectId( req.body.refTaskId ) );
|
|
1690
1627
|
}
|
|
1691
1628
|
|
|
1692
|
-
let layoutComment = await planoGlobalCommentService.find({
|
|
1693
|
-
planoId: new mongoose.Types.ObjectId(req.body.planoId),
|
|
1694
|
-
floorId: new mongoose.Types.ObjectId(req.body.floorId),
|
|
1695
|
-
...(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 } } ),
|
|
1696
1633
|
taskType: req.body.taskType,
|
|
1697
|
-
});
|
|
1634
|
+
} );
|
|
1698
1635
|
|
|
1699
|
-
res.sendSuccess(layoutComment);
|
|
1700
|
-
} catch (e) {
|
|
1701
|
-
logger.error({ functionName: 'getGlobalComment', error: e });
|
|
1702
|
-
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 );
|
|
1703
1640
|
}
|
|
1704
1641
|
}
|
|
1705
1642
|
|
|
1706
|
-
export async function getAllPlanoRevisions(req, res) {
|
|
1643
|
+
export async function getAllPlanoRevisions( req, res ) {
|
|
1707
1644
|
try {
|
|
1708
1645
|
const { clientId } = req.body;
|
|
1709
1646
|
|
|
1710
|
-
if (!clientId) {
|
|
1711
|
-
return res.sendError('Client Id is required', 400);
|
|
1647
|
+
if ( !clientId ) {
|
|
1648
|
+
return res.sendError( 'Client Id is required', 400 );
|
|
1712
1649
|
}
|
|
1713
1650
|
|
|
1714
1651
|
const revisions = await planoRevisionService.find(
|
|
1715
|
-
|
|
1716
|
-
|
|
1652
|
+
{ clientId },
|
|
1653
|
+
{ storeName: 1, storeId: 1, planoId: 1, floorId: 1, createdAt: 1 },
|
|
1717
1654
|
);
|
|
1718
1655
|
|
|
1719
|
-
res.sendSuccess(revisions);
|
|
1720
|
-
} catch (e) {
|
|
1721
|
-
logger.error({ functionName: 'getAllPlanoRevisions', error: e });
|
|
1722
|
-
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 );
|
|
1723
1660
|
}
|
|
1724
1661
|
}
|
|
1725
1662
|
|
|
1726
|
-
export async function createPlanoRevision(req, res) {
|
|
1663
|
+
export async function createPlanoRevision( req, res ) {
|
|
1727
1664
|
try {
|
|
1728
1665
|
const { storeName, storeId, clientId, planoId, floorId, floorData } = req.body;
|
|
1729
1666
|
|
|
1730
|
-
if (!storeName || !storeId || !clientId || !planoId || !floorId || !floorData) {
|
|
1731
|
-
return res.sendError('Missing required fields', 400);
|
|
1667
|
+
if ( !storeName || !storeId || !clientId || !planoId || !floorId || !floorData ) {
|
|
1668
|
+
return res.sendError( 'Missing required fields', 400 );
|
|
1732
1669
|
}
|
|
1733
1670
|
|
|
1734
|
-
const newRevision = await planoRevisionService.create({
|
|
1671
|
+
const newRevision = await planoRevisionService.create( {
|
|
1735
1672
|
storeName,
|
|
1736
1673
|
storeId,
|
|
1737
1674
|
clientId,
|
|
1738
1675
|
planoId,
|
|
1739
1676
|
floorId,
|
|
1740
1677
|
floorData,
|
|
1741
|
-
});
|
|
1678
|
+
} );
|
|
1742
1679
|
|
|
1743
|
-
res.sendSuccess(newRevision);
|
|
1744
|
-
} catch (e) {
|
|
1745
|
-
logger.error({ functionName: 'createPlanoRevision', error: e });
|
|
1746
|
-
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 );
|
|
1747
1684
|
}
|
|
1748
1685
|
}
|
|
1749
1686
|
|
|
1750
|
-
export async function getPlanoRevisionById(req, res) {
|
|
1687
|
+
export async function getPlanoRevisionById( req, res ) {
|
|
1751
1688
|
try {
|
|
1752
1689
|
const { id } = req.params;
|
|
1753
1690
|
|
|
1754
|
-
if (!id) {
|
|
1755
|
-
return res.sendError('Revision ID is required', 400);
|
|
1691
|
+
if ( !id ) {
|
|
1692
|
+
return res.sendError( 'Revision ID is required', 400 );
|
|
1756
1693
|
}
|
|
1757
1694
|
|
|
1758
1695
|
const revision = await planoRevisionService.findOne(
|
|
1759
|
-
|
|
1696
|
+
{ _id: id },
|
|
1760
1697
|
);
|
|
1761
1698
|
|
|
1762
|
-
if (!revision) {
|
|
1763
|
-
return res.sendError('Plano revision not found', 404);
|
|
1699
|
+
if ( !revision ) {
|
|
1700
|
+
return res.sendError( 'Plano revision not found', 404 );
|
|
1764
1701
|
}
|
|
1765
1702
|
|
|
1766
|
-
res.sendSuccess(revision);
|
|
1767
|
-
} catch (e) {
|
|
1768
|
-
logger.error({ functionName: 'getPlanoRevisionById', error: e });
|
|
1769
|
-
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 );
|
|
1770
1707
|
}
|
|
1771
1708
|
}
|
|
1772
|
-
export async function getRolloutFeedback(req, res) {
|
|
1709
|
+
export async function getRolloutFeedback( req, res ) {
|
|
1773
1710
|
try {
|
|
1774
|
-
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' ];
|
|
1775
1712
|
const filterByStatus = req.body.filterByStatus || [];
|
|
1776
1713
|
const filterByApprovalStatus = req.body.filterByApprovalStatus || '';
|
|
1777
1714
|
const resultMap = {};
|
|
1778
1715
|
const commentMap = {};
|
|
1779
|
-
if (req.body.redo) {
|
|
1780
|
-
let taskDetails = await planoTaskService.findOne({ taskId: req.body.taskId, fixtureId: req.body.fixtureId });
|
|
1781
|
-
if (!taskDetails) {
|
|
1716
|
+
if ( req.body.redo ) {
|
|
1717
|
+
let taskDetails = await planoTaskService.findOne( { taskId: req.body.taskId, fixtureId: req.body.fixtureId } );
|
|
1718
|
+
if ( !taskDetails ) {
|
|
1782
1719
|
req.body.taskId = req.body.refTaskId;
|
|
1783
1720
|
}
|
|
1784
1721
|
}
|
|
1785
1722
|
await Promise.all(
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
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,
|
|
1795
1736
|
);
|
|
1796
|
-
});
|
|
1797
|
-
|
|
1798
|
-
|
|
1737
|
+
} );
|
|
1738
|
+
data = data.filter(
|
|
1739
|
+
( element ) => element.answers && element.answers.length > 0,
|
|
1799
1740
|
);
|
|
1800
|
-
}
|
|
1801
|
-
data = data.filter(
|
|
1802
|
-
(element) => element.answers && element.answers.length > 0,
|
|
1803
|
-
);
|
|
1804
|
-
}
|
|
1741
|
+
}
|
|
1805
1742
|
|
|
1806
1743
|
|
|
1807
|
-
|
|
1744
|
+
resultMap[type] = data;
|
|
1808
1745
|
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
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
|
+
}
|
|
1816
1753
|
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
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
|
+
} ),
|
|
1825
1762
|
);
|
|
1826
1763
|
const response = {
|
|
1827
1764
|
merchRolloutData: resultMap['merchRollout'] || [],
|
|
@@ -1830,39 +1767,39 @@ export async function getRolloutFeedback(req, res) {
|
|
|
1830
1767
|
vmRolloutComment: commentMap['vmRollout'] || [],
|
|
1831
1768
|
};
|
|
1832
1769
|
|
|
1833
|
-
res.sendSuccess(response);
|
|
1834
|
-
} catch (e) {
|
|
1835
|
-
logger.error({ functionName: 'getRolloutFeedback', error: e });
|
|
1836
|
-
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 );
|
|
1837
1774
|
}
|
|
1838
1775
|
}
|
|
1839
1776
|
|
|
1840
1777
|
|
|
1841
|
-
export async function getRolloutFeedbackv2(req, res) {
|
|
1778
|
+
export async function getRolloutFeedbackv2( req, res ) {
|
|
1842
1779
|
try {
|
|
1843
|
-
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' ];
|
|
1844
1781
|
const filterByStatus = req.body.filterByStatus || [];
|
|
1845
1782
|
const filterByApprovalStatus = req.body.filterByApprovalStatus || '';
|
|
1846
1783
|
const resultMap = {};
|
|
1847
1784
|
const commentMap = {};
|
|
1848
1785
|
await Promise.all(
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
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
|
+
} ) );
|
|
1854
1791
|
const response = {
|
|
1855
1792
|
merchRolloutData: resultMap['merchRollout'] || [],
|
|
1856
1793
|
vmRolloutData: resultMap['vmRollout'] || [],
|
|
1857
1794
|
merchRolloutComment: commentMap['merchRollout'] || [],
|
|
1858
1795
|
vmRolloutComment: commentMap['vmRollout'] || [],
|
|
1859
1796
|
};
|
|
1860
|
-
if (filterByStatus.length || filterByApprovalStatus) {
|
|
1861
|
-
let data = response[`${req.body.type}RolloutData`].filter((ele) => ele.storeFixtureList.length);
|
|
1862
|
-
if (filterByStatus.length == 1) {
|
|
1863
|
-
data = data.filter((type) => {
|
|
1864
|
-
let fixtureList = type.storeFixtureList.filter((ele) => filterByStatus.includes(ele.status));
|
|
1865
|
-
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' ) ) {
|
|
1866
1803
|
return type.storeFixtureList.length == fixtureList.length;
|
|
1867
1804
|
} else {
|
|
1868
1805
|
return fixtureList.length;
|
|
@@ -1870,69 +1807,69 @@ export async function getRolloutFeedbackv2(req, res) {
|
|
|
1870
1807
|
},
|
|
1871
1808
|
);
|
|
1872
1809
|
}
|
|
1873
|
-
if (filterByApprovalStatus) {
|
|
1874
|
-
if (filterByApprovalStatus === 'pending') {
|
|
1875
|
-
data = data.filter((type) => {
|
|
1876
|
-
let fixtureList = type.storeFixtureList.filter((ele) => {
|
|
1877
|
-
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 ) {
|
|
1878
1815
|
return true;
|
|
1879
1816
|
} else {
|
|
1880
|
-
return ele.answers?.some((ans) =>
|
|
1881
|
-
ans.issues?.some((issue) =>
|
|
1882
|
-
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' ),
|
|
1883
1820
|
),
|
|
1884
1821
|
);
|
|
1885
1822
|
}
|
|
1886
|
-
});
|
|
1823
|
+
} );
|
|
1887
1824
|
|
|
1888
1825
|
return fixtureList.length;
|
|
1889
|
-
});
|
|
1826
|
+
} );
|
|
1890
1827
|
} else {
|
|
1891
|
-
data = data.filter((type) => {
|
|
1892
|
-
let fixtureList = type.storeFixtureList.filter((ele) => {
|
|
1893
|
-
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 ) {
|
|
1894
1831
|
return true;
|
|
1895
1832
|
} else {
|
|
1896
|
-
return ele.answers?.some((ans) =>
|
|
1897
|
-
ans.issues?.some((issue) =>
|
|
1898
|
-
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' ),
|
|
1899
1836
|
),
|
|
1900
1837
|
);
|
|
1901
1838
|
}
|
|
1902
|
-
});
|
|
1839
|
+
} );
|
|
1903
1840
|
|
|
1904
1841
|
return fixtureList.length;
|
|
1905
|
-
});
|
|
1842
|
+
} );
|
|
1906
1843
|
}
|
|
1907
1844
|
}
|
|
1908
1845
|
response[`${req.body.type}RolloutData`] = data;
|
|
1909
1846
|
}
|
|
1910
|
-
response.vmRolloutData = await Promise.all(response.vmRolloutData.map(async (ele) => {
|
|
1911
|
-
ele.storeFixtureList = await Promise.all(ele.storeFixtureList.map(async (fixt) => {
|
|
1912
|
-
if (fixt?.FixtureData?.vmConfig?.length) {
|
|
1913
|
-
fixt.FixtureData.vmConfig = await Promise.all(fixt?.FixtureData?.vmConfig?.map(async (config) => {
|
|
1914
|
-
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 } );
|
|
1915
1852
|
return { ...config, vmType: vmDetails.vmType, vmName: vmDetails.vmName };
|
|
1916
|
-
}));
|
|
1853
|
+
} ) );
|
|
1917
1854
|
}
|
|
1918
1855
|
return fixt;
|
|
1919
|
-
}));
|
|
1856
|
+
} ) );
|
|
1920
1857
|
return ele;
|
|
1921
|
-
}));
|
|
1922
|
-
res.sendSuccess(response);
|
|
1923
|
-
} catch (e) {
|
|
1924
|
-
logger.error({ functionName: 'getRolloutFeedbackv2', error: e });
|
|
1925
|
-
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 );
|
|
1926
1863
|
}
|
|
1927
1864
|
}
|
|
1928
1865
|
|
|
1929
1866
|
|
|
1930
|
-
function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0) {
|
|
1931
|
-
let matchStage = [{
|
|
1867
|
+
function pipelineStage( type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0 ) {
|
|
1868
|
+
let matchStage = [ {
|
|
1932
1869
|
$match: {
|
|
1933
1870
|
'planoType': type,
|
|
1934
|
-
'planoId': new mongoose.Types.ObjectId(planoId),
|
|
1935
|
-
'floorId': new mongoose.Types.ObjectId(floorId),
|
|
1871
|
+
'planoId': new mongoose.Types.ObjectId( planoId ),
|
|
1872
|
+
'floorId': new mongoose.Types.ObjectId( floorId ),
|
|
1936
1873
|
},
|
|
1937
1874
|
},
|
|
1938
1875
|
|
|
@@ -1960,7 +1897,7 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
|
|
|
1960
1897
|
$match: {
|
|
1961
1898
|
$expr: {
|
|
1962
1899
|
$and: [
|
|
1963
|
-
{ $eq: ['$taskId', '$$taskId'] },
|
|
1900
|
+
{ $eq: [ '$taskId', '$$taskId' ] },
|
|
1964
1901
|
],
|
|
1965
1902
|
},
|
|
1966
1903
|
},
|
|
@@ -1984,7 +1921,7 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
|
|
|
1984
1921
|
{
|
|
1985
1922
|
$match: {
|
|
1986
1923
|
$expr: {
|
|
1987
|
-
$eq: ['$taskId', '$$taskId'],
|
|
1924
|
+
$eq: [ '$taskId', '$$taskId' ],
|
|
1988
1925
|
},
|
|
1989
1926
|
},
|
|
1990
1927
|
},
|
|
@@ -2002,7 +1939,7 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
|
|
|
2002
1939
|
let: { fixtureId: '$planoData.fixtureId' },
|
|
2003
1940
|
pipeline: [
|
|
2004
1941
|
{
|
|
2005
|
-
$match: { $expr: { $eq: ['$_id', '$$fixtureId'] } },
|
|
1942
|
+
$match: { $expr: { $eq: [ '$_id', '$$fixtureId' ] } },
|
|
2006
1943
|
},
|
|
2007
1944
|
],
|
|
2008
1945
|
as: 'FixtureData',
|
|
@@ -2017,7 +1954,7 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
|
|
|
2017
1954
|
let: { fixtureId: '$FixtureData._id' },
|
|
2018
1955
|
pipeline: [
|
|
2019
1956
|
{
|
|
2020
|
-
$match: { $expr: { $eq: ['$fixtureId', '$$fixtureId'] } },
|
|
1957
|
+
$match: { $expr: { $eq: [ '$fixtureId', '$$fixtureId' ] } },
|
|
2021
1958
|
},
|
|
2022
1959
|
],
|
|
2023
1960
|
as: 'Fixtureshelves',
|
|
@@ -2052,16 +1989,16 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
|
|
|
2052
1989
|
$and: [
|
|
2053
1990
|
{
|
|
2054
1991
|
$or: [
|
|
2055
|
-
{ $eq: ['$redoStatus', true] },
|
|
1992
|
+
{ $eq: [ '$redoStatus', true ] },
|
|
2056
1993
|
{
|
|
2057
1994
|
$and: [
|
|
2058
|
-
{ $eq: ['$redoStatus', false] },
|
|
2059
|
-
{ $eq: ['$checklistStatus', 'submit'] },
|
|
1995
|
+
{ $eq: [ '$redoStatus', false ] },
|
|
1996
|
+
{ $eq: [ '$checklistStatus', 'submit' ] },
|
|
2060
1997
|
],
|
|
2061
1998
|
},
|
|
2062
1999
|
],
|
|
2063
2000
|
},
|
|
2064
|
-
{ $ne: [{ $ifNull: ['$FixtureData.fixtureName', null] }, null] },
|
|
2001
|
+
{ $ne: [ { $ifNull: [ '$FixtureData.fixtureName', null ] }, null ] },
|
|
2065
2002
|
// { $gt: [ { $size: { $ifNull: [ '$FixtureData' ] } }, 0 ] },
|
|
2066
2003
|
// { $gt: [ { $size: { $ifNull: [ '$FixtureData.shelfConfig', [] ] } }, 0 ] },
|
|
2067
2004
|
],
|
|
@@ -2108,48 +2045,3 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
|
|
|
2108
2045
|
|
|
2109
2046
|
return pipeline;
|
|
2110
2047
|
}
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
export async function getPlanoStoreVideoPageParams(req, res) {
|
|
2114
|
-
try {
|
|
2115
|
-
const { storeId } = req.body;
|
|
2116
|
-
|
|
2117
|
-
if (!storeId) {
|
|
2118
|
-
return res.sendError('Store ID Missing.', 400);
|
|
2119
|
-
}
|
|
2120
|
-
|
|
2121
|
-
const checkListRes = await planoStaticService.findOne({ type: 'storeVideoChecklist' }, { checklistIds: 1 });
|
|
2122
|
-
|
|
2123
|
-
if (checkListRes?.checklistIds?.length <= 0) {
|
|
2124
|
-
return res.sendError('No checklist ids found', 400);
|
|
2125
|
-
}
|
|
2126
|
-
|
|
2127
|
-
const checklistData = await processedChecklistService.findOne(
|
|
2128
|
-
{
|
|
2129
|
-
sourceCheckList_id: {
|
|
2130
|
-
$in: checkListRes?.checklistIds ?? [],
|
|
2131
|
-
},
|
|
2132
|
-
checklistStatus: "submit",
|
|
2133
|
-
store_id: storeId,
|
|
2134
|
-
checkListType: "custom",
|
|
2135
|
-
}, {}, { sort: { _id: -1 } }
|
|
2136
|
-
);
|
|
2137
|
-
|
|
2138
|
-
if (!checklistData) {
|
|
2139
|
-
return res.sendError('No checklist data found', 400);
|
|
2140
|
-
}
|
|
2141
|
-
|
|
2142
|
-
const response = {
|
|
2143
|
-
storeId: storeId,
|
|
2144
|
-
ChecklistDate: checklistData?.date_string,
|
|
2145
|
-
checklistType: checklistData?.checkListType,
|
|
2146
|
-
checklistStatus: checklistData?.checklistStatus,
|
|
2147
|
-
sourceCheckList_id: checklistData?.sourceCheckList_id,
|
|
2148
|
-
}
|
|
2149
|
-
|
|
2150
|
-
res.sendSuccess(response);
|
|
2151
|
-
} catch (e) {
|
|
2152
|
-
logger.error({ functionName: 'getPlanoStoreVideoPageParams', error: e });
|
|
2153
|
-
res.sendError('Failed to fetch plano store video page params', 500);
|
|
2154
|
-
}
|
|
2155
|
-
}
|