table.js 905 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose-free/lib/service');
  3. const template = require('../public/table-template');
  4. const TSTemplate = require('../public/ts-template');
  5. class TableService extends CrudService {
  6. constructor(ctx) {
  7. super(ctx, 'table');
  8. this.model = this.ctx.model.Table;
  9. }
  10. async test(data) {
  11. console.log(data);
  12. }
  13. async toExport({ ids }) {
  14. const res = await this.model.find({ _id: { $in: ids } });
  15. const data = {};
  16. for (const i of res) {
  17. const d = template(i);
  18. data[i.name_zh ? i.name_zh : i.name] = d;
  19. }
  20. return data;
  21. }
  22. async toExportTS({ ids }) {
  23. const res = await this.model.find({ _id: { $in: ids } }).lean();
  24. const data = {};
  25. for (const i of res) {
  26. const d = TSTemplate(i);
  27. data[i.name_zh ? i.name_zh : i.name] = d;
  28. }
  29. return data;
  30. }
  31. }
  32. module.exports = TableService;