update , remove endpoints

This commit is contained in:
2026-03-15 15:13:17 +03:30
parent 2f4fc1b1b0
commit 8e1df5aebc
4 changed files with 67 additions and 17 deletions
+9 -9
View File
@@ -3,7 +3,7 @@ import { BusinessService } from './business.service';
import { SetupBusinessDto } from './dto/setup-business.dto';
import { SuperAdminAuthGuard } from '../auth/guards/superAdminAuth.guard';
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')
@UseGuards(SuperAdminAuthGuard)
@@ -15,15 +15,15 @@ export class BusinessController {
return this.businessService.findAll(dto);
}
// @Get(':id')
// findOne(@Param('id') id: string) {
// return this.businessService.fin(id);
// }
@Get(':id')
findOne(@Param('id') id: string) {
return this.businessService.findByIdOrFail(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) {
+1 -1
View File
@@ -6,7 +6,7 @@ import { Business } from './entities/business.entity';
import { JwtModule } from '@nestjs/jwt';
@Module({
imports: [MikroOrmModule.forFeature([Business]), JwtModule.register({})],
imports: [MikroOrmModule.forFeature([Business]), JwtModule],
controllers: [BusinessController],
providers: [BusinessService],
exports: [BusinessService],
+37 -4
View File
@@ -19,10 +19,23 @@ export class BusinessService {
async setupAccount(dto: SetupBusinessDto) {
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,
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 = em.create(Business, {
danakSubscriptionId,
@@ -74,13 +87,33 @@ export class BusinessService {
return business
}
update(id: number, updateBusinessDto: UpdateBusinessDto) {
return `This action updates a #${id} business`;
async update(id: string, dto: UpdateBusinessDto) {
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) {
return await this.em.transactional(async (em) => {
// Find the restaurant first
const business = await em.findOne(Business, { id: businessId });
if (!business) {
@@ -1,4 +1,21 @@
import { PartialType } from '@nestjs/swagger';
import { SetupBusinessDto } from './setup-business.dto';
import { IsInt, IsString, } from 'class-validator';
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;
}