business remove
This commit is contained in:
@@ -1,23 +1,17 @@
|
|||||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Query } from '@nestjs/common';
|
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Query } from '@nestjs/common';
|
||||||
import { BusinessService } from './business.service';
|
import { BusinessService } from './business.service';
|
||||||
import { SetupBusinessDto } from './dto/create-business.dto';
|
import { SetupBusinessDto } from './dto/create-business.dto';
|
||||||
import { UpdateBusinessDto } from './dto/update-business.dto';
|
|
||||||
import { SuperAdminAuthGuard } from '../auth/guards/superAdminAuth.guard';
|
import { SuperAdminAuthGuard } from '../auth/guards/superAdminAuth.guard';
|
||||||
import { FindBusinessesDto } from './dto/find-businesses.dto';
|
import { FindBusinessesDto } from './dto/find-businesses.dto';
|
||||||
|
// import { UpdateBusinessDto } from './dto/update-business.dto';
|
||||||
|
|
||||||
@Controller('super-admin/business')
|
@Controller('super-admin/business')
|
||||||
@UseGuards(SuperAdminAuthGuard)
|
@UseGuards(SuperAdminAuthGuard)
|
||||||
export class BusinessController {
|
export class BusinessController {
|
||||||
constructor(private readonly businessService: BusinessService) { }
|
constructor(private readonly businessService: BusinessService) { }
|
||||||
|
|
||||||
@Post('setup')
|
|
||||||
@UseGuards(SuperAdminAuthGuard)
|
|
||||||
create(@Body() dto: SetupBusinessDto) {
|
|
||||||
return this.businessService.setupAccount(dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('list')
|
@Get('list')
|
||||||
findAll(@Query() dto :FindBusinessesDto) {
|
findAll(@Query() dto: FindBusinessesDto) {
|
||||||
return this.businessService.findAll(dto);
|
return this.businessService.findAll(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,13 +20,18 @@ export class BusinessController {
|
|||||||
// return this.businessService.fin(id);
|
// return this.businessService.fin(id);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Patch(':id')
|
// @Patch(':id')
|
||||||
update(@Param('id') id: string, @Body() updateBusinessDto: UpdateBusinessDto) {
|
// update(@Param('id') id: string, @Body() updateBusinessDto: UpdateBusinessDto) {
|
||||||
return this.businessService.update(+id, updateBusinessDto);
|
// return this.businessService.update(+id, updateBusinessDto);
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Post('setup')
|
||||||
|
create(@Body() dto: SetupBusinessDto) {
|
||||||
|
return this.businessService.setupAccount(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
remove(@Param('id') id: string) {
|
remove(@Param('id') id: string) {
|
||||||
return this.businessService.remove(+id);
|
return this.businessService.hardDelete(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Business } from './entities/business.entity';
|
|||||||
import { Admin } from '../admin/entities/admin.entity';
|
import { Admin } from '../admin/entities/admin.entity';
|
||||||
import { BusinessRepository } from './repositories/business.repository';
|
import { BusinessRepository } from './repositories/business.repository';
|
||||||
import { FindBusinessesDto } from './dto/find-businesses.dto';
|
import { FindBusinessesDto } from './dto/find-businesses.dto';
|
||||||
|
import { Catalogue } from '../catalogue/entities/catalogue.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BusinessService {
|
export class BusinessService {
|
||||||
@@ -71,7 +72,18 @@ export class BusinessService {
|
|||||||
return `This action updates a #${id} business`;
|
return `This action updates a #${id} business`;
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(id: number) {
|
async hardDelete(businessId: string) {
|
||||||
return `This action removes a #${id} business`;
|
return await this.em.transactional(async (em) => {
|
||||||
|
// Find the restaurant first
|
||||||
|
const business = await em.findOne(Business, { id: businessId });
|
||||||
|
|
||||||
|
if (!business) {
|
||||||
|
throw new NotFoundException('Not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
await em.nativeDelete(Business, { id: businessId });
|
||||||
|
|
||||||
|
await em.nativeDelete(Catalogue, { business: { id: businessId } });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user