????

Your IP : 18.191.73.161


Current Path : C:/inetpub/vhost/sdoc.gdtsolutions.vn/package/app/controllers/quantri/
Upload File :
Current File : C:/inetpub/vhost/sdoc.gdtsolutions.vn/package/app/controllers/quantri/nhomtailieu.js

var Database = require('../../models/Database');
class NhomTLController extends Database {
  constructor(params) {
    super(params);
  }
  static create(params) {
    return new NhomTLController(params);
  }
  async selectGroup() {
    return await this.select('SELECT * FROM [FileGroup]');
  }
  async addGroup(group) {
    var groups = await this.select('SELECT * FROM [FileGroup] WHERE GroupName = @name', { name: group.GroupName });
    if (groups.length) throw new Error(`Đã tồn tại [${group.GroupName}]`);
    var query = 'INSERT INTO [FileGroup](GroupName) VALUES (@name)';
    return await this.query(query, { name: group.GroupName });
  }
  async editGroup(group) {
    if (!group.Id) throw new Error('Không xác định được nhóm tài liệu cần chỉnh sửa');
    return await this.query('UPDATE [FileGroup] SET GroupName = @name WHERE Id = @id', { id: group.Id, name: group.GroupName })
  }
  async deleteGroup(id) {
    var files = await this.select('SELECT * FROM [File] WHERE GroupId = @id', { id: id });
    if (files.length) throw new Error('Có tồn tại hồ sơ trong nhóm tài liệu!\nKhông thể xóa nhóm tài liệu');
    return await this.query('DELETE FROM [FileGroup] WHERE Id = @id', { id: id });
  }
}
module.exports = NhomTLController;