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