'use strict'; const qs = require('qs'); const Controller = require('egg').Controller; const uuid = require('node-uuid'); class DictController extends Controller { async info() { const ctx = this.ctx; const id = ctx.params.id; try { const result = await ctx.service.dict.find(id); this.ctx.body = { result, success: true, }; } catch (error) { this.ctx.body = { success: false, error, }; } } async list() { const param = qs.parse(this.ctx.query); const ctx = this.ctx; try { const result = await ctx.service.dict.list(param); const total = await ctx.service.dict.count(); this.ctx.body = { result, total: total[0].total, success: true, }; } catch (error) { this.ctx.body = { success: false, error, }; } } async add() { const ctx = this.ctx; const id = uuid.v4(); const data = ctx.request.body; data.id = id; try { await ctx.service.dict.add(data); this.ctx.body = { success: true }; } catch (error) { this.ctx.body = { success: false, error }; } } async update() { const ctx = this.ctx; const data = ctx.request.body; try { await ctx.service.dict.update(data); this.ctx.body = { success: true }; } catch (error) { this.ctx.body = { success: false, error }; } } async remove() { const ctx = this.ctx; try { await ctx.service.dict.remove(ctx.request.body); this.ctx.body = { success: true }; } catch (error) { this.ctx.body = { success: false, error }; } } } module.exports = DictController;