Spaces:
Sleeping
Sleeping
File size: 1,345 Bytes
22df730 c995cfc 22df730 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import {
Controller,
Get,
Post,
Patch,
Delete,
Body,
Param,
} from '@nestjs/common';
import { VisitorService } from './visitor.service';
import { Visitor } from './dto/visitor.dto';
import { CreateVisitorDto } from './dto/create-visitor.dto';
import { UpdateVisitorDto } from './dto/update-visitor.dto';
import { buildDownloadFile } from '../utils/download.utils';
@Controller('visitors')
export class VisitorController {
constructor(private readonly visitorService: VisitorService) {}
@Get('all')
async getAll(): Promise<Visitor[]> {
return this.visitorService.getAll();
}
@Get(':id/download')
async download(@Param('id') id: string) {
const visitor = await this.visitorService.getById(id);
return buildDownloadFile('visitors', id, visitor);
}
@Post('create')
async create(@Body() dto: CreateVisitorDto): Promise<Visitor> {
return this.visitorService.add(dto);
}
@Get(':id')
async getById(@Param('id') id: string): Promise<Visitor> {
return this.visitorService.getById(id);
}
@Patch(':id')
async update(
@Param('id') id: string,
@Body() dto: UpdateVisitorDto,
): Promise<Visitor> {
return this.visitorService.update(id, dto);
}
@Delete('delete/:id')
async remove(@Param('id') id: string): Promise<void> {
return this.visitorService.delete(id);
}
}
|