add : direct login
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { IsString } from 'class-validator';
|
||||||
|
|
||||||
|
export class DirectLoginDto {
|
||||||
|
@ApiProperty({ example: '09123456789', description: 'شماره تلفن کاربر' })
|
||||||
|
@IsString()
|
||||||
|
phone!: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'zhivan', description: 'شناسه (slug) رستوران' })
|
||||||
|
@IsString()
|
||||||
|
slug!: string;
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import { FindRestaurantsDto } from "./DTO/find-restaurants.dto";
|
|||||||
import { SetupRestaurantDto } from "./DTO/create-restaurant.dto";
|
import { SetupRestaurantDto } from "./DTO/create-restaurant.dto";
|
||||||
import { UpdateRestaurantDto } from "./DTO/update-restaurant.dto";
|
import { UpdateRestaurantDto } from "./DTO/update-restaurant.dto";
|
||||||
import { CreateMyRestaurantAdminDto } from "./DTO/create-restaurant-admin.dto";
|
import { CreateMyRestaurantAdminDto } from "./DTO/create-restaurant-admin.dto";
|
||||||
|
import { DirectLoginDto } from "./DTO/direct-login.dto";
|
||||||
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
||||||
import { PermissionsDec } from "../../common/decorators/permission.decorator";
|
import { PermissionsDec } from "../../common/decorators/permission.decorator";
|
||||||
import { PermissionEnum } from "../users/enums/permission.enum";
|
import { PermissionEnum } from "../users/enums/permission.enum";
|
||||||
@@ -194,4 +195,10 @@ export class DmenuController {
|
|||||||
getRestaurantSubscription(@Param("subscriptionId") subscriptionId: string) {
|
getRestaurantSubscription(@Param("subscriptionId") subscriptionId: string) {
|
||||||
return this.restaurantService.getRestaurantSubscription(subscriptionId);
|
return this.restaurantService.getRestaurantSubscription(subscriptionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('dmenu/auth/direct-login')
|
||||||
|
@ApiOperation({ summary: "Direct login with phone number and restaurant slug" })
|
||||||
|
directLogin(@Body() dto: DirectLoginDto) {
|
||||||
|
return this.restaurantService.directLogin(dto);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { CreateMyRestaurantAdminDto } from "../DTO/create-restaurant-admin.dto";
|
|||||||
import { PlanEnum, ISetupRestaurant, IExternalApiResponse } from "../interface/plan.interface";
|
import { PlanEnum, ISetupRestaurant, IExternalApiResponse } from "../interface/plan.interface";
|
||||||
import { SubscriptionsService } from "../../subscriptions/providers/subscriptions.service";
|
import { SubscriptionsService } from "../../subscriptions/providers/subscriptions.service";
|
||||||
import { SubscriptionMessage } from "../../../common/enums/message.enum";
|
import { SubscriptionMessage } from "../../../common/enums/message.enum";
|
||||||
|
import { DirectLoginDto } from "../DTO/direct-login.dto";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RestaurantService {
|
export class RestaurantService {
|
||||||
@@ -308,7 +309,7 @@ export class RestaurantService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async assignRestaurantAdmin(restaurantId: string, dto: CreateMyRestaurantAdminDto) {
|
async assignRestaurantAdmin(restaurantId: string, dto: CreateMyRestaurantAdminDto) {
|
||||||
try {
|
try {
|
||||||
const { data } = await firstValueFrom(
|
const { data } = await firstValueFrom(
|
||||||
this.httpService
|
this.httpService
|
||||||
.post(`${this.config.baseUrl}/super-admin/restaurants/${restaurantId}/admins`, dto, {
|
.post(`${this.config.baseUrl}/super-admin/restaurants/${restaurantId}/admins`, dto, {
|
||||||
@@ -367,4 +368,36 @@ export class RestaurantService {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async directLogin(dto: DirectLoginDto) {
|
||||||
|
try {
|
||||||
|
const { data } = await firstValueFrom(
|
||||||
|
this.httpService
|
||||||
|
.post(`${this.config.baseUrl}/super-admin/auth/direct-login`, {
|
||||||
|
phone: dto.phone,
|
||||||
|
slug: dto.slug,
|
||||||
|
}, {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user