mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
refactor(backend): allow to set selected badge-slot to null (#8421)
* allow to set selected badgeslot to null Free a specific badge slot by setting it to null * Update backend/src/schema/resolvers/users.ts Co-authored-by: Wolfgang Huß <wolle.huss@pjannto.com> --------- Co-authored-by: Wolfgang Huß <wolle.huss@pjannto.com> Co-authored-by: Max <maxharz@gmail.com>
This commit is contained in:
parent
6b40a0dc59
commit
873cd6cd34
@ -252,6 +252,6 @@ type Mutation {
|
||||
# Get a JWT Token for the given Email and password
|
||||
login(email: String!, password: String!): String!
|
||||
|
||||
setTrophyBadgeSelected(slot: Int!, badgeId: ID!): User
|
||||
setTrophyBadgeSelected(slot: Int!, badgeId: ID): User
|
||||
resetTrophyBadgesSelected: User
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ const updateOnlineStatus = gql`
|
||||
`
|
||||
|
||||
const setTrophyBadgeSelected = gql`
|
||||
mutation ($slot: Int!, $badgeId: ID!) {
|
||||
mutation ($slot: Int!, $badgeId: ID) {
|
||||
setTrophyBadgeSelected(slot: $slot, badgeId: $badgeId) {
|
||||
badgeTrophiesCount
|
||||
badgeTrophiesSelected {
|
||||
@ -1294,6 +1294,53 @@ describe('setTrophyBadgeSelected', () => {
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
describe('set badge to null', () => {
|
||||
it('returns the user with no badge set on the selected slot', async () => {
|
||||
await mutate({
|
||||
mutation: setTrophyBadgeSelected,
|
||||
variables: { slot: 0, badgeId: 'trophy_bear' },
|
||||
})
|
||||
await mutate({
|
||||
mutation: setTrophyBadgeSelected,
|
||||
variables: { slot: 5, badgeId: 'trophy_panda' },
|
||||
})
|
||||
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: setTrophyBadgeSelected,
|
||||
variables: { slot: 5, badgeId: null },
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
data: {
|
||||
setTrophyBadgeSelected: {
|
||||
badgeTrophiesCount: 2,
|
||||
badgeTrophiesSelected: [
|
||||
{
|
||||
id: 'trophy_bear',
|
||||
},
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
badgeTrophiesUnused: [
|
||||
{
|
||||
id: 'trophy_panda',
|
||||
},
|
||||
],
|
||||
badgeTrophiesUnusedCount: 1,
|
||||
},
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -404,17 +404,25 @@ export default {
|
||||
const session = context.driver.session()
|
||||
|
||||
const query = session.writeTransaction(async (transaction) => {
|
||||
const result = await transaction.run(
|
||||
`
|
||||
const queryBadge = `
|
||||
MATCH (user:User {id: $userId})<-[:REWARDED]-(badge:Badge {id: $badgeId})
|
||||
OPTIONAL MATCH (user)-[badgeRelation:SELECTED]->(badge)
|
||||
OPTIONAL MATCH (user)-[slotRelation:SELECTED{slot: $slot}]->(:Badge)
|
||||
DELETE badgeRelation, slotRelation
|
||||
MERGE (user)-[:SELECTED{slot: toInteger($slot)}]->(badge)
|
||||
RETURN user {.*}
|
||||
`,
|
||||
{ userId, badgeId, slot },
|
||||
)
|
||||
`
|
||||
const queryNull = `
|
||||
MATCH (user:User {id: $userId})
|
||||
OPTIONAL MATCH (user)-[slotRelation:SELECTED {slot: $slot}]->(:Badge)
|
||||
DELETE slotRelation
|
||||
RETURN user {.*}
|
||||
`
|
||||
const result = await transaction.run(badgeId ? queryBadge : queryNull, {
|
||||
userId,
|
||||
badgeId,
|
||||
slot,
|
||||
})
|
||||
return result.records.map((record) => record.get('user'))[0]
|
||||
})
|
||||
try {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user