add : direct login
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user