109 lines
4.7 KiB
JavaScript
109 lines
4.7 KiB
JavaScript
"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.UserService = void 0;
|
|
const common_1 = require("@nestjs/common");
|
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
const typeorm_2 = require("typeorm");
|
|
const user_model_1 = require("../../../model/user.model");
|
|
const api_1 = require("../../common/api");
|
|
const tls_sig_api_v2_typescript_1 = require("tls-sig-api-v2-typescript");
|
|
const app_env_1 = require("../../../app.env");
|
|
const im_help_1 = require("../../common/util/im_help");
|
|
const user_vo_1 = require("../vo/user.vo");
|
|
const user_verify_model_1 = require("../../../model/user_verify.model");
|
|
const user_log_service_1 = require("../../common/service/user_log.service");
|
|
let UserService = class UserService {
|
|
userModel;
|
|
userVerifyModel;
|
|
userLogService;
|
|
constructor(userModel, userVerifyModel, userLogService) {
|
|
this.userModel = userModel;
|
|
this.userVerifyModel = userVerifyModel;
|
|
this.userLogService = userLogService;
|
|
}
|
|
async changePassword(userId, oldPassword, newPassword) {
|
|
const user = await this.userModel.findOne({
|
|
where: { id: userId },
|
|
select: {
|
|
password: true,
|
|
},
|
|
});
|
|
console.log(user?.password, oldPassword);
|
|
if (!user) {
|
|
return api_1.Api.error('用户不存在');
|
|
}
|
|
if (user.password !== oldPassword) {
|
|
return api_1.Api.error('旧密码错误');
|
|
}
|
|
await this.userModel.update({ id: userId }, { password: newPassword });
|
|
return api_1.Api.successMsg('密码修改成功');
|
|
}
|
|
async getProfile(userId) {
|
|
const user = await this.userModel
|
|
.createQueryBuilder('user')
|
|
.addSelect('user.tradePassword')
|
|
.where('user.id = :id', { id: userId })
|
|
.getOne();
|
|
if (!user) {
|
|
return api_1.Api.error('用户不存在');
|
|
}
|
|
const { tradePassword, ...result } = user;
|
|
const maskedPhone = user.phone
|
|
? user.phone.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2')
|
|
: null;
|
|
return api_1.Api.success({
|
|
...result,
|
|
phone: maskedPhone,
|
|
hasTradePassword: !!tradePassword,
|
|
});
|
|
}
|
|
async im(userId) {
|
|
const user = await this.userModel.findOneByOrFail({
|
|
id: userId,
|
|
});
|
|
const userVerify = await this.userVerifyModel.findOneBy({ userId });
|
|
const uid = userId;
|
|
const api = new tls_sig_api_v2_typescript_1.Api(app_env_1.AppEnv.IM_APP_ID, app_env_1.AppEnv.IM_SECRET_KEY);
|
|
const imUid = app_env_1.AppEnv.IM_USER_ID_PREFIX + uid;
|
|
const expire = 86400 * 180;
|
|
const sign = api.genSig(imUid, expire);
|
|
await im_help_1.IMHelp.updateUserProfile(imUid, user.phone, '');
|
|
const vo = new user_vo_1.ImVo();
|
|
vo.uid = imUid;
|
|
vo.sign = sign;
|
|
vo.isAuth =
|
|
userVerify != null && userVerify.status == user_verify_model_1.VerifyAuditStatus.Approved;
|
|
vo.appId = app_env_1.AppEnv.IM_APP_ID;
|
|
vo.username = user.phone;
|
|
vo.avatar = '';
|
|
vo.prefix = app_env_1.AppEnv.IM_USER_ID_PREFIX;
|
|
vo.enabledCreateGroup = user.enabledCreateGroup == 1;
|
|
return api_1.Api.success(vo);
|
|
}
|
|
async started() {
|
|
await this.userLogService.logStarted();
|
|
return api_1.Api.success();
|
|
}
|
|
};
|
|
exports.UserService = UserService;
|
|
exports.UserService = UserService = __decorate([
|
|
(0, common_1.Injectable)(),
|
|
__param(0, (0, typeorm_1.InjectRepository)(user_model_1.UserModel)),
|
|
__param(1, (0, typeorm_1.InjectRepository)(user_verify_model_1.UserVerifyModel)),
|
|
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
typeorm_2.Repository,
|
|
user_log_service_1.UserLogService])
|
|
], UserService);
|
|
//# sourceMappingURL=user.service.js.map
|