Skip to content

Commit 80e05a4

Browse files
authored
fix: correctly modify updated field on punishment updates (#1703)
1 parent 47e8ff7 commit 80e05a4

8 files changed

Lines changed: 41 additions & 14 deletions

server/graphql/resolvers/mutations/resolve-appeal-update-ban.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = async function resolveAppealUpdateBan (obj, { id, input }, { se
3333
let commentId
3434

3535
await server.pool.transaction(async trx => {
36-
await trx(server.config.tables.playerBans).update({ expires: input.expires, reason: input.reason }).where({ id: data.punishment_id })
36+
await trx(server.config.tables.playerBans).update({ expires: input.expires, reason: input.reason, updated: trx.raw('UNIX_TIMESTAMP()') }).where({ id: data.punishment_id })
3737

3838
return await state.dbPool.transaction(async trx => {
3939
const comment = {

server/graphql/resolvers/mutations/resolve-appeal-update-mute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = async function resolveAppealUpdateMute (obj, { id, input }, { s
3333
let commentId
3434

3535
await server.pool.transaction(async trx => {
36-
await trx(server.config.tables.playerMutes).update({ expires: input.expires, reason: input.reason, soft: input.soft ? 1 : 0 }).where({ id: data.punishment_id })
36+
await trx(server.config.tables.playerMutes).update({ expires: input.expires, reason: input.reason, soft: input.soft ? 1 : 0, updated: trx.raw('UNIX_TIMESTAMP()') }).where({ id: data.punishment_id })
3737

3838
return await state.dbPool.transaction(async trx => {
3939
const comment = {

server/graphql/resolvers/mutations/update-player-ban.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ module.exports = async function updatePlayerBan (obj, { id, serverId, input }, {
66

77
if (!server) throw new ExposedError('Server does not exist')
88

9-
let data = await playerBan(obj, { id, serverId }, { state }, info)
9+
const data = await playerBan(obj, { id, serverId }, { state }, info)
1010

1111
if (!data) throw new ExposedError(`Player ban ${id} does not exist`)
1212

1313
const table = server.config.tables.playerBans
14-
const updateData = { expires: input.expires, reason: input.reason }
1514

16-
await server.pool(table).update(updateData).where({ id })
15+
await server.pool(table).update({
16+
expires: input.expires,
17+
reason: input.reason,
18+
updated: server.pool.raw('UNIX_TIMESTAMP()')
19+
}).where({ id })
1720

18-
data = { ...data, ...updateData }
19-
20-
return data
21+
return playerBan(obj, { id, serverId }, { state }, info)
2122
}

server/graphql/resolvers/mutations/update-player-mute.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ module.exports = async function updatePlayerMute (obj, { id, serverId, input },
66

77
if (!server) throw new ExposedError('Server does not exist')
88

9-
let data = await playerMute(obj, { id, serverId }, { state }, info)
9+
const data = await playerMute(obj, { id, serverId }, { state }, info)
1010

1111
if (!data) throw new ExposedError(`Player mute ${id} does not exist`)
1212

1313
const table = server.config.tables.playerMutes
14-
const updateData = { soft: input.soft ? 1 : 0, expires: input.expires, reason: input.reason }
1514

16-
await server.pool(table).update(updateData).where({ id })
15+
await server.pool(table).update({
16+
soft: input.soft ? 1 : 0,
17+
expires: input.expires,
18+
reason: input.reason,
19+
updated: server.pool.raw('UNIX_TIMESTAMP()')
20+
}).where({ id })
1721

18-
data = { ...data, ...updateData }
19-
20-
return data
22+
return playerMute(obj, { id, serverId }, { state }, info)
2123
}

server/test/resolveAppealUpdateBan.mutation.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ describe('Mutation resolveAppealUpdateBan', () => {
5656
await pool('bm_players').insert(player)
5757

5858
const [id] = await pool('bm_player_bans').insert(punishment, ['id'])
59+
const [originalBan] = await pool('bm_player_bans').where({ id })
60+
const originalUpdated = originalBan.updated
61+
5962
const data = createAppeal({ ...punishment, id }, 'PlayerBan', server, player)
6063
const [inserted] = await pool('bm_web_appeals').insert(data, ['id'])
6164
const appealRole = await setTempRole(setup.dbPool, account, 'player.appeals', 'update.state.any', 'view.any')
@@ -110,6 +113,9 @@ describe('Mutation resolveAppealUpdateBan', () => {
110113
assert.strictEqual(body.data.resolveAppealUpdateBan.comment.newReason, 'test')
111114
assert.strictEqual(body.data.resolveAppealUpdateBan.comment.oldExpires, punishment.expires)
112115
assert.strictEqual(body.data.resolveAppealUpdateBan.comment.newExpires, 1000000000)
116+
117+
const [updatedBan] = await pool('bm_player_bans').where({ id })
118+
assert(updatedBan.updated >= originalUpdated, 'updated timestamp should be updated')
113119
})
114120

115121
test('should allow update.state.own', async () => {

server/test/resolveAppealUpdateMute.mutation.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ describe('Mutation resolveAppealUpdateMute', () => {
5656
await pool('bm_players').insert(player)
5757

5858
const [id] = await pool('bm_player_mutes').insert(punishment, ['id'])
59+
const [originalMute] = await pool('bm_player_mutes').where({ id })
60+
const originalUpdated = originalMute.updated
61+
5962
const data = createAppeal({ ...punishment, id }, 'PlayerMute', server, player)
6063
const [inserted] = await pool('bm_web_appeals').insert(data, ['id'])
6164
const appealRole = await setTempRole(setup.dbPool, account, 'player.appeals', 'update.state.any', 'view.any')
@@ -114,6 +117,9 @@ describe('Mutation resolveAppealUpdateMute', () => {
114117
assert.strictEqual(body.data.resolveAppealUpdateMute.comment.newExpires, 1000000000)
115118
assert.strictEqual(body.data.resolveAppealUpdateMute.comment.oldSoft, false)
116119
assert.strictEqual(body.data.resolveAppealUpdateMute.comment.newSoft, true)
120+
121+
const [updatedMute] = await pool('bm_player_mutes').where({ id })
122+
assert(updatedMute.updated >= originalUpdated, 'updated timestamp should be updated')
117123
})
118124

119125
test('should allow update.state.own', async () => {

server/test/updatePlayerBan.mutation.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ describe('Mutation update player ban', () => {
9898
await pool('bm_players').insert([player, actor])
9999
const [inserted] = await pool('bm_player_bans').insert(ban, ['id'])
100100

101+
const [originalBan] = await pool('bm_player_bans').where({ id: inserted })
102+
const originalUpdated = originalBan.updated
103+
101104
const { body, statusCode } = await request
102105
.post('/graphql')
103106
.set('Cookie', cookie)
@@ -139,5 +142,8 @@ describe('Mutation update player ban', () => {
139142
assert.strictEqual(body.data.updatePlayerBan.reason, 'testing updates')
140143
assert.strictEqual(body.data.updatePlayerBan.expires, 1000000000)
141144
assert.deepStrictEqual(body.data.updatePlayerBan.acl, { delete: true, update: true, yours: false })
145+
146+
const [updatedBan] = await pool('bm_player_bans').where({ id: inserted })
147+
assert(updatedBan.updated >= originalUpdated, 'updated timestamp should be updated')
142148
})
143149
})

server/test/updatePlayerMute.mutation.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ describe('Mutation update player mute', () => {
9898
await pool('bm_players').insert([player, actor])
9999
const [inserted] = await pool('bm_player_mutes').insert(mute, ['id'])
100100

101+
const [originalMute] = await pool('bm_player_mutes').where({ id: inserted })
102+
const originalUpdated = originalMute.updated
103+
101104
const { body, statusCode } = await request
102105
.post('/graphql')
103106
.set('Cookie', cookie)
@@ -142,5 +145,8 @@ describe('Mutation update player mute', () => {
142145
assert.strictEqual(body.data.updatePlayerMute.expires, 1000000000)
143146
assert.strictEqual(body.data.updatePlayerMute.soft, false)
144147
assert.deepStrictEqual(body.data.updatePlayerMute.acl, { delete: true, update: true, yours: false })
148+
149+
const [updatedMute] = await pool('bm_player_mutes').where({ id: inserted })
150+
assert(updatedMute.updated >= originalUpdated, 'updated timestamp should be updated')
145151
})
146152
})

0 commit comments

Comments
 (0)