diff --git a/src/service/api/user/admin-api/routes.ts b/src/service/api/user/admin-api/routes.ts index 3199fe4a..4279cced 100644 --- a/src/service/api/user/admin-api/routes.ts +++ b/src/service/api/user/admin-api/routes.ts @@ -14,6 +14,7 @@ import GET_UserInfo, { GET_UserInfoValidator } from "../shared/user-info.get"; import GET_EditableFields from "./editable-fields.get"; import GET_Roles from "../shared/roles.get"; import PATCH_User, { PATCH_UserValidator } from "./user.patch"; +import GET_SubscriptionTiers from "../shared/subscription-tiers.get"; const AdminApiRouter = express.Router(); @@ -28,6 +29,7 @@ AdminApiRouter.post("/credits", ...DelegatedAuthFlow, POST_CreditsValidator, POS AdminApiRouter.post("/restrict", ...DelegatedAuthFlow, POST_RestrictValidator, POST_Restrict); AdminApiRouter.post("/verify", ...DelegatedAuthFlow, POST_VerifyValidator, POST_Verify); AdminApiRouter.post("/subscription", ...DelegatedAuthFlow, POST_SubscriptionValidator, POST_Subscription); +AdminApiRouter.get("/subscription-tiers", ...DelegatedAuthFlow, GET_SubscriptionTiers); AdminApiRouter.post("/create", ...DelegatedAuthFlow, POST_CreateValidator, POST_Create); AdminApiRouter.get("/list", ...DelegatedAuthFlow, GET_List); diff --git a/src/service/api/user/shared/subscription-tiers.get.ts b/src/service/api/user/shared/subscription-tiers.get.ts new file mode 100644 index 00000000..d5f29e1a --- /dev/null +++ b/src/service/api/user/shared/subscription-tiers.get.ts @@ -0,0 +1,29 @@ +import { Logger } from "../../../../singleton/logger"; +const log = Logger.getLogger().child({ from: "admin-api/editable-fields" }); + +import { Request, Response } from "express"; + +import { errorMessages, statusCodes } from "../../../../utils/http-status"; +import { ErrorResponse, SuccessResponse } from "../../../../utils/response"; +import { Configuration } from "../../../../singleton/configuration"; +import { ScopeManager } from "../../../../singleton/scope-manager"; + +const GET_SubscriptionTiers = async (_: Request, res: Response) => { + try { + if (!ScopeManager.isScopeAllowedForSharedSession(":configuration:read", res)) { + return; + } + const subscriptionTiersFromConfiguration = Configuration.get("user.subscription.tier-list"); + const subscriptionTiers = []; + for (let i = 0; i < subscriptionTiersFromConfiguration.length; i++) { + const tier = subscriptionTiersFromConfiguration[i]; + subscriptionTiers.push({ name: tier }); + } + res.status(statusCodes.success).json(new SuccessResponse({ subscriptionTiers: subscriptionTiers })); + } catch (err) { + log.error(err); + return res.status(statusCodes.internalError).json(new ErrorResponse(errorMessages.internalError)); + } +}; + +export default GET_SubscriptionTiers;