yaml-admin-api 0.0.74 → 0.0.76

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.74",
3
+ "version": "0.0.76",
4
4
  "license": "MIT",
5
5
  "description": "YAML Admin API package",
6
6
  "type": "commonjs",
@@ -253,15 +253,12 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
253
253
  let aggregate = await makeApiGenerateAggregate(db, entity_name, yml_entity, yml, options)
254
254
 
255
255
  if(aggregate?.length > 0) {
256
- aggregate = [{$match: f}, ...aggregate]
257
-
256
+ aggregate = [...aggregate, {$match: f}]
258
257
  const countResult = await db.collection(entity_name).aggregate([...aggregate, { $count: 'count' }]).toArray()
259
258
  count = countResult.length > 0 ? countResult[0].count : 0
260
259
 
261
- list = await db.collection(entity_name).aggregate(aggregate)
262
- .sort(s)
263
- .skip(parseInt(_start))
264
- .limit(l).toArray()
260
+ aggregate = [...aggregate, { $sort: s }, { $skip: parseInt(_start) }, { $limit: l }]
261
+ list = await db.collection(entity_name).aggregate(aggregate).toArray()
265
262
  } else
266
263
  {
267
264
  count = await db.collection(entity_name).find(f).project(projection).sort(s).count()
@@ -707,6 +704,12 @@ const makeApiGenerateAggregate = async (db, entity_name, yml_entity, yml, option
707
704
  { $match: { $expr: { $eq: ['$' + match, '$$local_key'] } } }
708
705
  ]
709
706
 
707
+ // single일 때 max _id로 하나만 선택 ($match 바로 다음에)
708
+ if(single) {
709
+ innerPipeline.push({ $sort: { _id: -1 } })
710
+ innerPipeline.push({ $limit: 1 })
711
+ }
712
+
710
713
  // projection 구성
711
714
  const projection = { _id: 0, [match]: 1 }
712
715
  if(field) {
@@ -726,8 +729,8 @@ const makeApiGenerateAggregate = async (db, entity_name, yml_entity, yml, option
726
729
  })
727
730
  }
728
731
 
729
- // projection을 innerPipeline 맨 앞에 추가 (match 다음)
730
- innerPipeline.splice(1, 0, { $project: projection })
732
+ // projection을 innerPipeline 추가
733
+ innerPipeline.push({ $project: projection })
731
734
 
732
735
  // 기본 $lookup 추가
733
736
  aggregate.push({