generated from fahricansecer/boilerplate-be
feat: SEO Power Engine backend updates and remove temp media files
Backend Deploy 🚀 / build-and-deploy (push) Has been cancelled
Backend Deploy 🚀 / build-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -142,6 +142,49 @@ export class AuthService {
|
||||
throw new UnauthorizedException('ACCOUNT_DISABLED');
|
||||
}
|
||||
|
||||
// [AUTO-ASSIGN ADMIN ROLE FOR OWNER]
|
||||
if (user.email === 'admin@contentgen.ai') {
|
||||
const hasAdminRole = user.roles.some((ur) => ur.role.name === 'admin');
|
||||
if (!hasAdminRole) {
|
||||
const adminRole = await this.prisma.role.findUnique({ where: { name: 'admin' } });
|
||||
if (adminRole) {
|
||||
await this.prisma.userRole.create({
|
||||
data: { userId: user.id, roleId: adminRole.id }
|
||||
});
|
||||
// Refresh user object
|
||||
const refreshedUser = await this.prisma.user.findUnique({
|
||||
where: { email: dto.email },
|
||||
include: {
|
||||
roles: {
|
||||
include: {
|
||||
role: { include: { permissions: { include: { permission: true } } } }
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (refreshedUser) {
|
||||
// Grant 999999 credits if not granted
|
||||
const existingGrant = await this.prisma.creditTransaction.findFirst({
|
||||
where: { userId: refreshedUser.id, type: 'grant', description: 'Admin başlangıç kredisi — sınırsız' },
|
||||
});
|
||||
if (!existingGrant) {
|
||||
await this.prisma.creditTransaction.create({
|
||||
data: {
|
||||
userId: refreshedUser.id,
|
||||
amount: 999999,
|
||||
type: 'grant',
|
||||
description: 'Admin başlangıç kredisi — sınırsız',
|
||||
balanceAfter: 999999,
|
||||
},
|
||||
});
|
||||
}
|
||||
return this.generateTokens(refreshedUser as unknown as UserWithRoles);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.generateTokens(user as unknown as UserWithRoles);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user