73 lines
1.7 KiB
TypeScript
73 lines
1.7 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
Post,
|
|
Put,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ObatService } from './obat.service';
|
|
import { AuthGuard } from '../auth/guard/auth.guard';
|
|
import { UpdateObatDto } from './dto/update-obat-dto';
|
|
import { CurrentUser } from '../auth/decorator/current-user.decorator';
|
|
import type { ActiveUserPayload } from '../auth/decorator/current-user.decorator';
|
|
import { CreateObatDto } from './dto/create-obat-dto';
|
|
|
|
@Controller('obat')
|
|
export class ObatController {
|
|
constructor(private readonly obatService: ObatService) {}
|
|
|
|
@Get('/')
|
|
@UseGuards(AuthGuard)
|
|
async getAllObat(
|
|
@Query('take') take: number,
|
|
@Query('skip') skip: number,
|
|
@Query('page') page: number,
|
|
@Query('orderBy') orderBy: string,
|
|
@Query('obat') obat: string,
|
|
@Query('order') order: 'asc' | 'desc',
|
|
) {
|
|
return await this.obatService.getAllObat({
|
|
take,
|
|
skip,
|
|
page,
|
|
orderBy: orderBy ? { [orderBy]: order || 'asc' } : undefined,
|
|
obat,
|
|
order,
|
|
});
|
|
}
|
|
|
|
@Get(':id')
|
|
@UseGuards(AuthGuard)
|
|
async getObatById(@Param('id') id: number) {
|
|
return await this.obatService.getObatById(id);
|
|
}
|
|
|
|
@Post('/')
|
|
@UseGuards(AuthGuard)
|
|
async createObat(
|
|
@Body() dto: CreateObatDto,
|
|
@CurrentUser() user: ActiveUserPayload,
|
|
) {
|
|
return await this.obatService.createObat(dto, user);
|
|
}
|
|
|
|
@Put(':id')
|
|
@UseGuards(AuthGuard)
|
|
async updateObatById(
|
|
@Param('id') id: number,
|
|
@Body() dto: UpdateObatDto,
|
|
@CurrentUser() user: ActiveUserPayload,
|
|
) {
|
|
return await this.obatService.updateObatById(id, dto, user);
|
|
}
|
|
|
|
@Get('/:id/log')
|
|
@UseGuards(AuthGuard)
|
|
async getObatLogs(@Param('id') id: string) {
|
|
return await this.obatService.getLogObatById(id);
|
|
}
|
|
}
|