Spaces:
Sleeping
Sleeping
Viktoria435
Refactor import paths in Book, Visitor, and Worker modules to use relative paths
c995cfc
| import { | |
| Controller, | |
| Get, | |
| Post, | |
| Body, | |
| Param, | |
| Delete, | |
| Patch, | |
| HttpCode, | |
| HttpStatus, | |
| NotFoundException, | |
| Query, | |
| } from '@nestjs/common'; | |
| import { | |
| ApiTags, | |
| ApiOperation, | |
| ApiResponse, | |
| ApiParam, | |
| ApiQuery, | |
| } from '@nestjs/swagger'; | |
| import { WorkerService } from './worker.service'; | |
| import { Worker } from './dto/worker.dto'; | |
| import { CreateWorkerDto } from './dto/create-worker.dto'; | |
| import { DayOfWeek } from '../types/worker.types'; | |
| import { WorkerWithBooks } from '../common/worker-link-manager'; | |
| import { buildDownloadFile } from '../utils/download.utils'; | |
| ('Workers') | |
| ('workers') | |
| export class WorkerController { | |
| constructor(private readonly workerService: WorkerService) {} | |
| ('all') | |
| ({ summary: 'Get all workers' }) | |
| ({ status: 200, description: 'Returns all workers' }) | |
| async getWorkers(): Promise<WorkerWithBooks[]> { | |
| return await this.workerService.getAllWithIssuedBooks(); | |
| } | |
| (':id/download') | |
| ({ summary: 'Download worker data as file' }) | |
| ({ name: 'id', type: 'string' }) | |
| async downloadWorker(('id') id: string) { | |
| const worker = await this.workerService.getByIdWithIssuedBooks(id); | |
| if (!worker) { | |
| throw new NotFoundException(`Worker with id ${id} not found`); | |
| } | |
| return buildDownloadFile('workers', id, worker); | |
| } | |
| ('by-work-days') | |
| ({ summary: 'Get workers by work days' }) | |
| ({ name: 'workDays', type: 'array', items: { type: 'string' } }) | |
| ({ status: 200, description: 'Returns workers by work days' }) | |
| async getWorkersByWorkDays( | |
| ('workDays') workDays: DayOfWeek[], | |
| ): Promise<WorkerWithBooks[]> { | |
| return await this.workerService.getByWorkDays(workDays); | |
| } | |
| ('create') | |
| (HttpStatus.CREATED) | |
| ({ summary: 'Create a new worker' }) | |
| ({ status: 201, description: 'Worker created successfully' }) | |
| ({ status: 400, description: 'Invalid input' }) | |
| async addWorker(() body: CreateWorkerDto): Promise<Worker> { | |
| return await this.workerService.add(body); | |
| } | |
| (':id') | |
| ({ summary: 'Get employee by ID' }) | |
| ({ name: 'id', type: 'string' }) | |
| ({ status: 200, description: 'Returns the employee' }) | |
| ({ status: 404, description: 'Employee not found' }) | |
| async getWorker(('id') id: string): Promise<WorkerWithBooks> { | |
| const worker = await this.workerService.getByIdWithIssuedBooks(id); | |
| if (!worker) { | |
| throw new NotFoundException(`Worker with id ${id} not found`); | |
| } | |
| return worker; | |
| } | |
| (':id') | |
| ({ summary: 'Update a worker' }) | |
| ({ name: 'id', type: 'string' }) | |
| ({ status: 200, description: 'Employee updated successfully' }) | |
| ({ status: 404, description: 'Employee not found' }) | |
| async updateEmployee( | |
| ('id') id: string, | |
| () body: Partial<CreateWorkerDto>, | |
| ): Promise<Worker> { | |
| const updated = await this.workerService.update(id, body); | |
| if (!updated) { | |
| throw new NotFoundException(`Worker with id ${id} not found`); | |
| } | |
| return updated; | |
| } | |
| (':id') | |
| (HttpStatus.NO_CONTENT) | |
| ({ summary: 'Delete a worker' }) | |
| ({ name: 'id', type: 'string' }) | |
| ({ status: 204, description: 'Worker deleted successfully' }) | |
| ({ status: 404, description: 'Worker not found' }) | |
| async deleteWorker(('id') id: string): Promise<void> { | |
| const deleted = await this.workerService.delete(id); | |
| if (!deleted) { | |
| throw new NotFoundException(`Worker with id ${id} not found`); | |
| } | |
| } | |
| } | |