fix and update
This commit is contained in:
@@ -3,6 +3,7 @@ import * as bcrypt from 'bcryptjs';
|
||||
import { UserStatus } from '../generated/prisma/client';
|
||||
import { PrismaService } from '../infra/prisma.service';
|
||||
import { AccessService } from './access.service';
|
||||
import { DEFAULT_VERIFICATION_ICON, isAllowedVerificationIcon, VERIFICATION_ICONS } from './verification.constants';
|
||||
|
||||
@Injectable()
|
||||
export class AdminService {
|
||||
@@ -92,6 +93,43 @@ export class AdminService {
|
||||
return this.toAdminUser(user);
|
||||
}
|
||||
|
||||
async setUserVerification(actorUserId: string, userId: string, data: { isVerified: boolean; verificationIcon?: string }) {
|
||||
await this.access.assertCanVerifyUsers(actorUserId);
|
||||
await this.ensureUserExists(userId);
|
||||
|
||||
if (data.isVerified) {
|
||||
const icon = data.verificationIcon ?? DEFAULT_VERIFICATION_ICON;
|
||||
if (!isAllowedVerificationIcon(icon)) {
|
||||
throw new BadRequestException('Выберите значок верификации из списка');
|
||||
}
|
||||
const user = await this.prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: {
|
||||
isVerified: true,
|
||||
verificationIcon: icon,
|
||||
verifiedAt: new Date()
|
||||
},
|
||||
include: { userRoles: { include: { role: true } }, userPermissions: { include: { permission: true } } }
|
||||
});
|
||||
return this.toAdminUser(user);
|
||||
}
|
||||
|
||||
const user = await this.prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: {
|
||||
isVerified: false,
|
||||
verificationIcon: null,
|
||||
verifiedAt: null
|
||||
},
|
||||
include: { userRoles: { include: { role: true } }, userPermissions: { include: { permission: true } } }
|
||||
});
|
||||
return this.toAdminUser(user);
|
||||
}
|
||||
|
||||
listVerificationIcons() {
|
||||
return { icons: VERIFICATION_ICONS.map((icon) => ({ slug: icon.slug, name: icon.name })) };
|
||||
}
|
||||
|
||||
async deleteUser(userId: string) {
|
||||
await this.ensureUserExists(userId);
|
||||
const user = await this.prisma.user.update({
|
||||
@@ -111,6 +149,8 @@ export class AdminService {
|
||||
displayName: string;
|
||||
username: string | null;
|
||||
isSuperAdmin: boolean;
|
||||
isVerified: boolean;
|
||||
verificationIcon: string | null;
|
||||
status: UserStatus;
|
||||
createdAt: Date;
|
||||
userRoles?: { role: { slug: string } }[];
|
||||
@@ -125,6 +165,8 @@ export class AdminService {
|
||||
displayName: user.displayName,
|
||||
username: user.username ?? undefined,
|
||||
isSuperAdmin: user.isSuperAdmin,
|
||||
isVerified: user.isVerified,
|
||||
verificationIcon: user.isVerified ? (user.verificationIcon ?? DEFAULT_VERIFICATION_ICON) : undefined,
|
||||
status: user.status,
|
||||
createdAt: user.createdAt.toISOString(),
|
||||
roles: user.userRoles?.map((link) => link.role.slug) ?? [],
|
||||
|
||||
Reference in New Issue
Block a user