Skip to content

Commit

Permalink
transfer owner directly via userId
Browse files Browse the repository at this point in the history
  • Loading branch information
fcaps committed Dec 15, 2023
1 parent 466e1d0 commit 3836bb2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/backend/routes/views/clanRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ router.get(
require('./clans/kick')
)
router.get(
'/transfer/:memberId',
'/transfer/:userId',
middlewares.isAuthenticated(),
require('./clans/transfer')
)
Expand Down
29 changes: 16 additions & 13 deletions src/backend/routes/views/clans/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,34 @@ const { JavaApiError } = require('../../../services/ApiErrors')

exports = module.exports = [
async (req, res) => {
const newOwnerMemberId = req.params.memberId
const clanId = req.requestContainer.get('UserService').getUser().clan.id
if (!req.requestContainer.get('UserService').getUser()?.clan?.id) {
await req.asyncFlash('error', "You don't own a clan")

return res.redirect('/clans')
}

const newOwnerId = parseInt(req.params.userId)
try {
await req.requestContainer
.get('ClanManagementService')
.transferOwnership(newOwnerMemberId, clanId)
.transferOwnership(newOwnerId)
await req.asyncFlash('info', 'Clan ownership transferred')

return res.redirect(`/clans/view/${clanId}`, {
clan_tag: req.body.clan_tag,
clan_name: req.body.clan_name,
clan_description: req.body.clan_description,
})
return res.redirect(
'/clans/view/' +
req.requestContainer.get('UserService').getUser().clan.id
)
} catch (e) {
let message = e.toString()
if (e instanceof JavaApiError && e.error?.errors) {
message = e.error.errors[0].detail
}

await req.asyncFlash('error', message)
return res.redirect(`/clans/view/${clanId}`, {
clan_tag: req.body.clan_tag,
clan_name: req.body.clan_name,
clan_description: req.body.clan_description,
})
return res.redirect(
'/clans/view/' +
req.requestContainer.get('UserService').getUser().clan.id
)
}
},
]
8 changes: 3 additions & 5 deletions src/backend/services/ClanManagementService.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ class ClanManagementService {
}
}

async transferOwnership(newOwnerMemberId, clanId) {
const newOwnerUser =
await this.clanService.getClanMembership(newOwnerMemberId)
async transferOwnership(newOwnerId) {
await this.clanManagementRepository.transferOwnership(
newOwnerUser.id,
clanId
newOwnerId,
this.userService.getUser().clan.id
)
try {
this.clanService
Expand Down
2 changes: 1 addition & 1 deletion src/backend/templates/views/clans/clan.pug
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ block content
onclick='return confirm(\'Kick?\')'
) Kick
a#transfer-clan-ownership.action-link(
href=`/clans/transfer/${member.membershipId}`,
href=`/clans/transfer/${member.id}`,
onclick='return confirm(\'Transfer Clan Ownership?\')'
) Make Leader

Expand Down

0 comments on commit 3836bb2

Please sign in to comment.