generated from fahricansecer/boilerplate-be
This commit is contained in:
@@ -316,9 +316,68 @@ export class AdminController {
|
||||
await this.prisma.rolePermission.deleteMany({
|
||||
where: { roleId, permissionId },
|
||||
});
|
||||
// Invalidate roles_list because permissions are nested in roles
|
||||
await this.cacheManager.del('roles_list');
|
||||
return createSuccessResponse(null, 'Permission removed from role');
|
||||
}
|
||||
|
||||
// ================== Project Management (Admin) ==================
|
||||
|
||||
@Get('projects')
|
||||
@ApiOperation({ summary: 'Tüm projeleri getir (admin)' })
|
||||
async getAllProjects(
|
||||
@Query() query: { page?: number; limit?: number; status?: string; userId?: string },
|
||||
): Promise<ApiResponse<any>> {
|
||||
const result = await this.adminService.getAllProjects({
|
||||
page: query.page ? Number(query.page) : 1,
|
||||
limit: query.limit ? Number(query.limit) : 20,
|
||||
status: query.status,
|
||||
userId: query.userId,
|
||||
});
|
||||
return createSuccessResponse(result);
|
||||
}
|
||||
|
||||
@Delete('projects/:id')
|
||||
@ApiOperation({ summary: 'Projeyi sil (soft delete)' })
|
||||
async adminDeleteProject(@Param('id') id: string): Promise<ApiResponse<any>> {
|
||||
const result = await this.adminService.adminDeleteProject(id);
|
||||
return createSuccessResponse(result, 'Proje silindi');
|
||||
}
|
||||
|
||||
// ================== Render Job Management (Admin) ==================
|
||||
|
||||
@Get('render-jobs')
|
||||
@ApiOperation({ summary: 'Tüm render jobları getir (admin)' })
|
||||
async getAllRenderJobs(
|
||||
@Query() query: { page?: number; limit?: number; status?: string },
|
||||
): Promise<ApiResponse<any>> {
|
||||
const result = await this.adminService.getAllRenderJobs({
|
||||
page: query.page ? Number(query.page) : 1,
|
||||
limit: query.limit ? Number(query.limit) : 20,
|
||||
status: query.status,
|
||||
});
|
||||
return createSuccessResponse(result);
|
||||
}
|
||||
|
||||
// ================== Ban / Activate User ==================
|
||||
|
||||
@Put('users/:id/ban')
|
||||
@ApiOperation({ summary: 'Kullanıcıyı banla' })
|
||||
async banUser(@Param('id') id: string): Promise<ApiResponse<any>> {
|
||||
const user = await this.adminService.setUserActive(id, false);
|
||||
return createSuccessResponse(
|
||||
plainToInstance(UserResponseDto, user),
|
||||
'Kullanıcı banlandı',
|
||||
);
|
||||
}
|
||||
|
||||
@Put('users/:id/activate')
|
||||
@ApiOperation({ summary: 'Kullanıcıyı aktif et' })
|
||||
async activateUser(@Param('id') id: string): Promise<ApiResponse<any>> {
|
||||
const user = await this.adminService.setUserActive(id, true);
|
||||
return createSuccessResponse(
|
||||
plainToInstance(UserResponseDto, user),
|
||||
'Kullanıcı aktif edildi',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ export class AdminService {
|
||||
storageStats,
|
||||
recentUsers,
|
||||
projectsByStatus,
|
||||
totalRenderJobs,
|
||||
renderJobsByStatus,
|
||||
] = await Promise.all([
|
||||
this.prisma.user.count(),
|
||||
this.prisma.user.count({ where: { isActive: true } }),
|
||||
@@ -37,6 +39,11 @@ export class AdminService {
|
||||
by: ['status'],
|
||||
_count: { id: true },
|
||||
}),
|
||||
this.prisma.renderJob.count(),
|
||||
this.prisma.renderJob.groupBy({
|
||||
by: ['status'],
|
||||
_count: { id: true },
|
||||
}),
|
||||
]);
|
||||
|
||||
// Kredi istatistikleri
|
||||
@@ -63,6 +70,13 @@ export class AdminService {
|
||||
return acc;
|
||||
}, {} as Record<string, number>),
|
||||
},
|
||||
renderJobs: {
|
||||
total: totalRenderJobs,
|
||||
byStatus: renderJobsByStatus.reduce((acc, item) => {
|
||||
acc[item.status] = item._count.id;
|
||||
return acc;
|
||||
}, {} as Record<string, number>),
|
||||
},
|
||||
credits: {
|
||||
totalGranted: creditStats._sum.amount || 0,
|
||||
totalUsed: Math.abs(creditUsed._sum.amount || 0),
|
||||
@@ -106,6 +120,31 @@ export class AdminService {
|
||||
});
|
||||
}
|
||||
|
||||
// ── Proje ve Render Yönetimi ──────────────────────────────────────
|
||||
|
||||
async getAllProjects() {
|
||||
return this.prisma.project.findMany({
|
||||
include: { user: { select: { email: true, firstName: true, lastName: true } } },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
}
|
||||
|
||||
async getAllRenderJobs() {
|
||||
return this.prisma.renderJob.findMany({
|
||||
include: { project: { select: { name: true } } },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
}
|
||||
|
||||
// ── Kullanıcı Yönetimi ────────────────────────────────────────────
|
||||
|
||||
async banUser(userId: string, isBanned: boolean) {
|
||||
return this.prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: { isActive: !isBanned },
|
||||
});
|
||||
}
|
||||
|
||||
// ── Kullanıcı Kredi Yönetimi ──────────────────────────────────────
|
||||
|
||||
async grantCredits(userId: string, amount: number, description: string) {
|
||||
|
||||
Reference in New Issue
Block a user