add businesses CRUD module
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { BusinessEntity } from '../../entities/business.entity';
|
||||
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()
|
||||
create(@Body() payload: CreateBusinessDto): Promise<BusinessEntity> {
|
||||
return this.service.create(payload);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(
|
||||
@Param('id') id: string,
|
||||
@Body() payload: UpdateBusinessDto,
|
||||
): Promise<BusinessEntity> {
|
||||
return this.service.update(id, payload);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async remove(@Param('id') id: string): Promise<{ success: true }> {
|
||||
await this.service.remove(id);
|
||||
return { success: true };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user