update , remove endpoints
This commit is contained in:
@@ -3,7 +3,7 @@ import { BusinessService } from './business.service';
|
|||||||
import { SetupBusinessDto } from './dto/setup-business.dto';
|
import { SetupBusinessDto } from './dto/setup-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';
|
import { UpdateBusinessDto } from './dto/update-business.dto';
|
||||||
|
|
||||||
@Controller('super-admin/business')
|
@Controller('super-admin/business')
|
||||||
@UseGuards(SuperAdminAuthGuard)
|
@UseGuards(SuperAdminAuthGuard)
|
||||||
@@ -15,15 +15,15 @@ export class BusinessController {
|
|||||||
return this.businessService.findAll(dto);
|
return this.businessService.findAll(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Get(':id')
|
@Get(':id')
|
||||||
// findOne(@Param('id') id: string) {
|
findOne(@Param('id') id: string) {
|
||||||
// return this.businessService.fin(id);
|
return this.businessService.findByIdOrFail(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')
|
@Post('setup')
|
||||||
create(@Body() dto: SetupBusinessDto) {
|
create(@Body() dto: SetupBusinessDto) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { Business } from './entities/business.entity';
|
|||||||
import { JwtModule } from '@nestjs/jwt';
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [MikroOrmModule.forFeature([Business]), JwtModule.register({})],
|
imports: [MikroOrmModule.forFeature([Business]), JwtModule],
|
||||||
controllers: [BusinessController],
|
controllers: [BusinessController],
|
||||||
providers: [BusinessService],
|
providers: [BusinessService],
|
||||||
exports: [BusinessService],
|
exports: [BusinessService],
|
||||||
|
|||||||
@@ -19,10 +19,23 @@ export class BusinessService {
|
|||||||
|
|
||||||
async setupAccount(dto: SetupBusinessDto) {
|
async setupAccount(dto: SetupBusinessDto) {
|
||||||
const { danakSubscriptionId, name, phone, slug, firstName, lastName, maxCataloguesCount } = dto
|
const { danakSubscriptionId, name, phone, slug, firstName, lastName, maxCataloguesCount } = dto
|
||||||
this.logger.log('recived request from danak payload', {
|
|
||||||
|
this.logger.log('recived request payload from danak ', {
|
||||||
danakSubscriptionId, name, phone, slug,
|
danakSubscriptionId, name, phone, slug,
|
||||||
firstName, lastName, maxCataloguesCount
|
firstName, lastName, maxCataloguesCount
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const existingSlug = await this.businessRepository.findOne({ slug: dto.slug })
|
||||||
|
|
||||||
|
if (existingSlug) {
|
||||||
|
throw new NotFoundException("this Slug is already taken, Please select another one.")
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingSubscriptionId = await this.businessRepository.findOne({ danakSubscriptionId: dto.danakSubscriptionId })
|
||||||
|
if (existingSubscriptionId) {
|
||||||
|
throw new NotFoundException("this danakSubscriptionId is already used")
|
||||||
|
}
|
||||||
|
|
||||||
const business = await this.em.transactional(async (em) => {
|
const business = await this.em.transactional(async (em) => {
|
||||||
const business = em.create(Business, {
|
const business = em.create(Business, {
|
||||||
danakSubscriptionId,
|
danakSubscriptionId,
|
||||||
@@ -74,13 +87,33 @@ export class BusinessService {
|
|||||||
return business
|
return business
|
||||||
}
|
}
|
||||||
|
|
||||||
update(id: number, updateBusinessDto: UpdateBusinessDto) {
|
async update(id: string, dto: UpdateBusinessDto) {
|
||||||
return `This action updates a #${id} business`;
|
const business = await this.findByIdOrFail(id)
|
||||||
|
|
||||||
|
if (dto.slug) {
|
||||||
|
const existing = await this.businessRepository.findOne({ slug: dto.slug, id: { $not: id } })
|
||||||
|
if (existing) {
|
||||||
|
throw new NotFoundException("this Slug is already taken, Please select another one.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dto.danakSubscriptionId) {
|
||||||
|
const existing = await this.businessRepository.findOne({ danakSubscriptionId: dto.danakSubscriptionId, id: { $not: id } })
|
||||||
|
if (existing) {
|
||||||
|
throw new NotFoundException("this danakSubscriptionId is already used")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.em.assign(business, dto)
|
||||||
|
|
||||||
|
await this.em.flush()
|
||||||
|
|
||||||
|
return business
|
||||||
}
|
}
|
||||||
|
|
||||||
async hardDelete(businessId: string) {
|
async hardDelete(businessId: string) {
|
||||||
return await this.em.transactional(async (em) => {
|
return await this.em.transactional(async (em) => {
|
||||||
// Find the restaurant first
|
|
||||||
const business = await em.findOne(Business, { id: businessId });
|
const business = await em.findOne(Business, { id: businessId });
|
||||||
|
|
||||||
if (!business) {
|
if (!business) {
|
||||||
|
|||||||
@@ -1,4 +1,21 @@
|
|||||||
import { PartialType } from '@nestjs/swagger';
|
import { IsInt, IsString, } from 'class-validator';
|
||||||
import { SetupBusinessDto } from './setup-business.dto';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
export class UpdateBusinessDto extends PartialType(SetupBusinessDto) { }
|
export class UpdateBusinessDto {
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ example: '01619684-aebc-47d4-acc4-2e912a3d9dce' })
|
||||||
|
danakSubscriptionId: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty()
|
||||||
|
slug: string;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
@ApiProperty()
|
||||||
|
maxCataloguesCount: number;
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user