import { Provide } from '@midwayjs/core';
import { Admin } from '../../entity/system/admin.entity';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { BaseService } from '../../frame/BaseService';
@Provide()
export class AdminService extends BaseService<Admin> {
  @InjectEntityModel(Admin)
  model: Repository<Admin>;

  async initSuperAdmin() {
    const data = {
      account: 'admin',
      password: '1qaz2wsx',
      nick_name: '系统管理员',
      is_super: '0',
    };
    const is_exist = await this.model.count({ where: { is_super: '0' } });
    if (!is_exist) return await this.model.insert(data);
    return;
  }
}
