yaml-admin-api 0.0.81 → 0.0.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml-admin-api",
3
- "version": "0.0.81",
3
+ "version": "0.0.83",
4
4
  "license": "MIT",
5
5
  "description": "YAML Admin API package",
6
6
  "type": "commonjs",
@@ -338,6 +338,34 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
338
338
  res.json(list);
339
339
  }));
340
340
 
341
+ //view
342
+ app.get(`${api_prefix}/${entity_name}/:id`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
343
+ let f = {}
344
+ f[key_field.name] = parseKey(req.params.id)
345
+ Object.assign(f, default_filter)
346
+
347
+ let aggregate = await makeApiGenerateAggregate(db, entity_name, yml_entity, yml, options)
348
+
349
+ let m
350
+ if(aggregate?.length > 0) {
351
+ aggregate = [{$match: f}, ...aggregate, { $limit: 1 }]
352
+ if(yml.debug && entity_name == 'ils')
353
+ console.log('list', entity_name, JSON.stringify(aggregate, null, 2))
354
+ const result = await db.collection(collection_name).aggregate(aggregate).toArray()
355
+ m = result.length > 0 ? result[0] : null
356
+ } else {
357
+ m = await db.collection(collection_name).findOne(f);
358
+ }
359
+
360
+ if (!m)
361
+ return res.status(404).send('Not found');
362
+
363
+ m.id = getKeyFromEntity(m)
364
+ await addInfo(db, [m])
365
+
366
+ res.json(m);
367
+ }))
368
+
341
369
 
342
370
  const constructEntity = async (req, entityId) => {
343
371
  var entity = {};
@@ -467,35 +495,6 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
467
495
  res.json(entity);
468
496
  }));
469
497
 
470
- //view
471
- app.get(`${api_prefix}/${entity_name}/:id`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
472
- let f = {}
473
- f[key_field.name] = parseKey(req.params.id)
474
- Object.assign(f, default_filter)
475
-
476
- let aggregate = await makeApiGenerateAggregate(db, entity_name, yml_entity, yml, options)
477
-
478
- let m
479
- if(aggregate?.length > 0) {
480
- aggregate = [{$match: f}, ...aggregate, { $limit: 1 }]
481
- const result = await db.collection(collection_name).aggregate(aggregate).toArray()
482
- m = result.length > 0 ? result[0] : null
483
- } else {
484
- m = await db.collection(collection_name).findOne(f);
485
- }
486
-
487
- if (!m)
488
- return res.status(404).send('Not found');
489
-
490
- m.id = getKeyFromEntity(m)
491
- await addInfo(db, [m])
492
-
493
- if(yml.debug)
494
- console.log('show', entity_name, m)
495
-
496
- res.json(m);
497
- }))
498
-
499
498
  //delete
500
499
  app.delete(`${api_prefix}/${entity_name}/:id`, auth.isAuthenticated, asyncErrorHandler(async (req, res) =>{
501
500
  let f = {}
@@ -793,9 +792,7 @@ const makeApiGenerateAggregate = async (db, entity_name, yml_entity, yml, option
793
792
  projection[field] = 1
794
793
  } else if(fields) {
795
794
  fields.forEach(m => {
796
- if(m.type !== 'reference') {
797
- projection[m.name] = 1
798
- }
795
+ projection[m.name] = 1
799
796
  })
800
797
 
801
798
  // reference 필드는 중첩 lookup으로 처리