chore: add business logic

This commit is contained in:
Mahyargdz
2025-05-18 10:19:00 +03:30
parent 479c9c390a
commit 9eeab529a9
25 changed files with 350 additions and 74 deletions
+17 -13
View File
@@ -1,48 +1,52 @@
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from "@nestjs/common";
import { Body, Controller, Delete, Get, Param, Patch, Post, Query, UseInterceptors } from "@nestjs/common";
import { ApiOperation } from "@nestjs/swagger";
import { CompanyListQueryDto } from "./DTO/company-list-query.dto";
import { CreateCompanyDto } from "./DTO/create-company.dto";
import { UpdateCompanyDto } from "./DTO/update-company.dto";
import { CompaniesService } from "./services/companies.service";
import { BusinessDec } from "../../common/decorators/business.decorator";
import { ParamDto } from "../../common/DTO/param.dto";
import { BusinessInterceptor } from "../../core/interceptors/business.interceptor";
import { Business } from "../businesses/entities/business.entity";
@Controller("companies")
@UseInterceptors(BusinessInterceptor)
export class CompaniesController {
constructor(private readonly companiesService: CompaniesService) {}
@Post()
@ApiOperation({ summary: "create company (admin)" })
create(@Body() createCompanyDto: CreateCompanyDto) {
return this.companiesService.create(createCompanyDto);
create(@Body() createCompanyDto: CreateCompanyDto, @BusinessDec() business: Business) {
return this.companiesService.create(createCompanyDto, business);
}
@Patch(":id")
@ApiOperation({ summary: "update company (admin)" })
update(@Param() paramDto: ParamDto, @Body() updateCompanyDto: UpdateCompanyDto) {
return this.companiesService.updateCompanyById(paramDto.id, updateCompanyDto);
update(@Param() paramDto: ParamDto, @Body() updateCompanyDto: UpdateCompanyDto, @BusinessDec("id") businessId: string) {
return this.companiesService.updateCompanyById(paramDto.id, updateCompanyDto, businessId);
}
@Delete(":id")
@ApiOperation({ summary: "delete company (admin)" })
delete(@Param() paramDto: ParamDto) {
return this.companiesService.deleteCompanyById(paramDto.id);
delete(@Param() paramDto: ParamDto, @BusinessDec("id") businessId: string) {
return this.companiesService.deleteCompanyById(paramDto.id, businessId);
}
@Get("list")
@ApiOperation({ summary: "get companies list (admin)" })
getCompaniesList(@Query() query: CompanyListQueryDto) {
return this.companiesService.getCompaniesList(query);
getCompaniesList(@Query() query: CompanyListQueryDto, @BusinessDec("id") businessId: string) {
return this.companiesService.getCompaniesList(query, businessId);
}
@Get(":id")
@ApiOperation({ summary: "get company by id" })
get(@Param() paramDto: ParamDto) {
return this.companiesService.getCompanyById(paramDto.id);
get(@Param() paramDto: ParamDto, @BusinessDec("id") businessId: string) {
return this.companiesService.getCompanyById(paramDto.id, businessId);
}
@Patch(":id/toggle-status")
@ApiOperation({ summary: "toggle company status (admin)" })
toggleStatus(@Param() paramDto: ParamDto) {
return this.companiesService.toggleStatus(paramDto.id);
toggleStatus(@Param() paramDto: ParamDto, @BusinessDec("id") businessId: string) {
return this.companiesService.toggleStatus(paramDto.id, businessId);
}
}