Skip to content

Commit

Permalink
🔧 feat(frontend): Change frontend to send proper requests to adapted …
Browse files Browse the repository at this point in the history
…membership-service
  • Loading branch information
orazefabian committed May 13, 2024
1 parent f3d3bb7 commit 5cf0513
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
28 changes: 23 additions & 5 deletions src/frontend/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const adManagerRouter = require('./controller/adManager');
const cheerio = require('cheerio');
const express = require('express');
const router = express.Router();
const querystring = require("querystring");

// Global Timeline route
router.get('/', showGlobalTimeline);
Expand Down Expand Up @@ -373,11 +374,28 @@ function unlikePost(req, res) {
}

function postMembership(req, res) {
const membership = {userid: getJwtUserId(req.cookies), membership: req.body.membershipText};
fetchUsingDeploymentBase(req, () => req.MEMBERSHIP_SERVICE_API.post('/', membership)).then((response) => {
res.redirect(extendURL(`/user/${getJwtUser(req.cookies)}`));
}, (error) => res.status(statusCodeForError(error)).render('error.njk', handleError(error)));

const formData = {
membership: req.body.membershipText,
};
fetchUsingDeploymentBase(req, () =>
req.MEMBERSHIP_SERVICE_API.post(
`/add/${getJwtUserId(req.cookies)}`,
querystring.stringify(formData),
{
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
}
)
).then(
(response) => {
res.redirect(extendURL(`/user/${getJwtUser(req.cookies)}`));
},
(error) =>
res
.status(statusCodeForError(error))
.render("error.njk", handleError(error))
);
}

function postBio(req, res) {
Expand Down
5 changes: 3 additions & 2 deletions src/frontend/views/membership.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{#
{#
Copyright 2023 Dynatrace LLC
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -48,6 +48,7 @@ limitations under the License.
</ul>
</div>
</div>
</div>
</div>

<form method="post">
Expand All @@ -66,6 +67,6 @@ limitations under the License.
Update membership plan
</button>
</div>
</post>
</form>
</div>
{% endblock %}

0 comments on commit 5cf0513

Please sign in to comment.