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