Spaces:
Runtime error
Runtime error
Download src/modules/backup/controllers/backup.controller.ts from eduverse-team/eduverse-backend: direct link, hf CLI and curl.
- Browser
- Download file 3.21 kB
-
https://huggingface.co/spaces/eduverse-team/eduverse-backend/resolve/main/src/modules/backup/controllers/backup.controller.ts
- Command line
-
hf download hf://spaces/eduverse-team/eduverse-backend/src/modules/backup/controllers/backup.controller.ts
-
curl -L -o backup.controller.ts https://huggingface.co/spaces/eduverse-team/eduverse-backend/resolve/main/src/modules/backup/controllers/backup.controller.ts
3.21 kB
| import { | |
| Controller, | |
| Get, | |
| Post, | |
| Delete, | |
| Param, | |
| UseGuards, | |
| ParseIntPipe, | |
| Request, | |
| } from '@nestjs/common'; | |
| import { | |
| ApiTags, | |
| ApiBearerAuth, | |
| ApiOperation, | |
| ApiResponse, | |
| ApiParam, | |
| } from '@nestjs/swagger'; | |
| import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard'; | |
| import { RolesGuard } from '../../auth/guards/roles.guard'; | |
| import { Roles } from '../../../common/decorators/roles.decorator'; | |
| import { RoleName } from '../../auth/entities/role.entity'; | |
| import { BackupService } from '../services/backup.service'; | |
| ('💾 Backups') | |
| ('JWT-auth') | |
| ('api/backups') | |
| (JwtAuthGuard, RolesGuard) | |
| export class BackupController { | |
| constructor(private readonly backupService: BackupService) {} | |
| () | |
| (RoleName.ADMIN, RoleName.IT_ADMIN) | |
| ({ | |
| summary: 'List all backup records', | |
| description: | |
| 'Retrieves all database backup records ordered by most recent. ' + | |
| 'Access roles: ADMIN, IT_ADMIN. Uses table: `backup_records`.', | |
| }) | |
| ({ status: 200, description: 'Backup records returned' }) | |
| ({ status: 401, description: 'Unauthorized' }) | |
| ({ status: 403, description: 'Forbidden – insufficient role' }) | |
| async listBackups() { | |
| return this.backupService.listBackups(); | |
| } | |
| () | |
| (RoleName.IT_ADMIN) | |
| ({ | |
| summary: 'Create a new database backup', | |
| description: | |
| 'Triggers a mysqldump of the database and saves the output to backups/ directory. ' + | |
| 'Access roles: IT_ADMIN. Uses table: `backup_records`. Executes system command: `mysqldump`.', | |
| }) | |
| ({ status: 201, description: 'Backup created (or failed with message)' }) | |
| ({ status: 401, description: 'Unauthorized' }) | |
| ({ status: 403, description: 'Forbidden – insufficient role' }) | |
| async createBackup(() req) { | |
| return this.backupService.createBackup(req.user.sub); | |
| } | |
| (':id') | |
| (RoleName.ADMIN, RoleName.IT_ADMIN) | |
| ({ | |
| summary: 'Get backup details by ID', | |
| description: | |
| 'Retrieves full details of a specific backup record including creator info. ' + | |
| 'Access roles: ADMIN, IT_ADMIN. Uses table: `backup_records`.', | |
| }) | |
| ({ name: 'id', type: Number, description: 'Backup record ID' }) | |
| ({ status: 200, description: 'Backup details returned' }) | |
| ({ status: 404, description: 'Backup not found' }) | |
| async getBackupDetails(('id', ParseIntPipe) id: number) { | |
| return this.backupService.getBackupDetails(id); | |
| } | |
| (':id') | |
| (RoleName.IT_ADMIN) | |
| ({ | |
| summary: 'Delete a backup record and file', | |
| description: | |
| 'Removes the backup record from the database and deletes the physical file from disk. ' + | |
| 'Access roles: IT_ADMIN. Uses table: `backup_records`.', | |
| }) | |
| ({ name: 'id', type: Number, description: 'Backup record ID' }) | |
| ({ status: 200, description: 'Backup deleted' }) | |
| ({ status: 404, description: 'Backup not found' }) | |
| async deleteBackup(('id', ParseIntPipe) id: number) { | |
| return this.backupService.deleteBackup(id); | |
| } | |
| } | |