business list
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { Controller, Get, Post, Body, Param, Delete } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, Param, Delete, Query } from '@nestjs/common';
|
||||
import { DPageService } from './dpage.service';
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
import { UserDec } from '../../common/decorators/user.decorator';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { AuthGuards } from '../../common/decorators/auth-guard.decorator';
|
||||
import { FindBusinessesDto } from './dto/find-businesses.dto';
|
||||
|
||||
@Controller('dpage')
|
||||
@ApiTags('d-page')
|
||||
@@ -18,9 +19,9 @@ export class DpageController {
|
||||
return this.dpageService.loginToDpage(dto, userId);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.dpageService.findAll();
|
||||
@Get('business/list')
|
||||
findAll(@Query() dto :FindBusinessesDto) {
|
||||
return this.dpageService.findAll(dto);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
|
||||
@@ -7,6 +7,7 @@ import { SubscriptionsService } from "../subscriptions/providers/subscriptions.s
|
||||
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 { UsersService } from "../users/providers/users.service";
|
||||
// import { UpdateDpageDto } from './dto/update-dpage.dto';
|
||||
|
||||
@@ -28,8 +29,38 @@ export class DPageService {
|
||||
};
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all dpage`;
|
||||
async findAll(dto: FindBusinessesDto) {
|
||||
|
||||
try {
|
||||
// 2. Login with userSubscriptionId
|
||||
const { data } = await firstValueFrom(
|
||||
this.httpService
|
||||
.get(`${this.config.baseUrl}/super-admin/business/list`,
|
||||
{
|
||||
params: dto,
|
||||
headers: this.getHeaders(),
|
||||
})
|
||||
.pipe(
|
||||
catchError((err: AxiosError) => {
|
||||
this.logger.error(`Failed to perform direct login: ${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 direct login: ${error instanceof Error ? error.message : "Unknown error"}`);
|
||||
throw error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
@@ -49,11 +80,11 @@ export class DPageService {
|
||||
// 1. validate userSubscription by id
|
||||
const userSubscription = await this.subscriptionService.findOneOrFail(userSubscriptionId)
|
||||
|
||||
|
||||
|
||||
if (userSubscription.user.id !== userId) {
|
||||
throw new BadRequestException("this subscription doesnt belongs to you")
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// 2. Login with userSubscriptionId
|
||||
const { data } = await firstValueFrom(
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { IsOptional, IsNumber, IsString, IsIn, IsBoolean } from 'class-validator';
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
export class FindBusinessesDto {
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Type(() => Number)
|
||||
@ApiPropertyOptional({ example: 1 })
|
||||
page?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Type(() => Number)
|
||||
@ApiPropertyOptional({ example: 10 })
|
||||
limit?: number;
|
||||
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional({ example: 'createdAt' })
|
||||
orderBy?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsIn(['asc', 'desc'])
|
||||
@ApiPropertyOptional({ example: 'desc' })
|
||||
order?: 'asc' | 'desc';
|
||||
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Type(() => Boolean)
|
||||
@ApiPropertyOptional({ example: true })
|
||||
isActive?: boolean;
|
||||
}
|
||||
Reference in New Issue
Block a user