Skip to content

Commit

Permalink
finalize this feature
Browse files Browse the repository at this point in the history
  • Loading branch information
beckpaul committed Dec 30, 2023
1 parent 466e1d0 commit ab7242b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
15 changes: 4 additions & 11 deletions src/backend/routes/views/clans/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,19 @@ exports = module.exports = [
try {
await req.requestContainer

Check warning on line 8 in src/backend/routes/views/clans/transfer.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/clans/transfer.js#L4-L8

Added lines #L4 - L8 were not covered by tests
.get('ClanManagementService')
.transferOwnership(newOwnerMemberId, clanId)
.transferOwnership(newOwnerMemberId)
await req.asyncFlash('info', 'Clan ownership transferred')

Check warning on line 11 in src/backend/routes/views/clans/transfer.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/clans/transfer.js#L11

Added line #L11 was not covered by tests

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/${clanId}`)

Check warning on line 13 in src/backend/routes/views/clans/transfer.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/clans/transfer.js#L13

Added line #L13 was not covered by tests
} catch (e) {
console.log('<==============HIT ERROR ==============>')
let message = e.toString()

Check warning on line 16 in src/backend/routes/views/clans/transfer.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/clans/transfer.js#L15-L16

Added lines #L15 - L16 were not covered by tests
if (e instanceof JavaApiError && e.error?.errors) {
message = e.error.errors[0].detail

Check warning on line 18 in src/backend/routes/views/clans/transfer.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/clans/transfer.js#L18

Added line #L18 was not covered by tests
}

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/${clanId}`)

Check warning on line 22 in src/backend/routes/views/clans/transfer.js

View check run for this annotation

Codecov / codecov/patch

src/backend/routes/views/clans/transfer.js#L21-L22

Added lines #L21 - L22 were not covered by tests
}
},
]
13 changes: 9 additions & 4 deletions src/backend/services/ClanManagementService.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ class ClanManagementService {
}
}

async transferOwnership(newOwnerMemberId, clanId) {
const newOwnerUser =
async transferOwnership(newOwnerMemberId) {

Check warning on line 39 in src/backend/services/ClanManagementService.js

View check run for this annotation

Codecov / codecov/patch

src/backend/services/ClanManagementService.js#L39

Added line #L39 was not covered by tests
const clanMembership =
await this.clanService.getClanMembership(newOwnerMemberId)

Check warning on line 41 in src/backend/services/ClanManagementService.js

View check run for this annotation

Codecov / codecov/patch

src/backend/services/ClanManagementService.js#L41

Added line #L41 was not covered by tests

const newOwnerMember = Object.values(clanMembership.members).find(
(member) => member.membershipId === newOwnerMemberId

Check warning on line 44 in src/backend/services/ClanManagementService.js

View check run for this annotation

Codecov / codecov/patch

src/backend/services/ClanManagementService.js#L43-L44

Added lines #L43 - L44 were not covered by tests
)

await this.clanManagementRepository.transferOwnership(

Check warning on line 47 in src/backend/services/ClanManagementService.js

View check run for this annotation

Codecov / codecov/patch

src/backend/services/ClanManagementService.js#L47

Added line #L47 was not covered by tests
newOwnerUser.id,
clanId
newOwnerMember.id,
clanMembership.clan_id
)
try {
this.clanService

Check warning on line 52 in src/backend/services/ClanManagementService.js

View check run for this annotation

Codecov / codecov/patch

src/backend/services/ClanManagementService.js#L51-L52

Added lines #L51 - L52 were not covered by tests
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 @@ -57,7 +57,7 @@ block content
href=`/clans/kick/${member.membershipId}`,
onclick='return confirm(\'Kick?\')'
) Kick
a#transfer-clan-ownership.action-link(
a.action-link(
href=`/clans/transfer/${member.membershipId}`,
onclick='return confirm(\'Transfer Clan Ownership?\')'
) Make Leader
Expand Down

0 comments on commit ab7242b

Please sign in to comment.