????
Current Path : C:/inetpub/vhost/binhdinhinvest.gdtvietnam.com/api/dist/auth/dang-nhap/ |
Current File : C:/inetpub/vhost/binhdinhinvest.gdtvietnam.com/api/dist/auth/dang-nhap/dang-nhap.service.js |
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LoginService = void 0; const common_1 = require("@nestjs/common"); const jwt_1 = require("@nestjs/jwt"); const typeorm_1 = require("@nestjs/typeorm"); const typeorm_2 = require("typeorm"); const entity_1 = require("../../admin/entity"); let LoginService = class LoginService { constructor(entity, jwtService) { this.entity = entity; this.jwtService = jwtService; } async login(model) { const user = await this.entity.getRepository(entity_1.TaiKhoan).findOne({ where: { maTaiKhoan: model.username }, select: [ 'taiKhoanId', 'maTaiKhoan', 'matKhau', 'tenHienThi', 'loaiTaiKhoan', 'email', 'hoatDong', 'dangNhapThatBai', 'donVi' ], relations: ['donVi'] }); if (!user) throw new common_1.BadRequestException("Tài khoản không tồn tại"); if (await user.comparePasword(model.password)) { const token = await this.jwtService.signAsync({ user: user.maTaiKhoan, uid: user.taiKhoanId }); const menu = await this.getMenu(user.taiKhoanId); delete user.taiKhoanId; delete user.matKhau; return { token, user, menu }; } throw new common_1.BadRequestException("Mật khẩu không chính xác"); } async getMenu(taiKhoanId) { const chucNangs = await this.entity.createQueryBuilder(entity_1.TaiKhoanQuyen, 'quyens') .select([ "chucnang.ID as id", "chucnang.Url as url", "chucnang.Icon as icon", "chucnang.TenChucNang as name", "'chuc-nang' as loai", "CAST(1 as bit) as coChucNang" ]) .addSelect("chucnang.ID_NhomChucNang", "parentId") .innerJoin(entity_1.ChucNang, "chucnang", "chucnang.ID = quyens.ChucNang_ID") .where("chucnang.isHidden = :hidden", { hidden: false }).andWhere("quyens.TaiKhoan_ID = :taiKhoanId", { taiKhoanId }) .orderBy("chucnang.STT").getRawMany(); const nhomChucNang = await this.entity.getRepository("SYS_NhomChucNang").createQueryBuilder() .select(["id", "TenNhom as name", "icon", "stt", "parentId", "null as url", "'nhom-chuc-nang' as loai"]) .addSelect("CAST(0 as bit) as coChucNang").execute(); const full = [...chucNangs, ...nhomChucNang]; return this.buildMenu(full).filter(f => f.coChucNang); } buildMenu(full, parent = null) { const list = full.filter(f => f.parentId == parent).sort((a, b) => a.stt - b.stt); list.forEach((n, i, a) => { const children = this.buildMenu(full, n.id); if (!!children.length) { a[i].coChucNang = true; a[i].children = children; } }); return list; } }; LoginService = __decorate([ (0, common_1.Injectable)(), __param(0, (0, typeorm_1.InjectEntityManager)()), __metadata("design:paramtypes", [typeorm_2.EntityManager, jwt_1.JwtService]) ], LoginService); exports.LoginService = LoginService;