Skip to content

Commit

Permalink
🔧 feat(frontend): Change frontend to send adapted POST requests to th…
Browse files Browse the repository at this point in the history
…e membership service
  • Loading branch information
orazefabian committed May 13, 2024
1 parent ace7b49 commit 6e22a44
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
38 changes: 28 additions & 10 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 @@ -71,7 +72,7 @@ function showGlobalTimeline(req, res) {
username: getJwtUser(req.cookies),
isAdManager: hasJwtRole(req.cookies, roles.AD_MANAGER),
baseData: baseRequestFactory.baseData,
membership: membership.data.membership
membership: membership.data

}, req);
res.render('index.njk', data)
Expand Down Expand Up @@ -109,7 +110,7 @@ function showUsers(req, res) {
username: getJwtUser(req.cookies),
isAdManager: hasJwtRole(req.cookies, roles.AD_MANAGER),
baseData: baseRequestFactory.baseData,
membership: membership.data.membership
membership: membership.data

}, req);
res.render('users.njk', data);
Expand All @@ -130,7 +131,7 @@ function showPersonalTimeline(req, res) {
username: getJwtUser(req.cookies),
isAdManager: hasJwtRole(req.cookies, roles.AD_MANAGER),
baseData: baseRequestFactory.baseData,
membership: membership.data.membership
membership: membership.data
}, req);
res.render('index.njk', data);
}, (err) => displayError(err, res))
Expand All @@ -154,7 +155,7 @@ function showUserProfile(req, res) {
isAdManager: hasJwtRole(req.cookies, roles.AD_MANAGER),
bio: bioText,
baseData: baseRequestFactory.baseData,
membership: membership.data.membership
membership: membership.data
}, req);

res.render('profile.njk', data);
Expand Down Expand Up @@ -189,7 +190,7 @@ function showMembership(req, res) {
username: getJwtUser(req.cookies),
isAdManager: hasJwtRole(req.cookies, roles.AD_MANAGER),
baseData: baseRequestFactory.baseData,
membership: membership.data.membership
membership: membership.data
}, req);

res.render('membership.njk', data);
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 6e22a44

Please sign in to comment.