2026-05-07 21:22:50 +03:30
|
|
|
import {
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Delete,
|
|
|
|
|
Get,
|
|
|
|
|
Param,
|
|
|
|
|
Patch,
|
|
|
|
|
Post,
|
|
|
|
|
Query,
|
2026-05-11 12:40:42 +03:30
|
|
|
UseGuards,
|
2026-05-07 21:22:50 +03:30
|
|
|
} from '@nestjs/common';
|
|
|
|
|
import { BusinessEntity } from '../../entities/business.entity';
|
2026-05-11 12:40:42 +03:30
|
|
|
import { UserRole } from '../../entities/user.entity';
|
|
|
|
|
import { AuthUser } from '../auth/auth.types';
|
|
|
|
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
|
|
|
|
import { Roles } from '../auth/decorators/roles.decorator';
|
|
|
|
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
|
|
|
|
import { RolesGuard } from '../auth/guards/roles.guard';
|
2026-05-07 21:22:50 +03:30
|
|
|
import { BusinessesService } from './businesses.service';
|
|
|
|
|
import { CreateBusinessDto } from './dto/create-business.dto';
|
|
|
|
|
import { UpdateBusinessDto } from './dto/update-business.dto';
|
|
|
|
|
|
|
|
|
|
@Controller('businesses')
|
|
|
|
|
export class BusinessesController {
|
|
|
|
|
constructor(private readonly service: BusinessesService) {}
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
findAll(
|
|
|
|
|
@Query('categoryId') categoryId?: string,
|
|
|
|
|
@Query('isActive') isActive?: string,
|
|
|
|
|
): Promise<BusinessEntity[]> {
|
|
|
|
|
const parsedIsActive =
|
|
|
|
|
typeof isActive === 'string' ? isActive === 'true' : undefined;
|
|
|
|
|
|
|
|
|
|
return this.service.findAll({
|
|
|
|
|
categoryId,
|
|
|
|
|
isActive: parsedIsActive,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':id')
|
|
|
|
|
findOne(@Param('id') id: string): Promise<BusinessEntity> {
|
|
|
|
|
return this.service.findOne(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post()
|
2026-05-11 12:40:42 +03:30
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.ADMIN)
|
2026-05-07 21:22:50 +03:30
|
|
|
create(@Body() payload: CreateBusinessDto): Promise<BusinessEntity> {
|
|
|
|
|
return this.service.create(payload);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Patch(':id')
|
2026-05-11 12:40:42 +03:30
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.ADMIN, UserRole.BUSINESS_OWNER)
|
2026-05-07 21:22:50 +03:30
|
|
|
update(
|
|
|
|
|
@Param('id') id: string,
|
|
|
|
|
@Body() payload: UpdateBusinessDto,
|
2026-05-11 12:40:42 +03:30
|
|
|
@CurrentUser() user: AuthUser,
|
2026-05-07 21:22:50 +03:30
|
|
|
): Promise<BusinessEntity> {
|
2026-05-11 12:40:42 +03:30
|
|
|
return this.service.update(id, payload, user);
|
2026-05-07 21:22:50 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete(':id')
|
2026-05-11 12:40:42 +03:30
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.ADMIN)
|
2026-05-07 21:22:50 +03:30
|
|
|
async remove(@Param('id') id: string): Promise<{ success: true }> {
|
|
|
|
|
await this.service.remove(id);
|
|
|
|
|
return { success: true };
|
|
|
|
|
}
|
|
|
|
|
}
|