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