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 { BusinessService } from './business.service';
|
||||
import { SetupBusinessDto } from './dto/create-business.dto';
|
||||
import { UpdateBusinessDto } from './dto/update-business.dto';
|
||||
import { SuperAdminAuthGuard } from '../auth/guards/superAdminAuth.guard';
|
||||
import { FindBusinessesDto } from './dto/find-businesses.dto';
|
||||
// import { UpdateBusinessDto } from './dto/update-business.dto';
|
||||
|
||||
@Controller('super-admin/business')
|
||||
@UseGuards(SuperAdminAuthGuard)
|
||||
export class BusinessController {
|
||||
constructor(private readonly businessService: BusinessService) { }
|
||||
|
||||
@Post('setup')
|
||||
@UseGuards(SuperAdminAuthGuard)
|
||||
create(@Body() dto: SetupBusinessDto) {
|
||||
return this.businessService.setupAccount(dto);
|
||||
}
|
||||
|
||||
@Get('list')
|
||||
findAll(@Query() dto :FindBusinessesDto) {
|
||||
findAll(@Query() dto: FindBusinessesDto) {
|
||||
return this.businessService.findAll(dto);
|
||||
}
|
||||
|
||||
@@ -26,13 +20,18 @@ export class BusinessController {
|
||||
// return this.businessService.fin(id);
|
||||
// }
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateBusinessDto: UpdateBusinessDto) {
|
||||
return this.businessService.update(+id, updateBusinessDto);
|
||||
// @Patch(':id')
|
||||
// update(@Param('id') id: string, @Body() updateBusinessDto: UpdateBusinessDto) {
|
||||
// return this.businessService.update(+id, updateBusinessDto);
|
||||
// }
|
||||
|
||||
@Post('setup')
|
||||
create(@Body() dto: SetupBusinessDto) {
|
||||
return this.businessService.setupAccount(dto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
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 { BusinessRepository } from './repositories/business.repository';
|
||||
import { FindBusinessesDto } from './dto/find-businesses.dto';
|
||||
import { Catalogue } from '../catalogue/entities/catalogue.entity';
|
||||
|
||||
@Injectable()
|
||||
export class BusinessService {
|
||||
@@ -71,7 +72,18 @@ export class BusinessService {
|
||||
return `This action updates a #${id} business`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} business`;
|
||||
async hardDelete(businessId: string) {
|
||||
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