mirror of
https://github.com/vastxie/99AI.git
synced 2025-11-10 18:53:46 +08:00
v4.1.0
This commit is contained in:
52
AIWebQuickDeploy/dist/modules/user/dto/queryAllUser.dto.js
vendored
Normal file
52
AIWebQuickDeploy/dist/modules/user/dto/queryAllUser.dto.js
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
"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);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.QueryAllUserDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QueryAllUserDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryAllUserDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryAllUserDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '小九', description: '用户姓名', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QueryAllUserDto.prototype, "username", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'J_longyan@163.com', description: '用户邮箱', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QueryAllUserDto.prototype, "email", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '18888888888', description: '用户手机号码', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QueryAllUserDto.prototype, "phone", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 2, description: '用户状态', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryAllUserDto.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'super', description: '关键字查询', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QueryAllUserDto.prototype, "keyword", void 0);
|
||||
exports.QueryAllUserDto = QueryAllUserDto;
|
||||
27
AIWebQuickDeploy/dist/modules/user/dto/queryInviteRecord.dto.js
vendored
Normal file
27
AIWebQuickDeploy/dist/modules/user/dto/queryInviteRecord.dto.js
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
"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);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.queryInviteRecordDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class queryInviteRecordDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], queryInviteRecordDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], queryInviteRecordDto.prototype, "size", void 0);
|
||||
exports.queryInviteRecordDto = queryInviteRecordDto;
|
||||
22
AIWebQuickDeploy/dist/modules/user/dto/queryOne.dto.js
vendored
Normal file
22
AIWebQuickDeploy/dist/modules/user/dto/queryOne.dto.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"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);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.QueryOneUserDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QueryOneUserDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, nullable: true, description: '查询用户的id', required: false }),
|
||||
(0, class_validator_1.IsDefined)({ message: '用户id是必传参数' }),
|
||||
__metadata("design:type", Number)
|
||||
], QueryOneUserDto.prototype, "id", void 0);
|
||||
exports.QueryOneUserDto = QueryOneUserDto;
|
||||
22
AIWebQuickDeploy/dist/modules/user/dto/resetUserPass.dto.js
vendored
Normal file
22
AIWebQuickDeploy/dist/modules/user/dto/resetUserPass.dto.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"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);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ResetUserPassDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class ResetUserPassDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, nullable: true, description: '用户id', required: false }),
|
||||
(0, class_validator_1.IsDefined)({ message: '用户id是必传参数' }),
|
||||
__metadata("design:type", Number)
|
||||
], ResetUserPassDto.prototype, "id", void 0);
|
||||
exports.ResetUserPassDto = ResetUserPassDto;
|
||||
28
AIWebQuickDeploy/dist/modules/user/dto/retrieve.dto.js
vendored
Normal file
28
AIWebQuickDeploy/dist/modules/user/dto/retrieve.dto.js
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"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);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RetrieveUserDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class RetrieveUserDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 100, nullable: true, description: '查询用户的id', required: false }),
|
||||
__metadata("design:type", Number)
|
||||
], RetrieveUserDto.prototype, "id", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'sfas12', nullable: true, description: 'TODO待完善', required: false }),
|
||||
__metadata("design:type", String)
|
||||
], RetrieveUserDto.prototype, "secret", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 100, nullable: true, description: 'TODO待完善', required: false }),
|
||||
__metadata("design:type", Number)
|
||||
], RetrieveUserDto.prototype, "moreId", void 0);
|
||||
exports.RetrieveUserDto = RetrieveUserDto;
|
||||
41
AIWebQuickDeploy/dist/modules/user/dto/updateUser.dto.js
vendored
Normal file
41
AIWebQuickDeploy/dist/modules/user/dto/updateUser.dto.js
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
"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);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UpdateUserDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class UpdateUserDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'cooper', nullable: true, description: '用户名称', required: false }),
|
||||
(0, class_validator_1.MinLength)(2, { message: '用户名最低需要大于2位数!' }),
|
||||
(0, class_validator_1.MaxLength)(12, { message: '用户名不得超过12位!' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户名不能为空!' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateUserDto.prototype, "username", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '', description: '用户头像', required: false }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户头像不能为空!' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateUserDto.prototype, "avatar", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '我是一台基于深度学习和自然语言处理技术的 AI 机器人,旨在为用户提供高效、精准、个性化的智能服务。',
|
||||
description: '用户签名',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户签名不能为空!' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateUserDto.prototype, "sign", void 0);
|
||||
exports.UpdateUserDto = UpdateUserDto;
|
||||
29
AIWebQuickDeploy/dist/modules/user/dto/updateUserStatus.dto.js
vendored
Normal file
29
AIWebQuickDeploy/dist/modules/user/dto/updateUserStatus.dto.js
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"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);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UpdateUserStatusDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class UpdateUserStatusDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 2, description: '用户状态', required: false }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户状态不能为空!' }),
|
||||
(0, class_validator_1.IsDefined)({ message: '用户状态是必传参数' }),
|
||||
(0, class_validator_1.IsIn)([0, 1, 2, 3], { message: '非法参数、用户状态非法!' }),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateUserStatusDto.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '修改的用户id', required: false }),
|
||||
(0, class_validator_1.IsDefined)({ message: '用户id是必传参数' }),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateUserStatusDto.prototype, "id", void 0);
|
||||
exports.UpdateUserStatusDto = UpdateUserStatusDto;
|
||||
37
AIWebQuickDeploy/dist/modules/user/dto/userRecharge.dto.js
vendored
Normal file
37
AIWebQuickDeploy/dist/modules/user/dto/userRecharge.dto.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"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);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UserRechargeDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class UserRechargeDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '用户id', required: true }),
|
||||
(0, class_validator_1.IsDefined)({ message: '用户id是必传参数' }),
|
||||
__metadata("design:type", Number)
|
||||
], UserRechargeDto.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 100, description: '用户对话模型3次数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UserRechargeDto.prototype, "model3Count", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 5, description: '用户对话模型4次数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UserRechargeDto.prototype, "model4Count", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 0, description: '用户MJ额度', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UserRechargeDto.prototype, "drawMjCount", void 0);
|
||||
exports.UserRechargeDto = UserRechargeDto;
|
||||
118
AIWebQuickDeploy/dist/modules/user/user.controller.js
vendored
Normal file
118
AIWebQuickDeploy/dist/modules/user/user.controller.js
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
"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.UserController = void 0;
|
||||
const adminAuth_guard_1 = require("../../common/auth/adminAuth.guard");
|
||||
const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
|
||||
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const queryAllUser_dto_1 = require("./dto/queryAllUser.dto");
|
||||
const queryOne_dto_1 = require("./dto/queryOne.dto");
|
||||
const resetUserPass_dto_1 = require("./dto/resetUserPass.dto");
|
||||
const updateUser_dto_1 = require("./dto/updateUser.dto");
|
||||
const updateUserStatus_dto_1 = require("./dto/updateUserStatus.dto");
|
||||
const userRecharge_dto_1 = require("./dto/userRecharge.dto");
|
||||
const user_service_1 = require("./user.service");
|
||||
let UserController = class UserController {
|
||||
constructor(userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
async update(body, req) {
|
||||
return await this.userService.updateInfo(body, req);
|
||||
}
|
||||
async userRecharge(body) {
|
||||
return await this.userService.userRecharge(body);
|
||||
}
|
||||
async queryAll(query, req) {
|
||||
return await this.userService.queryAll(query, req);
|
||||
}
|
||||
async queryOne(params) {
|
||||
return await this.userService.queryOne(params);
|
||||
}
|
||||
async updateStatus(body) {
|
||||
return await this.userService.updateStatus(body);
|
||||
}
|
||||
async resetUserPass(body) {
|
||||
return await this.userService.resetUserPass(body);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Post)('update'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '更新用户信息' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [updateUser_dto_1.UpdateUserDto, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "update", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('recharge'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户充值' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [userRecharge_dto_1.UserRechargeDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "userRecharge", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryAll'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询所有用户' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [queryAllUser_dto_1.QueryAllUserDto, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "queryAll", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryOne'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询单个用户' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [queryOne_dto_1.QueryOneUserDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "queryOne", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('updateStatus'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '更新用户状态' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [updateUserStatus_dto_1.UpdateUserStatusDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "updateStatus", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('resetUserPass'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '重置用户密码' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [resetUserPass_dto_1.ResetUserPassDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "resetUserPass", null);
|
||||
UserController = __decorate([
|
||||
(0, common_1.Controller)('user'),
|
||||
(0, swagger_1.ApiTags)('user'),
|
||||
__metadata("design:paramtypes", [user_service_1.UserService])
|
||||
], UserController);
|
||||
exports.UserController = UserController;
|
||||
115
AIWebQuickDeploy/dist/modules/user/user.entity.js
vendored
Normal file
115
AIWebQuickDeploy/dist/modules/user/user.entity.js
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
"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);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UserEntity = void 0;
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let UserEntity = class UserEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ length: 12, comment: '用户昵称' }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "username", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ length: 64, comment: '用户密码', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "password", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: 0, comment: '用户状态' }),
|
||||
__metadata("design:type", Number)
|
||||
], UserEntity.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: 1, comment: '用户性别' }),
|
||||
__metadata("design:type", Number)
|
||||
], UserEntity.prototype, "sex", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ length: 64, unique: true, comment: '用户邮箱' }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "email", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ length: 64, nullable: true, comment: '用户手机号' }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "phone", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({
|
||||
length: 300,
|
||||
nullable: true,
|
||||
default: '',
|
||||
comment: '用户头像',
|
||||
}),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "avatar", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({
|
||||
length: 300,
|
||||
nullable: true,
|
||||
default: '我是一台基于深度学习和自然语言处理技术的 AI 机器人,旨在为用户提供高效、精准、个性化的智能服务。',
|
||||
comment: '用户签名',
|
||||
}),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "sign", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ length: 64, default: '', comment: '注册IP', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "registerIp", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({
|
||||
length: 64,
|
||||
default: '',
|
||||
comment: '最后一次登录IP',
|
||||
nullable: true,
|
||||
}),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "lastLoginIp", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ length: 10, default: '', comment: '用户邀请码' }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "inviteCode", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ length: 10, default: '', comment: '用户填写的别人的邀请码' }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "invitedBy", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ length: 10, default: 'viewer', comment: '用户角色' }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "role", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ length: 64, default: '', comment: '微信openId', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "openId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ length: 64, comment: '用户注册来源', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "client", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '用户邀请链接被点击次数', default: 0 }),
|
||||
__metadata("design:type", Number)
|
||||
], UserEntity.prototype, "inviteLinkCount", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '用户连续签到天数', default: 0 }),
|
||||
__metadata("design:type", Number)
|
||||
], UserEntity.prototype, "consecutiveDays", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '用户违规记录次数', default: 0 }),
|
||||
__metadata("design:type", Number)
|
||||
], UserEntity.prototype, "violationCount", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '真实姓名', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "realName", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '身份证号', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "idCard", void 0);
|
||||
UserEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'users' })
|
||||
], UserEntity);
|
||||
exports.UserEntity = UserEntity;
|
||||
58
AIWebQuickDeploy/dist/modules/user/user.module.js
vendored
Normal file
58
AIWebQuickDeploy/dist/modules/user/user.module.js
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
"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;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UserModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const chatGroup_entity_1 = require("../chatGroup/chatGroup.entity");
|
||||
const chatLog_entity_1 = require("../chatLog/chatLog.entity");
|
||||
const cramiPackage_entity_1 = require("../crami/cramiPackage.entity");
|
||||
const config_entity_1 = require("../globalConfig/config.entity");
|
||||
const mailer_service_1 = require("../mailer/mailer.service");
|
||||
const redisCache_service_1 = require("../redisCache/redisCache.service");
|
||||
const accountLog_entity_1 = require("../userBalance/accountLog.entity");
|
||||
const balance_entity_1 = require("../userBalance/balance.entity");
|
||||
const fingerprint_entity_1 = require("../userBalance/fingerprint.entity");
|
||||
const userBalance_entity_1 = require("../userBalance/userBalance.entity");
|
||||
const userBalance_service_1 = require("../userBalance/userBalance.service");
|
||||
const verification_service_1 = require("./../verification/verification.service");
|
||||
const verifycation_entity_1 = require("./../verification/verifycation.entity");
|
||||
const user_controller_1 = require("./user.controller");
|
||||
const user_entity_1 = require("./user.entity");
|
||||
const user_service_1 = require("./user.service");
|
||||
let UserModule = class UserModule {
|
||||
};
|
||||
UserModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [
|
||||
typeorm_1.TypeOrmModule.forFeature([
|
||||
user_entity_1.UserEntity,
|
||||
verifycation_entity_1.VerifycationEntity,
|
||||
balance_entity_1.BalanceEntity,
|
||||
accountLog_entity_1.AccountLogEntity,
|
||||
config_entity_1.ConfigEntity,
|
||||
cramiPackage_entity_1.CramiPackageEntity,
|
||||
userBalance_entity_1.UserBalanceEntity,
|
||||
fingerprint_entity_1.FingerprintLogEntity,
|
||||
chatLog_entity_1.ChatLogEntity,
|
||||
chatGroup_entity_1.ChatGroupEntity,
|
||||
]),
|
||||
],
|
||||
controllers: [user_controller_1.UserController],
|
||||
providers: [
|
||||
user_service_1.UserService,
|
||||
verification_service_1.VerificationService,
|
||||
userBalance_service_1.UserBalanceService,
|
||||
redisCache_service_1.RedisCacheService,
|
||||
mailer_service_1.MailerService,
|
||||
],
|
||||
exports: [user_service_1.UserService],
|
||||
})
|
||||
], UserModule);
|
||||
exports.UserModule = UserModule;
|
||||
523
AIWebQuickDeploy/dist/modules/user/user.service.js
vendored
Normal file
523
AIWebQuickDeploy/dist/modules/user/user.service.js
vendored
Normal file
@@ -0,0 +1,523 @@
|
||||
"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 balance_constant_1 = require("../../common/constants/balance.constant");
|
||||
const verification_constant_1 = require("../../common/constants/verification.constant");
|
||||
const utils_1 = require("../../common/utils");
|
||||
const mailer_service_1 = require("../mailer/mailer.service");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const bcrypt = require("bcryptjs");
|
||||
const _ = require("lodash");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const config_entity_1 = require("../globalConfig/config.entity");
|
||||
const userBalance_service_1 = require("../userBalance/userBalance.service");
|
||||
const user_constant_1 = require("./../../common/constants/user.constant");
|
||||
const globalConfig_service_1 = require("./../globalConfig/globalConfig.service");
|
||||
const verification_service_1 = require("./../verification/verification.service");
|
||||
const user_entity_1 = require("./user.entity");
|
||||
let UserService = class UserService {
|
||||
constructor(userEntity, connection, verificationService, mailerService, userBalanceService, globalConfigService, configEntity) {
|
||||
this.userEntity = userEntity;
|
||||
this.connection = connection;
|
||||
this.verificationService = verificationService;
|
||||
this.mailerService = mailerService;
|
||||
this.userBalanceService = userBalanceService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.configEntity = configEntity;
|
||||
}
|
||||
async createUserAndVerifycation(user, req) {
|
||||
const { username, email, password, client = 0 } = user;
|
||||
const where = [{ username }, { email }];
|
||||
const u = await this.userEntity.findOne({ where: where });
|
||||
if (u && u.status !== user_constant_1.UserStatusEnum.PENDING) {
|
||||
throw new common_1.HttpException('用户名或者邮箱已被注册!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
try {
|
||||
const userInput = _.cloneDeep(user);
|
||||
const hashedPassword = bcrypt.hashSync(password, 10);
|
||||
const ip = (0, utils_1.getClientIp)(req);
|
||||
userInput.password = hashedPassword;
|
||||
userInput.registerIp = ip;
|
||||
userInput.client = client;
|
||||
let n;
|
||||
if (!u) {
|
||||
const userDefautlAvatar = await this.globalConfigService.getConfigs([
|
||||
'userDefautlAvatar',
|
||||
]);
|
||||
userInput.avatar = userDefautlAvatar;
|
||||
n = await this.userEntity.save(userInput);
|
||||
}
|
||||
else {
|
||||
n = u;
|
||||
}
|
||||
const emailConfigs = await this.configEntity.find({
|
||||
where: {
|
||||
configKey: (0, typeorm_2.In)([
|
||||
'isVerifyEmail',
|
||||
'registerBaseUrl',
|
||||
'registerVerifyEmailTitle',
|
||||
'registerVerifyEmailDesc',
|
||||
'registerVerifyEmailFrom',
|
||||
'registerVerifyExpir',
|
||||
]),
|
||||
},
|
||||
});
|
||||
const configMap = emailConfigs.reduce((pre, cur) => {
|
||||
pre[cur.configKey] = cur.configVal;
|
||||
return pre;
|
||||
}, {});
|
||||
const isVerifyEmail = configMap['isVerifyEmail']
|
||||
? Number(configMap['isVerifyEmail'])
|
||||
: 1;
|
||||
if (isVerifyEmail) {
|
||||
const expir = configMap['registerVerifyExpir']
|
||||
? Number(configMap['registerVerifyExpir'])
|
||||
: 30 * 60;
|
||||
const v = await this.verificationService.createVerification(n, verification_constant_1.VerificationEnum.Registration, expir);
|
||||
const { code, email, id } = v;
|
||||
const { registerVerifyEmailFrom } = configMap;
|
||||
console.log('configMap: ', configMap);
|
||||
console.log(`尝试发送邮件到: ${email}`);
|
||||
}
|
||||
else {
|
||||
const { id } = n;
|
||||
await this.updateUserStatus(id, user_constant_1.UserStatusEnum.ACTIVE);
|
||||
await this.userBalanceService.addBalanceToNewUser(id);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
catch (error) {
|
||||
console.log('error: ', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
async getSuper() {
|
||||
const user = await this.userEntity.findOne({ where: { role: 'super' } });
|
||||
return user;
|
||||
}
|
||||
async verifyUserCredentials(user) {
|
||||
const { username, password, uid = 0, phone } = user;
|
||||
let u = null;
|
||||
if (uid > 0) {
|
||||
u = await this.userEntity.findOne({ where: { id: uid } });
|
||||
if (!u) {
|
||||
throw new common_1.HttpException('当前账户不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (!bcrypt.compareSync(password, u.password)) {
|
||||
throw new common_1.HttpException('当前密码错误!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
if (username && password) {
|
||||
const where = [
|
||||
{ username },
|
||||
{ email: username },
|
||||
{ phone: username },
|
||||
];
|
||||
u = await this.userEntity.findOne({ where: where });
|
||||
if (!u) {
|
||||
throw new common_1.HttpException('当前账户不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (!bcrypt.compareSync(password, u.password)) {
|
||||
throw new common_1.HttpException('当前密码错误!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
if (!u) {
|
||||
throw new common_1.HttpException('当前账户不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (u.status !== user_constant_1.UserStatusEnum.ACTIVE) {
|
||||
throw new common_1.HttpException(user_constant_1.UserStatusErrMsg[u.status], common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return u;
|
||||
}
|
||||
async verifyUserPassword(userId, password) {
|
||||
const u = await this.userEntity.findOne({ where: { id: userId } });
|
||||
return bcrypt.compareSync(password, u.password);
|
||||
}
|
||||
async updateUserStatus(id, status) {
|
||||
const u = await this.userEntity.update({ id }, { status });
|
||||
return u.affected > 0;
|
||||
}
|
||||
async getUserStatus(id) {
|
||||
const u = await this.userEntity.findOne({ where: { id } });
|
||||
return u.status;
|
||||
}
|
||||
async queryUserInfoById(id) {
|
||||
return await this.userEntity.findOne({ where: { id } });
|
||||
}
|
||||
async queryOneUserInfo(userId) {
|
||||
return await this.userEntity.findOne({ where: { id: userId } });
|
||||
}
|
||||
async checkUserStatus(user) {
|
||||
const { id: userId, role } = user;
|
||||
if (role === 'visitor')
|
||||
return true;
|
||||
const u = await this.userEntity.findOne({ where: { id: userId } });
|
||||
if (!u) {
|
||||
throw new common_1.HttpException('当前用户信息失效、请重新登录!', common_1.HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
if (u.status === user_constant_1.UserStatusEnum.BLACKLISTED) {
|
||||
throw new common_1.HttpException('您的账户已被永久加入黑名单、如有疑问、请联系管理员!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (u.status === user_constant_1.UserStatusEnum.LOCKED) {
|
||||
throw new common_1.HttpException('您的账户已被封禁、如有疑问、请联系管理员!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async getUserInfo(userId) {
|
||||
const userInfo = await this.userEntity.findOne({
|
||||
where: { id: userId },
|
||||
select: [
|
||||
'username',
|
||||
'avatar',
|
||||
'role',
|
||||
'email',
|
||||
'sign',
|
||||
'openId',
|
||||
'consecutiveDays',
|
||||
],
|
||||
});
|
||||
if (!userInfo) {
|
||||
throw new common_1.HttpException('当前用户信息失效、请重新登录!', common_1.HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
userInfo.isBindWx = !!(userInfo === null || userInfo === void 0 ? void 0 : userInfo.openId);
|
||||
delete userInfo.openId;
|
||||
const userBalance = await this.userBalanceService.queryUserBalance(userId);
|
||||
const processedId = (userId * 123 + 100000000)
|
||||
.toString(36)
|
||||
.toUpperCase()
|
||||
.slice(-6);
|
||||
userInfo.id = processedId;
|
||||
return { userInfo, userBalance: Object.assign({}, userBalance) };
|
||||
}
|
||||
async getUserById(id) {
|
||||
return await this.userEntity.findOne({ where: { id } });
|
||||
}
|
||||
async getUserOpenId(openId) {
|
||||
return await this.userEntity.findOne({ where: { openId } });
|
||||
}
|
||||
async updateInfo(body, req) {
|
||||
const { id } = req.user;
|
||||
const u = await this.userEntity.findOne({ where: { id } });
|
||||
if (!u) {
|
||||
throw new common_1.HttpException('当前用户不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (body.username && u.username === body.username) {
|
||||
throw new common_1.HttpException('没有变更,无需更改!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (body.username) {
|
||||
const usernameTaken = await this.isUsernameTaken(body.username, id);
|
||||
if (usernameTaken) {
|
||||
throw new common_1.HttpException('用户名已存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
const r = await this.userEntity.update({ id }, body);
|
||||
if (r.affected <= 0) {
|
||||
throw new common_1.HttpException('修改用户信息失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return '修改用户信息成功!';
|
||||
}
|
||||
async isUsernameTaken(username, excludeUserId) {
|
||||
const where = { username };
|
||||
if (excludeUserId) {
|
||||
where.id = (0, typeorm_2.Not)(excludeUserId);
|
||||
}
|
||||
const user = await this.userEntity.findOne({ where });
|
||||
return !!user;
|
||||
}
|
||||
async updateUserPassword(userId, password) {
|
||||
const hashedPassword = bcrypt.hashSync(password, 10);
|
||||
const r = await this.userEntity.update({ id: userId }, { password: hashedPassword });
|
||||
if (r.affected <= 0) {
|
||||
throw new common_1.HttpException('修改密码失败、请重新试试吧。', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async userRecharge(body) {
|
||||
const { userId, model3Count = 0, model4Count = 0, drawMjCount = 0 } = body;
|
||||
await this.userBalanceService.addBalanceToUser(userId, {
|
||||
model3Count,
|
||||
model4Count,
|
||||
drawMjCount,
|
||||
});
|
||||
const res = await this.userBalanceService.saveRecordRechargeLog({
|
||||
userId,
|
||||
rechargeType: balance_constant_1.RechargeType.ADMIN_GIFT,
|
||||
model3Count,
|
||||
model4Count,
|
||||
drawMjCount,
|
||||
extent: '',
|
||||
});
|
||||
return res;
|
||||
}
|
||||
async queryAll(query, req) {
|
||||
const { page = 1, size = 10, username, email, status, keyword, phone, } = query;
|
||||
let where = {};
|
||||
username && Object.assign(where, { username: (0, typeorm_2.Like)(`%${username}%`) });
|
||||
email && Object.assign(where, { email: (0, typeorm_2.Like)(`%${email}%`) });
|
||||
phone && Object.assign(where, { phone: (0, typeorm_2.Like)(`%${phone}%`) });
|
||||
status && Object.assign(where, { status });
|
||||
if (keyword) {
|
||||
where = [
|
||||
{ username: (0, typeorm_2.Like)(`%${keyword}%`) },
|
||||
{ email: (0, typeorm_2.Like)(`%${keyword}%`) },
|
||||
{ phone: (0, typeorm_2.Like)(`%${keyword}%`) },
|
||||
];
|
||||
}
|
||||
const [rows, count] = await this.userEntity.findAndCount({
|
||||
skip: (page - 1) * size,
|
||||
where,
|
||||
take: size,
|
||||
order: { createdAt: 'DESC' },
|
||||
cache: true,
|
||||
select: [
|
||||
'username',
|
||||
'avatar',
|
||||
'role',
|
||||
'sign',
|
||||
'status',
|
||||
'id',
|
||||
'email',
|
||||
'createdAt',
|
||||
'lastLoginIp',
|
||||
'phone',
|
||||
'realName',
|
||||
'idCard',
|
||||
],
|
||||
});
|
||||
const ids = rows.map((t) => t.id);
|
||||
const data = await this.userBalanceService.queryUserBalanceByIds(ids);
|
||||
rows.forEach((user) => (user.balanceInfo = data.find((t) => t.userId === user.id)));
|
||||
req.user.role !== 'super' &&
|
||||
rows.forEach((t) => (t.email = (0, utils_1.maskEmail)(t.email)));
|
||||
req.user.role !== 'super' &&
|
||||
rows.forEach((t) => (t.lastLoginIp = (0, utils_1.maskIpAddress)(t.lastLoginIp)));
|
||||
req.user.role !== 'super' &&
|
||||
rows.forEach((t) => (t.phone = (0, utils_1.maskIpAddress)(t.phone)));
|
||||
return { rows, count };
|
||||
}
|
||||
async queryOne({ id }) {
|
||||
return await this.userEntity.findOne({
|
||||
where: { id },
|
||||
select: ['username', 'avatar', 'role', 'sign', 'status'],
|
||||
});
|
||||
}
|
||||
async updateStatus(body) {
|
||||
const { id, status } = body;
|
||||
const n = await this.userEntity.findOne({ where: { id } });
|
||||
if (!n) {
|
||||
throw new common_1.HttpException('用户不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (n.role === 'super') {
|
||||
throw new common_1.HttpException('超级管理员不可被操作!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (n.role === 'super') {
|
||||
throw new common_1.HttpException('超级管理员不可被操作!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const r = await this.userEntity.update({ id }, { status });
|
||||
if (r.affected <= 0) {
|
||||
throw new common_1.HttpException('修改用户状态失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return '修改用户状态成功!';
|
||||
}
|
||||
async resetUserPass(body) {
|
||||
const { id } = body;
|
||||
const u = await this.userEntity.findOne({ where: { id } });
|
||||
if (!u) {
|
||||
throw new common_1.HttpException('用户不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const defaultPassword = '123456';
|
||||
const hashPassword = bcrypt.hashSync(defaultPassword, 10);
|
||||
const raw = await this.userEntity.update({ id }, { password: hashPassword });
|
||||
if (raw.affected <= 0) {
|
||||
throw new common_1.HttpException('重置密码失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return `密码重置为[${defaultPassword}]成功!`;
|
||||
}
|
||||
async savaLoginIp(userId, ip) {
|
||||
return await this.userEntity.update({ id: userId }, { lastLoginIp: ip });
|
||||
}
|
||||
async getUserFromOpenId(openId, sceneStr) {
|
||||
const user = await this.userEntity.findOne({ where: { openId } });
|
||||
if (!user) {
|
||||
const user = await this.createUserFromOpenId(openId);
|
||||
await this.userBalanceService.addBalanceToNewUser(user.id);
|
||||
return user;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
async createUserFromOpenId(openId) {
|
||||
const userDefautlAvatar = await this.globalConfigService.getConfigs([
|
||||
'userDefautlAvatar',
|
||||
]);
|
||||
const userInfo = {
|
||||
avatar: userDefautlAvatar,
|
||||
username: `用户${(0, utils_1.createRandomUid)()}`,
|
||||
status: user_constant_1.UserStatusEnum.ACTIVE,
|
||||
sex: 0,
|
||||
email: `${(0, utils_1.createRandomUid)()}@default.com`,
|
||||
openId,
|
||||
};
|
||||
const user = await this.userEntity.save(userInfo);
|
||||
return user;
|
||||
}
|
||||
async createUserFromContact(params) {
|
||||
const { username, email, phone } = params;
|
||||
const userDefautlAvatar = await this.globalConfigService.getConfigs([
|
||||
'userDefautlAvatar',
|
||||
]);
|
||||
const userInfo = {
|
||||
avatar: userDefautlAvatar,
|
||||
username: `用户${(0, utils_1.createRandomUid)()}`,
|
||||
status: user_constant_1.UserStatusEnum.ACTIVE,
|
||||
sex: 0,
|
||||
};
|
||||
if (username) {
|
||||
userInfo.username = username;
|
||||
}
|
||||
if (email) {
|
||||
userInfo.email = email;
|
||||
}
|
||||
if (phone) {
|
||||
userInfo.phone = phone;
|
||||
}
|
||||
const user = await this.userEntity.save(userInfo);
|
||||
return user;
|
||||
}
|
||||
async getUserByContact(params) {
|
||||
const { username, email, phone } = params;
|
||||
const where = [];
|
||||
if (username) {
|
||||
where.push({ username });
|
||||
}
|
||||
if (email) {
|
||||
where.push({ email });
|
||||
}
|
||||
if (phone) {
|
||||
where.push({ phone });
|
||||
}
|
||||
return await this.userEntity.findOne({ where });
|
||||
}
|
||||
async bindWx(openId, userId) {
|
||||
try {
|
||||
const user = await this.userEntity.findOne({ where: { id: userId } });
|
||||
if (!user)
|
||||
return { status: false, msg: '当前绑定用户不存在!' };
|
||||
const bindU = await this.userEntity.findOne({ where: { openId } });
|
||||
if (bindU)
|
||||
return { status: false, msg: '该微信已绑定其他账号!' };
|
||||
const res = await this.userEntity.update({ id: userId }, { openId });
|
||||
if (res.affected <= 0)
|
||||
return { status: false, msg: '绑定微信失败、请联系管理员!' };
|
||||
return { status: true, msg: '恭喜您绑定成功、后续可直接扫码登录了!' };
|
||||
}
|
||||
catch (error) {
|
||||
return { status: false, msg: '绑定微信失败、请联系管理员!' };
|
||||
}
|
||||
}
|
||||
async getOpenIdByUserId(userId) {
|
||||
const user = await this.userEntity.findOne({ where: { id: userId } });
|
||||
return user === null || user === void 0 ? void 0 : user.openId;
|
||||
}
|
||||
async verifyUserRegister(params) {
|
||||
const { username, phone, email } = params;
|
||||
if (phone) {
|
||||
const userByPhone = await this.userEntity.findOne({ where: { phone } });
|
||||
if (userByPhone) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (email) {
|
||||
const userByEmail = await this.userEntity.findOne({ where: { email } });
|
||||
if (userByEmail) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (username) {
|
||||
const userByUsername = await this.userEntity.findOne({
|
||||
where: { username },
|
||||
});
|
||||
if (userByUsername) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!phone && !email && !username) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
async verifyUserRegisterByPhone(params) {
|
||||
const { username, password, phone, phoneCode } = params;
|
||||
const user = await this.userEntity.findOne({
|
||||
where: [{ username }, { phone }],
|
||||
});
|
||||
if (user && user.username === username) {
|
||||
throw new common_1.HttpException('用户名已存在、请更换用户名!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (user && user.phone === phone) {
|
||||
throw new common_1.HttpException('当前手机号已注册、请勿重复注册!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async verifyUserRegisterByEmail(params) {
|
||||
const { username, email } = params;
|
||||
console.log(`校验邮箱注册: 开始 - 用户名: ${username}, 邮箱: ${email}`);
|
||||
const user = await this.userEntity.findOne({
|
||||
where: [{ username }, { email }],
|
||||
});
|
||||
if (user && user.username === username) {
|
||||
console.error(`校验失败: 用户名 "${username}" 已存在`);
|
||||
throw new common_1.HttpException('用户名已存在、请更换用户名!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (user && user.email === email) {
|
||||
console.error(`校验失败: 邮箱 "${email}" 已被注册`);
|
||||
throw new common_1.HttpException('当前邮箱已注册、请勿重复注册!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
console.log(`校验邮箱注册: 成功 - 用户名: ${username}, 邮箱: ${email} 未被占用`);
|
||||
}
|
||||
async createUser(userInfo) {
|
||||
return await this.userEntity.save(userInfo);
|
||||
}
|
||||
async saveRealNameInfo(userId, realName, idCard) {
|
||||
const user = await this.userEntity.findOne({ where: { id: userId } });
|
||||
if (!user) {
|
||||
common_1.Logger.error('用户不存在');
|
||||
}
|
||||
await this.userEntity.update({ id: userId }, { realName, idCard });
|
||||
return;
|
||||
}
|
||||
async updateUserPhone(userId, phone, username, password) {
|
||||
const user = await this.userEntity.findOne({ where: { id: userId } });
|
||||
const hashedPassword = bcrypt.hashSync(password, 10);
|
||||
if (!user) {
|
||||
common_1.Logger.error('用户不存在');
|
||||
}
|
||||
if (!phone || !username || !hashedPassword) {
|
||||
throw new common_1.HttpException('参数错误!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
await this.userEntity.update({ id: userId }, { phone, username, password: hashedPassword });
|
||||
return;
|
||||
}
|
||||
};
|
||||
UserService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(user_entity_1.UserEntity)),
|
||||
__param(6, (0, typeorm_1.InjectRepository)(config_entity_1.ConfigEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository,
|
||||
typeorm_2.Connection,
|
||||
verification_service_1.VerificationService,
|
||||
mailer_service_1.MailerService,
|
||||
userBalance_service_1.UserBalanceService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
typeorm_2.Repository])
|
||||
], UserService);
|
||||
exports.UserService = UserService;
|
||||
Reference in New Issue
Block a user