yaml-admin-api 0.0.41 → 0.0.43

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.41",
3
+ "version": "0.0.43",
4
4
  "license": "MIT",
5
5
  "description": "YAML Admin API package",
6
6
  "type": "commonjs",
@@ -210,8 +210,14 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
210
210
  }
211
211
  })
212
212
 
213
- //console.log('f', f)
214
- //console.log('s', s)
213
+ if(req.query['id']) {
214
+ let array = req.query['id']
215
+ if(Array.isArray(array)) {
216
+ f[key_field.name] = { $in: array.map(v => parseKey(v)) }
217
+ } else {
218
+ f[key_field.name] = parseKey(array)
219
+ }
220
+ }
215
221
 
216
222
  var name = req.query.name;
217
223
  if (name == null && req.query.q)
@@ -237,6 +243,8 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
237
243
  console.log('list', entity_name, 'found', count)
238
244
 
239
245
  await addInfo(db, list)
246
+ if(options?.listener?.entityListed)
247
+ await options.listener.entityListed(db, entity_name, list)
240
248
 
241
249
  res.header('X-Total-Count', count);
242
250
  res.json(list);
@@ -309,7 +317,8 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
309
317
 
310
318
  var r = await db.collection(entity_name).insertOne(entity);
311
319
  //Custom Create Tail Start
312
- options?.listener?.entityCreated?.(db, entity_name, entity)
320
+ if(options?.listener?.entityCreated)
321
+ await options.listener.entityCreated(db, entity_name, entity)
313
322
  //Custom Create Tail End
314
323
 
315
324
  const generatedId = entityId || r.insertedId
@@ -350,7 +359,8 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
350
359
  await db.collection(entity_name).updateOne(f, { $set: entity });
351
360
 
352
361
  //Custom Create Tail Start
353
- options?.listener?.entityUpdated?.(db, entity_name, entity)
362
+ if(options?.listener?.entityUpdated)
363
+ await options.listener.entityUpdated(db, entity_name, entity)
354
364
  //Custom Create Tail End
355
365
 
356
366
  // Ensure React-Admin receives an `id` in the response
@@ -370,6 +380,9 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
370
380
  m.id = getKeyFromEntity(m)
371
381
  await addInfo(db, [m])
372
382
 
383
+ if(yml.debug)
384
+ console.log('show', entity_name, m)
385
+
373
386
  res.json(m);
374
387
  }))
375
388
 
@@ -396,7 +409,8 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
396
409
  else
397
410
  await db.collection(entity_name).deleteOne(f);
398
411
 
399
- options?.listener?.entityDeleted?.(db, entity_name, entity)
412
+ if(options?.listener?.entityDeleted)
413
+ await options.listener.entityDeleted(db, entity_name, entity)
400
414
 
401
415
  res.json(entity);
402
416
  }));
@@ -601,7 +615,6 @@ const makeApiGenerateFields = async (db, entity_name, yml_entity, yml, options,
601
615
 
602
616
  let match_from_list = data_list.map(m=>matchPathInObject(m, match_from))
603
617
  match_from_list = match_from_list.filter(m=>m)
604
- const f = { [match]: {$in:match_from_list} }
605
618
  const projection = {[match]:1}
606
619
 
607
620
  const aggregate = [
@@ -610,7 +623,7 @@ const makeApiGenerateFields = async (db, entity_name, yml_entity, yml, options,
610
623
 
611
624
  if(field)
612
625
  projection[field] = 1
613
- else {
626
+ else if(fields){
614
627
  fields.map(m=>{
615
628
  projection[m.name] = 1
616
629
  })
@@ -618,9 +631,13 @@ const makeApiGenerateFields = async (db, entity_name, yml_entity, yml, options,
618
631
  fields.map(m=>{
619
632
  if(m.type == 'reference') {
620
633
  let project = { _id: 0 }
621
- m.fields.map(f=>{
622
- project[f.name] = 1
623
- })
634
+
635
+ if(m.field)
636
+ project[m.field] = 1
637
+ else
638
+ m.fields.map(f=>{
639
+ project[f.name] = 1
640
+ })
624
641
 
625
642
  aggregate.push({ $lookup: {
626
643
  from: m.reference_entity,
@@ -633,6 +650,9 @@ const makeApiGenerateFields = async (db, entity_name, yml_entity, yml, options,
633
650
  } })
634
651
  if(m.single)
635
652
  aggregate.push({ $unwind: `$${m.name}` })
653
+
654
+ if(m.field)
655
+ aggregate.push({ $addFields: { [m.field]: `$${m.name}.${m.field}` } })
636
656
  }
637
657
  })
638
658
  }