diff --git a/backend/src/ee/controllers/v1/organizationsController.ts b/backend/src/ee/controllers/v1/organizationsController.ts index 1a19eef2d..b79379f29 100644 --- a/backend/src/ee/controllers/v1/organizationsController.ts +++ b/backend/src/ee/controllers/v1/organizationsController.ts @@ -36,6 +36,27 @@ export const getOrganizationPlan = async (req: Request, res: Response) => { }); } +/** + * Update the organization plan to product with id [productId] + * @param req + * @param res + * @returns + */ +export const updateOrganizationPlan = async (req: Request, res: Response) => { + const { + productId + } = req.body; + + const { data } = await licenseServerKeyRequest.patch( + `${await getLicenseServerUrl()}/api/license-server/v1/customers/${req.organization.customerId}/cloud-plan`, + { + productId + } + ); + + return res.status(200).send(data); +} + /** * Return the organization's payment methods on file */ diff --git a/backend/src/ee/routes/v1/organizations.ts b/backend/src/ee/routes/v1/organizations.ts index b41e49334..fd9fd08e9 100644 --- a/backend/src/ee/routes/v1/organizations.ts +++ b/backend/src/ee/routes/v1/organizations.ts @@ -25,6 +25,21 @@ router.get( organizationsController.getOrganizationPlan ); +router.patch( + '/:organizationId/plan', + requireAuth({ + acceptedAuthModes: ['jwt', 'apiKey'] + }), + requireOrganizationAuth({ + acceptedRoles: [OWNER, ADMIN, MEMBER], + acceptedStatuses: [ACCEPTED] + }), + param('organizationId').exists().trim(), + body('productId').exists().isString(), + validateRequest, + organizationsController.updateOrganizationPlan +); + router.get( '/:organizationId/billing-details/payment-methods', requireAuth({