????
Current Path : C:/inetpub/vhost/sdoc.gdtsolutions.vn/package/app/controllers/quantri/ |
Current File : C:/inetpub/vhost/sdoc.gdtsolutions.vn/package/app/controllers/quantri/loaivanban.js |
var Database = require('../../models/Database'); class LoaiVBController extends Database { constructor(params) { super(params); } static create(params) { return new LoaiVBController(params); } async selectType() { return await this.select('SELECT DocType.Id,DocType.TypeGroup,DocTypeGroup.Name as GroupName,DocType.TypeName,DocType.TypeCode FROM DocType INNER JOIN DocTypeGroup ON DocType.TypeGroup = DocTypeGroup.Id'); } async addType(type) { var types = await this.select('SELECT * FROM DocType WHERE TypeName = @name', { name: type.name }); if (types.length) throw new Error(`Đã tồn tại loại văn bản [${type.name}]`); var query = 'INSERT INTO DocType(TypeGroup,TypeName,TypeCode) VALUES (@group,@name,@code)'; return await this.query(query, type); } async editType(type) { if (!type.id) throw new Error('Không xác định được cơ quan cần chỉnh sửa'); var types = await this.select('SELECT * FROM DocType WHERE TypeName = @name AND Id != @id', { name: type.name, id: type.id }); if (types.length) throw new Error(`Đã tồn tại loại văn bản khác có tên [${type.name}]`); var updates = []; if (typeof type.group != 'undefined') updates.push('TypeGroup = @group'); if (typeof type.name != 'undefined') updates.push('TypeName = @name'); if (typeof type.code != 'undefined') updates.push('TypeCode = @code'); return await this.query(`UPDATE DocType SET ${updates.join(',')} WHERE Id = @id`, type) } async deleteType(id) { return await this.query('DELETE FROM DocType WHERE Id = @id', { id: id }); } async getTypeGroups() { var typeGroups = await this.select('SELECT * FROM DocTypeGroup'); return typeGroups.map(function (x) { return { id: x.Id, text: x.Name } }) } } module.exports = LoaiVBController;