yaml-admin-api 0.0.35 → 0.0.37

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.35",
3
+ "version": "0.0.37",
4
4
  "license": "MIT",
5
5
  "description": "YAML Admin API package",
6
6
  "type": "commonjs",
@@ -320,7 +320,7 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
320
320
 
321
321
 
322
322
  //edit
323
- app.put(`/${entity_name}/:id`, auth.isAuthenticated, async (req, res) => {
323
+ app.put(`/${entity_name}/:id`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
324
324
  let entityId = parseKey(req.params.id)
325
325
 
326
326
  const entity = await constructEntity(req, entityId);
@@ -357,10 +357,10 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
357
357
  entity.id = (key_field.type == 'objectId') ? entityId?.toString() : entityId
358
358
 
359
359
  res.json(entity);
360
- });
360
+ }));
361
361
 
362
362
  //view
363
- app.get(`/${entity_name}/:id`, auth.isAuthenticated, async (req, res) => {
363
+ app.get(`/${entity_name}/:id`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
364
364
  let f = {}
365
365
  f[key_field.name] = parseKey(req.params.id)
366
366
  const m = await db.collection(entity_name).findOne(f);
@@ -371,10 +371,10 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
371
371
  await addInfo(db, [m])
372
372
 
373
373
  res.json(m);
374
- })
374
+ }))
375
375
 
376
376
  //delete
377
- app.delete(`/${entity_name}/:id`, auth.isAuthenticated, async function (req, res) {
377
+ app.delete(`/${entity_name}/:id`, auth.isAuthenticated, asyncErrorHandler(async (req, res) =>{
378
378
  let f = {}
379
379
  f[key_field.name] = parseKey(req.params.id)
380
380
  const entity = await db.collection(entity_name).findOne(f);
@@ -399,10 +399,11 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
399
399
  options?.listener?.entityDeleted?.(db, entity_name, entity)
400
400
 
401
401
  res.json(entity);
402
- });
402
+ }));
403
+
403
404
 
404
405
  if (yml_entity.crud?.export) {
405
- app.post(`/excel/${entity_name}/export`, auth.isAuthenticated, async (req, res) => {
406
+ app.post(`/excel/${entity_name}/export`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
406
407
  const filename = `${entity_name}_`
407
408
  const fields = yml_entity.crud.export.fields.map(field => ({
408
409
  label: field.name,
@@ -434,15 +435,15 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
434
435
  const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'buffer' });
435
436
 
436
437
  const currentTime = moment().format('YYYYMMDD_HHmmss');
437
- const key = `/excel/${filename}${currentTime}.xlsx`;
438
+ const key = `excel/${filename}${currentTime}.xlsx`;
438
439
  await uploader.uploadSecure(key, excelBuffer);
439
440
  let url = await uploader.getUrlSecure(key, auth);
440
441
  return res.json({ r: true, url });
441
- })
442
+ }))
442
443
  }
443
444
 
444
445
  if (yml_entity.crud?.import) {
445
- app.post(`/excel/${entity_name}/import`, auth.isAuthenticated, async (req, res) => {
446
+ app.post(`/excel/${entity_name}/import`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
446
447
  const { base64 } = req.body
447
448
  const buf = Buffer.from(base64, 'base64');
448
449
  const workbook = XLSX.read(buf, { type: 'buffer' });
@@ -553,7 +554,7 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
553
554
 
554
555
 
555
556
  res.json({ r: true, msg: 'Import success - ' + result.upsertedCount + ' new rows inserted' });
556
- })
557
+ }))
557
558
  }
558
559
  }
559
560