remove endpoint , update

This commit is contained in:
2026-03-15 14:46:13 +03:30
parent 98916399c4
commit 7f0fa2d394
4 changed files with 83 additions and 11 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ export class DpageController {
@AdminRoute()
@PermissionsDec(PermissionEnum.DMENU)
findAll(@Query() dto: FindBusinessesDto) {
return this.dpageService.findAll(dto);
return this.dpageService.findAllBusinesses(dto);
}
// @Get(':id')
+62 -5
View File
@@ -8,6 +8,7 @@ import { IDPageConfig } from "../../configs/dpage.config";
import { LoginDto } from './dto/login.dto';
import { DPAGE_CONFIG } from "./constants";
import { FindBusinessesDto } from "./dto/find-businesses.dto";
import { UpdateDpageDto } from "./dto/update-dpage.dto";
@Injectable()
@@ -27,7 +28,7 @@ export class DPageService {
};
}
async findAll(dto: FindBusinessesDto) {
async findAllBusinesses(dto: FindBusinessesDto) {
try {
// 2. Login with userSubscriptionId
@@ -61,7 +62,7 @@ export class DPageService {
}
async setupDpageAccount(dto: SetupAccountDto) {
async createDpageAccount(dto: createAccountDto) {
try {
const { data } = await firstValueFrom(
this.httpService
@@ -91,8 +92,64 @@ export class DPageService {
}
}
remove(id: number) {
return `This action removes a #${id} dpage`;
async updateDpageAccount(id: string, dto: UpdateDpageDto) {
try {
const { data } = await firstValueFrom(
this.httpService
.patch(`${this.config.baseUrl}/super-admin/business/${id}`, dto,
{
headers: this.getHeaders(),
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error(`Failed to perform update account: ${err.message}`, err.stack);
return throwError(() => err);
}),
),
);
return data;
} catch (error: unknown) {
if (error instanceof AxiosError && error.response) {
this.logger.error(`External API error response:`, error.response.data);
const errorResponse = {
...error.response.data,
message: error.response.data.error?.message || error.message,
};
throw new HttpException(errorResponse, error.response.status);
}
this.logger.error(`Error performing setup account: ${error instanceof Error ? error.message : "Unknown error"}`);
throw error;
}
}
async removeAccount(id: string) {
try {
const { data } = await firstValueFrom(
this.httpService
.post(`${this.config.baseUrl}/super-admin/business/${id}`,
{
headers: this.getHeaders(),
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error(`Failed to hard delete business: ${err.message}`, err.stack);
return throwError(() => err);
}),
),
);
return data;
} catch (error: unknown) {
if (error instanceof AxiosError && error.response) {
this.logger.error(`External API error response:`, error.response.data);
const errorResponse = {
...error.response.data,
message: error.response.data.error?.message || error.message,
};
throw new HttpException(errorResponse, error.response.status);
}
this.logger.error(`Error performing hard delete: ${error instanceof Error ? error.message : "Unknown error"}`);
throw error;
}
}
async loginToDpage(dto: LoginDto, userId: string) {
@@ -138,7 +195,7 @@ export class DPageService {
}
export class SetupAccountDto {
export class createAccountDto {
danakSubscriptionId: string;
name: string;
slug: string;
+18 -3
View File
@@ -1,4 +1,19 @@
import { PartialType } from '@nestjs/swagger';
import { LoginDto } from './login.dto';
import { IsInt, IsOptional, IsString } from 'class-validator';
export class UpdateDpageDto extends PartialType(LoginDto) {}
export class UpdateDpageDto {
@IsString()
@IsOptional()
danakSubscriptionId: string;
@IsString()
@IsOptional()
name: string;
@IsString()
@IsOptional()
slug: string;
@IsInt()
@IsOptional()
maxCataloguesCount: number
}
@@ -904,7 +904,7 @@ export class InvoicesService {
try {
this.logger.log(`Calling external API for dpage setup: subscription ${userSubscription.id}`);
console.log('userSubscription.plan.count',userSubscription.plan.count)
await this.dpageService.setupDpageAccount({
await this.dpageService.createDpageAccount({
danakSubscriptionId: userSubscription.id,
name: userSubscription.businessName,
slug: randomInt(100_000, 1_000_000).toString(),