tango-app-api-store-builder 1.0.0-beta-113 → 1.0.0-beta-115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +4 -1
- package/inputjson/layoutverification.json +465 -0
- package/package.json +3 -2
- package/response.json +654 -0
- package/src/controllers/fixtureTemplate.controller.js +475 -0
- package/src/controllers/managePlano.controller.js +572 -0
- package/src/controllers/planoLibrary.controller.js +1418 -0
- package/src/controllers/script.controller.js +1861 -401
- package/src/controllers/storeBuilder.controller.js +665 -289
- package/src/controllers/task.controller.js +176 -59
- package/src/dtos/validation.dtos.js +227 -0
- package/src/routes/fixtureTemplate.routes.js +17 -0
- package/src/routes/managePlano.routes.js +18 -0
- package/src/routes/planoLibrary.routes.js +40 -0
- package/src/routes/script.routes.js +3 -1
- package/src/routes/storeBuilder.routes.js +7 -1
- package/src/routes/task.routes.js +1 -0
- package/src/service/fixtureConfig.service.js +30 -3
- package/src/service/planoLibrary.service.js +37 -0
- package/src/service/planoStaticData.service.js +3 -0
- package/src/service/planoTask.service.js +3 -0
- package/src/service/planoVm.service.js +49 -0
- package/src/service/planoproductCategory.service.js +47 -0
- package/src/service/vmType.service.js +33 -0
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
import * as floorService from '../service/storeBuilder.service.js';
|
|
2
|
+
import { logger } from 'tango-app-api-middleware';
|
|
3
|
+
// import * as storeService from '../service/store.service.js';
|
|
4
|
+
// import * as planoService from '../service/planogram.service.js';
|
|
5
|
+
import * as storeFixtureService from '../service/storeFixture.service.js';
|
|
6
|
+
import * as fixtureShelfService from '../service/fixtureShelf.service.js';
|
|
7
|
+
// import * as planoProductService from '../service/planoProduct.service.js';
|
|
8
|
+
import * as planoVmService from '../service/planoVm.service.js';
|
|
9
|
+
// import * as planoMappingService from '../service/planoMapping.service.js';
|
|
10
|
+
// import * as planoTaskService from '../service/planoTask.service.js';
|
|
11
|
+
// import * as processedTaskService from '../service/processedTaskservice.js';
|
|
12
|
+
import * as planoproductCategoryService from '../service/planoproductCategory.service.js';
|
|
13
|
+
import * as fixtureConfigService from '../service/fixtureConfig.service.js';
|
|
14
|
+
import * as fixtureLibraryService from '../service/planoLibrary.service.js';
|
|
15
|
+
import * as planoTaskService from '../service/planoTask.service.js';
|
|
16
|
+
import mongoose from 'mongoose';
|
|
17
|
+
export async function getplanoFeedback( req, res ) {
|
|
18
|
+
try {
|
|
19
|
+
let query = [];
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
query.push( {
|
|
23
|
+
$match: {
|
|
24
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
25
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
26
|
+
type: 'layout',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
$lookup: {
|
|
31
|
+
from: 'processedtasks',
|
|
32
|
+
let: { 'taskId': '$taskId' },
|
|
33
|
+
pipeline: [
|
|
34
|
+
{
|
|
35
|
+
$match: {
|
|
36
|
+
$expr: {
|
|
37
|
+
$and: [
|
|
38
|
+
{ $eq: [ '$_id', '$$taskId' ] },
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
$project: {
|
|
45
|
+
'userName': 1,
|
|
46
|
+
'createdAt': 1,
|
|
47
|
+
'createdByName': 1,
|
|
48
|
+
'submitTime_string': 1,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
as: 'taskData',
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
}, { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: true } },
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
let findPlanoCompliance = await planoTaskService.aggregate( query );
|
|
60
|
+
let queryfixture = [];
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
queryfixture.push( {
|
|
64
|
+
$match: {
|
|
65
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
66
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
67
|
+
type: 'fixture',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
$lookup: {
|
|
72
|
+
from: 'processedtasks',
|
|
73
|
+
let: { 'taskId': '$taskId' },
|
|
74
|
+
pipeline: [
|
|
75
|
+
{
|
|
76
|
+
$match: {
|
|
77
|
+
$expr: {
|
|
78
|
+
$and: [
|
|
79
|
+
{ $eq: [ '$_id', '$$taskId' ] },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
$project: {
|
|
86
|
+
'userName': 1,
|
|
87
|
+
'createdAt': 1,
|
|
88
|
+
'createdByName': 1,
|
|
89
|
+
'submitTime_string': 1,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
as: 'taskData',
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
}, { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: true } },
|
|
97
|
+
{
|
|
98
|
+
$lookup: {
|
|
99
|
+
from: 'storefixtures',
|
|
100
|
+
let: { 'fixtureId': '$fixtureId' },
|
|
101
|
+
pipeline: [
|
|
102
|
+
{
|
|
103
|
+
$match: {
|
|
104
|
+
$expr: {
|
|
105
|
+
$and: [
|
|
106
|
+
{ $eq: [ '$_id', '$$fixtureId' ] },
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
as: 'storeFixtureData',
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
$unwind: { path: '$storeFixtureData', preserveNullAndEmptyArrays: true },
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
$lookup: {
|
|
120
|
+
from: 'fixtureconfigs',
|
|
121
|
+
let: { 'fixtureConfigId': '$storeFixtureData.fixtureConfigId' },
|
|
122
|
+
pipeline: [
|
|
123
|
+
{
|
|
124
|
+
$match: {
|
|
125
|
+
$expr: {
|
|
126
|
+
$and: [
|
|
127
|
+
{ $eq: [ '$_id', '$$fixtureConfigId' ] },
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
as: 'FixtureData',
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
$unwind: { path: '$FixtureData', preserveNullAndEmptyArrays: true },
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
let findfixtureCompliance = await planoTaskService.aggregate( queryfixture );
|
|
143
|
+
let queryVm = [];
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
queryVm.push( {
|
|
147
|
+
$match: {
|
|
148
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
149
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
150
|
+
type: 'vm',
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
$lookup: {
|
|
155
|
+
from: 'processedtasks',
|
|
156
|
+
let: { 'taskId': '$taskId' },
|
|
157
|
+
pipeline: [
|
|
158
|
+
{
|
|
159
|
+
$match: {
|
|
160
|
+
$expr: {
|
|
161
|
+
$and: [
|
|
162
|
+
{ $eq: [ '$_id', '$$taskId' ] },
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
$project: {
|
|
169
|
+
'userName': 1,
|
|
170
|
+
'createdAt': 1,
|
|
171
|
+
'createdByName': 1,
|
|
172
|
+
'submitTime_string': 1,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
as: 'taskData',
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
}, { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: true } },
|
|
180
|
+
{
|
|
181
|
+
$lookup: {
|
|
182
|
+
from: 'storefixtures',
|
|
183
|
+
let: { 'fixtureId': '$fixtureId' },
|
|
184
|
+
pipeline: [
|
|
185
|
+
{
|
|
186
|
+
$match: {
|
|
187
|
+
$expr: {
|
|
188
|
+
$and: [
|
|
189
|
+
{ $eq: [ '$_id', '$$fixtureId' ] },
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
as: 'storeFixtureData',
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
$unwind: { path: '$storeFixtureData', preserveNullAndEmptyArrays: true },
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
$lookup: {
|
|
203
|
+
from: 'fixtureconfigs',
|
|
204
|
+
let: { 'fixtureConfigId': '$storeFixtureData.fixtureConfigId' },
|
|
205
|
+
pipeline: [
|
|
206
|
+
{
|
|
207
|
+
$match: {
|
|
208
|
+
$expr: {
|
|
209
|
+
$and: [
|
|
210
|
+
{ $eq: [ '$_id', '$$fixtureConfigId' ] },
|
|
211
|
+
],
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
as: 'FixtureData',
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
$unwind: { path: '$FixtureData', preserveNullAndEmptyArrays: true },
|
|
221
|
+
},
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
let findvmCompliance = await planoTaskService.aggregate( queryVm );
|
|
226
|
+
console.log( findvmCompliance );
|
|
227
|
+
res.sendSuccess( { count: findfixtureCompliance.length, layoutData: findPlanoCompliance, fixtureData: findfixtureCompliance, VmData: findvmCompliance } );
|
|
228
|
+
} catch ( e ) {
|
|
229
|
+
logger.error( { functionName: 'getplanoFeedback', error: e, message: req.body } );
|
|
230
|
+
return res.sendError( e, 500 );
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
export async function getStoreFixturesfeedback( req, res ) {
|
|
234
|
+
try {
|
|
235
|
+
let query = [];
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
query.push( {
|
|
239
|
+
$match: {
|
|
240
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
241
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
242
|
+
type: { $ne: 'layout' },
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
$lookup: {
|
|
247
|
+
from: 'processedtasks',
|
|
248
|
+
let: { 'taskId': '$taskId' },
|
|
249
|
+
pipeline: [
|
|
250
|
+
{
|
|
251
|
+
$match: {
|
|
252
|
+
$expr: {
|
|
253
|
+
$and: [
|
|
254
|
+
{ $eq: [ '$_id', '$$taskId' ] },
|
|
255
|
+
],
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
$project: {
|
|
261
|
+
'userName': 1,
|
|
262
|
+
'createdAt': 1,
|
|
263
|
+
'createdByName': 1,
|
|
264
|
+
'submitTime_string': 1,
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
as: 'taskData',
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
}, { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: true } },
|
|
272
|
+
{
|
|
273
|
+
$lookup: {
|
|
274
|
+
from: 'fixtureconfigs',
|
|
275
|
+
let: { 'fixtureId': '$fixtureId' },
|
|
276
|
+
pipeline: [
|
|
277
|
+
{
|
|
278
|
+
$match: {
|
|
279
|
+
$expr: {
|
|
280
|
+
$and: [
|
|
281
|
+
{ $eq: [ '$_id', '$$fixtureId' ] },
|
|
282
|
+
],
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
as: 'FixtureData',
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
$unwind: { path: '$FixtureData', preserveNullAndEmptyArrays: true },
|
|
292
|
+
},
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
let findPlanoCompliance = await planoTaskService.aggregate( query );
|
|
297
|
+
console.log( findPlanoCompliance.length );
|
|
298
|
+
res.sendSuccess( { count: findPlanoCompliance.length, data: findPlanoCompliance } );
|
|
299
|
+
} catch ( e ) {
|
|
300
|
+
logger.error( { functionName: 'getplanoFeedbackFixture', error: e, message: req.body } );
|
|
301
|
+
return res.sendError( e, 500 );
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
export async function updateStorePlano( req, res ) {
|
|
305
|
+
try {
|
|
306
|
+
const { floorId, data } = req.body;
|
|
307
|
+
|
|
308
|
+
const floorData = await floorService.findOne( { _id: new mongoose.Types.ObjectId( floorId ) } );
|
|
309
|
+
|
|
310
|
+
const additionalMeta = {
|
|
311
|
+
clientId: '11',
|
|
312
|
+
storeId: floorData.toObject().storeId,
|
|
313
|
+
storeName: floorData.toObject().storeName,
|
|
314
|
+
planoId: floorData.toObject().planoId,
|
|
315
|
+
floorId: floorData.toObject()._id,
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const layoutPolygon = JSON.parse( JSON.stringify( data.layoutPolygon ) );
|
|
319
|
+
|
|
320
|
+
layoutPolygon.forEach( ( element ) => {
|
|
321
|
+
delete element.fixtures;
|
|
322
|
+
} );
|
|
323
|
+
|
|
324
|
+
await floorService.updateOne( { _id: new mongoose.Types.ObjectId( floorId ) },
|
|
325
|
+
{ layoutPolygon: layoutPolygon } );
|
|
326
|
+
|
|
327
|
+
const currentWallFixtures = data.layoutPolygon.flatMap( ( element ) =>
|
|
328
|
+
( element.fixtures || [] ).map( ( fixture ) => fixture ),
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
const currentFloorFixtures = ( data.centerFixture || [] );
|
|
332
|
+
|
|
333
|
+
const currentFixtures = [ ...currentWallFixtures, ...currentFloorFixtures ];
|
|
334
|
+
|
|
335
|
+
const existingFixtures = await storeFixtureService.find( { floorId: new mongoose.Types.ObjectId( floorId ) } );
|
|
336
|
+
|
|
337
|
+
const currentIds = new Set( currentFixtures.map( ( f ) => f._id ) );
|
|
338
|
+
const removedFixtures = existingFixtures.filter(
|
|
339
|
+
( f ) => f._id && !currentIds.has( f._id.toString() ),
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
if ( removedFixtures.length ) {
|
|
343
|
+
const fixtureIds = removedFixtures.map( ( fixture ) => fixture.toObject()._id );
|
|
344
|
+
await storeFixtureService.deleteMany( { _id: { $in: fixtureIds } } );
|
|
345
|
+
await fixtureShelfService.deleteMany( { fixtureId: { $in: fixtureIds } } );
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
const newWallFixtures = currentWallFixtures.filter( ( fixture ) => fixture?._id?.startsWith( 'new' ) );
|
|
350
|
+
|
|
351
|
+
const newFloorFixtures = currentFloorFixtures.filter( ( fixture ) => fixture?._id?.startsWith( 'new' ) );
|
|
352
|
+
|
|
353
|
+
const newFixtures = [ ...newWallFixtures, ...newFloorFixtures ];
|
|
354
|
+
|
|
355
|
+
if ( newFixtures.length ) {
|
|
356
|
+
newFixtures.forEach( async ( fixture ) => {
|
|
357
|
+
delete fixture._id;
|
|
358
|
+
const fixturePayload = {
|
|
359
|
+
...additionalMeta,
|
|
360
|
+
...fixture,
|
|
361
|
+
};
|
|
362
|
+
const createdFixture = await storeFixtureService.create( fixturePayload );
|
|
363
|
+
fixture.shelfConfig.forEach( async ( shelf ) => {
|
|
364
|
+
delete shelf._id;
|
|
365
|
+
const shelfPayload = {
|
|
366
|
+
...additionalMeta,
|
|
367
|
+
...shelf,
|
|
368
|
+
fixtureId: createdFixture.toObject()._id,
|
|
369
|
+
|
|
370
|
+
};
|
|
371
|
+
await fixtureShelfService.create( shelfPayload );
|
|
372
|
+
} );
|
|
373
|
+
} );
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
currentFixtures.forEach( async ( fixture ) => {
|
|
377
|
+
if ( mongoose.Types.ObjectId.isValid( fixture._id ) ) {
|
|
378
|
+
const updatedFixture = await storeFixtureService.upsertOne( { _id: new mongoose.Types.ObjectId( fixture._id ) }, fixture );
|
|
379
|
+
|
|
380
|
+
await fixtureShelfService.deleteMany( { fixtureId: new mongoose.Types.ObjectId( fixture._id ) } );
|
|
381
|
+
|
|
382
|
+
fixture.shelfConfig.forEach( async ( shelf ) => {
|
|
383
|
+
delete shelf._id;
|
|
384
|
+
const shelfPayload = {
|
|
385
|
+
...additionalMeta,
|
|
386
|
+
...shelf,
|
|
387
|
+
fixtureId: updatedFixture.toObject()._id,
|
|
388
|
+
};
|
|
389
|
+
await fixtureShelfService.create( shelfPayload );
|
|
390
|
+
} );
|
|
391
|
+
}
|
|
392
|
+
} );
|
|
393
|
+
|
|
394
|
+
res.sendSuccess( 'Updated Successfully' );
|
|
395
|
+
} catch ( e ) {
|
|
396
|
+
logger.error( { functionName: 'updateStorePlano', error: e } );
|
|
397
|
+
return res.sendError( e, 500 );
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
export async function fixtureList( req, res ) {
|
|
401
|
+
try {
|
|
402
|
+
let findData = await fixtureLibraryService.find( { clientId: req.query.clientId } );
|
|
403
|
+
if ( findData.length === 0 ) {
|
|
404
|
+
return res.sendError( 'nodata found', 204 );
|
|
405
|
+
}
|
|
406
|
+
res.sendSuccess( findData );
|
|
407
|
+
} catch ( e ) {
|
|
408
|
+
logger.error( { functionName: 'fixtureList', error: e } );
|
|
409
|
+
return res.sendError( e, 500 );
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
export async function templateList( req, res ) {
|
|
413
|
+
try {
|
|
414
|
+
let findData = await fixtureConfigService.find( { clientId: req.query.clientId, fixtureLibraryId: new mongoose.Types.ObjectId( req.query.fixtureId ) } );
|
|
415
|
+
if ( findData.length === 0 ) {
|
|
416
|
+
return res.sendError( 'nodata found', 204 );
|
|
417
|
+
}
|
|
418
|
+
res.sendSuccess( findData );
|
|
419
|
+
} catch ( e ) {
|
|
420
|
+
logger.error( { functionName: 'templateList', error: e } );
|
|
421
|
+
return res.sendError( e, 500 );
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
export async function fixtureBrandsList( req, res ) {
|
|
425
|
+
try {
|
|
426
|
+
let findData = await planoproductCategoryService.find( { clientId: req.query.clientId } );
|
|
427
|
+
if ( findData.length === 0 ) {
|
|
428
|
+
return res.sendError( 'nodata found', 204 );
|
|
429
|
+
}
|
|
430
|
+
res.sendSuccess( findData );
|
|
431
|
+
} catch ( e ) {
|
|
432
|
+
logger.error( { functionName: 'fixtureBrandsList', error: e } );
|
|
433
|
+
return res.sendError( e, 500 );
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export async function fixtureVMList( req, res ) {
|
|
438
|
+
try {
|
|
439
|
+
let findData = await planoVmService.find( { clientId: req.query.clientId } );
|
|
440
|
+
if ( findData.length === 0 ) {
|
|
441
|
+
return res.sendError( 'nodata found', 204 );
|
|
442
|
+
}
|
|
443
|
+
res.sendSuccess( findData );
|
|
444
|
+
} catch ( e ) {
|
|
445
|
+
logger.error( { functionName: 'fixtureVMList', error: e } );
|
|
446
|
+
return res.sendError( e, 500 );
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
export async function updateFixtureStatus( req, res ) {
|
|
450
|
+
try {
|
|
451
|
+
console.log( req.body );
|
|
452
|
+
|
|
453
|
+
let comments = {
|
|
454
|
+
userId: req.user._id,
|
|
455
|
+
userName: req.user.userName,
|
|
456
|
+
role: req.user.role,
|
|
457
|
+
responsetype: req.user.type,
|
|
458
|
+
comment: req.body.comments,
|
|
459
|
+
};
|
|
460
|
+
console.log( comments );
|
|
461
|
+
// return;
|
|
462
|
+
let updateResponse = await planoTaskService.updateOnefilters(
|
|
463
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
464
|
+
{
|
|
465
|
+
$set: { 'answers.$[ans].issues.$[iss].Details.$[det].status': 'completed' },
|
|
466
|
+
},
|
|
467
|
+
[
|
|
468
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
469
|
+
{ 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
|
|
470
|
+
{ 'det._id': new mongoose.Types.ObjectId( req.body.DetailsId ) },
|
|
471
|
+
|
|
472
|
+
] );
|
|
473
|
+
let updatecomment = await planoTaskService.updateOnefilters(
|
|
474
|
+
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
475
|
+
{
|
|
476
|
+
$push: { 'answers.$[ans].issues.$[iss].Details.$[det].comments': comments },
|
|
477
|
+
},
|
|
478
|
+
[
|
|
479
|
+
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
480
|
+
{ 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
|
|
481
|
+
{ 'det._id': new mongoose.Types.ObjectId( req.body.DetailsId ) },
|
|
482
|
+
|
|
483
|
+
] );
|
|
484
|
+
console.log( updateResponse, updatecomment );
|
|
485
|
+
res.sendSuccess( 'updated successfully' );
|
|
486
|
+
} catch ( e ) {
|
|
487
|
+
logger.error( { functionName: 'updateFixtureStatus', error: e } );
|
|
488
|
+
return res.sendError( e, 500 );
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
export async function updateStoreFixture(req, res) {
|
|
493
|
+
try {
|
|
494
|
+
const { fixtureId, data } = req.body;
|
|
495
|
+
|
|
496
|
+
const currentFixture = await storeFixtureService.findOne({ _id: new mongoose.Types.ObjectId(fixtureId) });
|
|
497
|
+
let currentFixtureDoc = currentFixture.toObject()
|
|
498
|
+
|
|
499
|
+
const productBrandName = new Set();
|
|
500
|
+
const productCategory = new Set();
|
|
501
|
+
const productSubCategory = new Set();
|
|
502
|
+
|
|
503
|
+
data.shelfConfig.forEach((shelf) => {
|
|
504
|
+
const { productBrandName: brand, productCategory: category, productSubCategory: subCategory } = shelf;
|
|
505
|
+
|
|
506
|
+
if (Array.isArray(brand)) {
|
|
507
|
+
brand.forEach((b) => productBrandName.add(b));
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
if (Array.isArray(category)) {
|
|
511
|
+
category.forEach((c) => productCategory.add(c));
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (Array.isArray(subCategory)) {
|
|
515
|
+
subCategory.forEach((s) => productSubCategory.add(s));
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
if (currentFixtureDoc.fixtureConfigId.toString() !== data.fixtureConfigId) {
|
|
522
|
+
const newTemplate = await fixtureConfigService.findOne({_id: data.fixtureConfigId})
|
|
523
|
+
currentFixtureDoc = {
|
|
524
|
+
...currentFixtureDoc,
|
|
525
|
+
...newTemplate.toObject(),
|
|
526
|
+
fixtureConfigDoc:newTemplate.toObject()._id,
|
|
527
|
+
productBrandName:[...productBrandName],
|
|
528
|
+
productCategory:[...productCategory],
|
|
529
|
+
productSubCategory:[...productSubCategory]
|
|
530
|
+
}
|
|
531
|
+
}else{
|
|
532
|
+
currentFixtureDoc = {
|
|
533
|
+
...currentFixtureDoc,
|
|
534
|
+
...data,
|
|
535
|
+
productBrandName:[...productBrandName],
|
|
536
|
+
productCategory:[...productCategory],
|
|
537
|
+
productSubCategory:[...productSubCategory]
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
delete currentFixtureDoc._id
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
await storeFixtureService.updateOne({ _id: new mongoose.Types.ObjectId(fixtureId) }, currentFixtureDoc);
|
|
545
|
+
|
|
546
|
+
if (data?.shelfConfig?.length) {
|
|
547
|
+
await fixtureShelfService.deleteMany({ fixtureId: new mongoose.Types.ObjectId(fixtureId) })
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
data.shelfConfig.forEach(async (shelf) => {
|
|
551
|
+
delete shelf?._id
|
|
552
|
+
const additionalMeta = {
|
|
553
|
+
clientId: currentFixture.clientId,
|
|
554
|
+
storeId: currentFixture.storeId,
|
|
555
|
+
storeName: currentFixture.storeName,
|
|
556
|
+
planoId: currentFixture.planoId,
|
|
557
|
+
floorId: currentFixture.floorId,
|
|
558
|
+
fixtureId: currentFixture._id,
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
await fixtureShelfService.create({ ...additionalMeta, ...shelf });
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
res.sendSuccess('Updated Successfully');
|
|
567
|
+
} catch (e) {
|
|
568
|
+
logger.error({ functionName: 'updateStoreFixture', error: e });
|
|
569
|
+
return res.sendError(e, 500);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|