12345678910111213141516171819202122232425262728293031323334 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose-free/lib/service');
- const template = require('../public/table-template');
- const TSTemplate = require('../public/ts-template');
- class TableService extends CrudService {
- constructor(ctx) {
- super(ctx, 'table');
- this.model = this.ctx.model.Table;
- }
- async test(data) {
- console.log(data);
- }
- async toExport({ ids }) {
- const res = await this.model.find({ _id: { $in: ids } });
- const data = {};
- for (const i of res) {
- const d = template(i);
- data[i.name_zh ? i.name_zh : i.name] = d;
- }
- return data;
- }
- async toExportTS({ ids }) {
- const res = await this.model.find({ _id: { $in: ids } }).lean();
- const data = {};
- for (const i of res) {
- const d = TSTemplate(i);
- data[i.name_zh ? i.name_zh : i.name] = d;
- }
- return data;
- }
- }
- module.exports = TableService;
|