add : direct login

This commit is contained in:
2026-01-05 09:08:51 +03:30
parent 62aa24122e
commit a0437b02af
3 changed files with 53 additions and 1 deletions
+12
View File
@@ -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;
}
+7
View File
@@ -12,6 +12,7 @@ import { FindRestaurantsDto } from "./DTO/find-restaurants.dto";
import { SetupRestaurantDto } from "./DTO/create-restaurant.dto";
import { UpdateRestaurantDto } from "./DTO/update-restaurant.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 { PermissionsDec } from "../../common/decorators/permission.decorator";
import { PermissionEnum } from "../users/enums/permission.enum";
@@ -194,4 +195,10 @@ export class DmenuController {
getRestaurantSubscription(@Param("subscriptionId") subscriptionId: string) {
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 { SubscriptionsService } from "../../subscriptions/providers/subscriptions.service";
import { SubscriptionMessage } from "../../../common/enums/message.enum";
import { DirectLoginDto } from "../DTO/direct-login.dto";
@Injectable()
export class RestaurantService {
@@ -308,7 +309,7 @@ export class RestaurantService {
}
async assignRestaurantAdmin(restaurantId: string, dto: CreateMyRestaurantAdminDto) {
try {
try {
const { data } = await firstValueFrom(
this.httpService
.post(`${this.config.baseUrl}/super-admin/restaurants/${restaurantId}/admins`, dto, {
@@ -367,4 +368,36 @@ export class RestaurantService {
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;
}
}
}