56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import {
|
|||
|
|
Body,
|
||
|
|
Controller,
|
||
|
|
Delete,
|
||
|
|
Get,
|
||
|
|
Param,
|
||
|
|
Patch,
|
||
|
|
Post,
|
||
|
|
Query,
|
||
|
|
UseGuards,
|
||
|
|
} from '@nestjs/common';
|
||
|
|
import { ProductType } from '@prisma/client';
|
||
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
||
|
|
import { CreateTenantDto } from './dto/create-tenant.dto';
|
||
|
|
import { UpdateTenantDto } from './dto/update-tenant.dto';
|
||
|
|
import { TenantsService } from './tenants.service';
|
||
|
|
|
||
|
|
@Controller('tenants')
|
||
|
|
@UseGuards(JwtAuthGuard)
|
||
|
|
export class TenantsController {
|
||
|
|
constructor(private readonly tenantsService: TenantsService) {}
|
||
|
|
|
||
|
|
@Get()
|
||
|
|
findAll(@Query('product') product?: ProductType) {
|
||
|
|
return this.tenantsService.findAll(product);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get(':id')
|
||
|
|
findOne(@Param('id') id: string) {
|
||
|
|
return this.tenantsService.findOne(id);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Post()
|
||
|
|
create(
|
||
|
|
@Body() dto: CreateTenantDto,
|
||
|
|
@CurrentUser() user: { id: string },
|
||
|
|
) {
|
||
|
|
return this.tenantsService.create(dto, user.id);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Patch(':id')
|
||
|
|
update(
|
||
|
|
@Param('id') id: string,
|
||
|
|
@Body() dto: UpdateTenantDto,
|
||
|
|
@CurrentUser() user: { id: string },
|
||
|
|
) {
|
||
|
|
return this.tenantsService.update(id, dto, user.id);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Delete(':id')
|
||
|
|
remove(@Param('id') id: string, @CurrentUser() user: { id: string }) {
|
||
|
|
return this.tenantsService.remove(id, user.id);
|
||
|
|
}
|
||
|
|
}
|