remove endpoint , update
This commit is contained in:
@@ -30,7 +30,7 @@ export class DpageController {
|
|||||||
@AdminRoute()
|
@AdminRoute()
|
||||||
@PermissionsDec(PermissionEnum.DMENU)
|
@PermissionsDec(PermissionEnum.DMENU)
|
||||||
findAll(@Query() dto: FindBusinessesDto) {
|
findAll(@Query() dto: FindBusinessesDto) {
|
||||||
return this.dpageService.findAll(dto);
|
return this.dpageService.findAllBusinesses(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Get(':id')
|
// @Get(':id')
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { IDPageConfig } from "../../configs/dpage.config";
|
|||||||
import { LoginDto } from './dto/login.dto';
|
import { LoginDto } from './dto/login.dto';
|
||||||
import { DPAGE_CONFIG } from "./constants";
|
import { DPAGE_CONFIG } from "./constants";
|
||||||
import { FindBusinessesDto } from "./dto/find-businesses.dto";
|
import { FindBusinessesDto } from "./dto/find-businesses.dto";
|
||||||
|
import { UpdateDpageDto } from "./dto/update-dpage.dto";
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -27,7 +28,7 @@ export class DPageService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(dto: FindBusinessesDto) {
|
async findAllBusinesses(dto: FindBusinessesDto) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 2. Login with userSubscriptionId
|
// 2. Login with userSubscriptionId
|
||||||
@@ -61,7 +62,7 @@ export class DPageService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async setupDpageAccount(dto: SetupAccountDto) {
|
async createDpageAccount(dto: createAccountDto) {
|
||||||
try {
|
try {
|
||||||
const { data } = await firstValueFrom(
|
const { data } = await firstValueFrom(
|
||||||
this.httpService
|
this.httpService
|
||||||
@@ -91,8 +92,64 @@ export class DPageService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(id: number) {
|
async updateDpageAccount(id: string, dto: UpdateDpageDto) {
|
||||||
return `This action removes a #${id} dpage`;
|
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) {
|
async loginToDpage(dto: LoginDto, userId: string) {
|
||||||
@@ -138,7 +195,7 @@ export class DPageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class SetupAccountDto {
|
export class createAccountDto {
|
||||||
danakSubscriptionId: string;
|
danakSubscriptionId: string;
|
||||||
name: string;
|
name: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
|
|||||||
@@ -1,4 +1,19 @@
|
|||||||
import { PartialType } from '@nestjs/swagger';
|
import { IsInt, IsOptional, IsString } from 'class-validator';
|
||||||
import { LoginDto } from './login.dto';
|
|
||||||
|
|
||||||
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 {
|
try {
|
||||||
this.logger.log(`Calling external API for dpage setup: subscription ${userSubscription.id}`);
|
this.logger.log(`Calling external API for dpage setup: subscription ${userSubscription.id}`);
|
||||||
console.log('userSubscription.plan.count',userSubscription.plan.count)
|
console.log('userSubscription.plan.count',userSubscription.plan.count)
|
||||||
await this.dpageService.setupDpageAccount({
|
await this.dpageService.createDpageAccount({
|
||||||
danakSubscriptionId: userSubscription.id,
|
danakSubscriptionId: userSubscription.id,
|
||||||
name: userSubscription.businessName,
|
name: userSubscription.businessName,
|
||||||
slug: randomInt(100_000, 1_000_000).toString(),
|
slug: randomInt(100_000, 1_000_000).toString(),
|
||||||
|
|||||||
Reference in New Issue
Block a user