upgrade plan

This commit is contained in:
2026-01-04 10:34:34 +03:30
parent 3c0b583a9d
commit 62aa24122e
13 changed files with 335 additions and 20 deletions
@@ -10,7 +10,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 { PlanEnum, ISetupRestaurant } from "../interface/plan.interface";
import { PlanEnum, ISetupRestaurant, IExternalApiResponse } from "../interface/plan.interface";
import { SubscriptionsService } from "../../subscriptions/providers/subscriptions.service";
import { SubscriptionMessage } from "../../../common/enums/message.enum";
@@ -55,7 +55,7 @@ export class RestaurantService {
const { data } = await firstValueFrom(
this.httpService
.get(`${this.config.baseUrl}/super-admin/restaurants`, {
.get<IExternalApiResponse<any[]>>(`${this.config.baseUrl}/super-admin/restaurants`, {
params,
headers: this.getHeaders(),
})
@@ -66,7 +66,11 @@ export class RestaurantService {
}),
),
);
return data;
return {
restaurants: data.data,
count: data.meta.total,
paginate: true,
};
} catch (error: unknown) {
if (error instanceof AxiosError && error.response) {
this.logger.error(`External API error response:`, error.response.data);
@@ -331,4 +335,36 @@ export class RestaurantService {
throw error;
}
}
async upgradeSubscription(subscriptionId: string, newPlan: string, subscriptionEndDate: string) {
try {
const { data } = await firstValueFrom(
this.httpService
.patch(`${this.config.baseUrl}/super-admin/restaurants/subscription/${subscriptionId}/upgrade`, {
plan: newPlan,
subscriptionEndDate,
}, {
headers: this.getHeaders(),
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error(`Failed to upgrade restaurant subscription: ${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 upgrading restaurant subscription: ${error instanceof Error ? error.message : "Unknown error"}`);
throw error;
}
}
}