Skip to content

Commit 78dc8e0

Browse files
authored
Merge pull request #318 from TaloDev/feedback-dev-data-filter
Add dev data filter to feedback index endpoint
2 parents 6956a34 + 3483f41 commit 78dc8e0

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/services/game-feedback.service.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import GameFeedbackPolicy from '../policies/game-feedback.policy'
55
import GameFeedbackCategory from '../entities/game-feedback-category'
66
import createGameActivity from '../lib/logging/createGameActivity'
77
import { GameActivityType } from '../entities/game-activity'
8+
import { devDataPlayerFilter } from '../middlewares/dev-data-middleware'
89

910
const itemsPerPage = 50
1011

@@ -40,14 +41,14 @@ export default class GameFeedbackService extends Service {
4041
const { feedbackCategoryInternalName, search, page } = req.query
4142
const em: EntityManager = req.ctx.em
4243

43-
let query = em.qb(GameFeedback, 'gf')
44+
const query = em.qb(GameFeedback, 'gf')
4445
.select('gf.*')
4546
.orderBy({ createdAt: QueryOrder.DESC })
4647
.limit(itemsPerPage)
4748
.offset(Number(page) * itemsPerPage)
4849

4950
if (feedbackCategoryInternalName) {
50-
query = query
51+
query
5152
.andWhere({
5253
category: {
5354
internalName: feedbackCategoryInternalName
@@ -56,7 +57,7 @@ export default class GameFeedbackService extends Service {
5657
}
5758

5859
if (search) {
59-
query = query.andWhere({
60+
query.andWhere({
6061
$or: [
6162
{ comment: { $like: `%${search}%` } },
6263
{
@@ -69,6 +70,14 @@ export default class GameFeedbackService extends Service {
6970
})
7071
}
7172

73+
if (!req.ctx.state.includeDevData) {
74+
query.andWhere({
75+
playerAlias: {
76+
player: devDataPlayerFilter(em)
77+
}
78+
})
79+
}
80+
7281
const [feedback, count] = await query
7382
.andWhere({
7483
category: {

tests/services/game-feedback/index.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,21 @@ describe('Game feedback service - index', () => {
217217

218218
expect(res.body.feedback).toHaveLength(feedbackWithRelevantCategoryAndAlias.length)
219219
})
220+
221+
it('should not return feedback from dev build players if the dev data header is not set', async () => {
222+
const [organisation, game] = await createOrganisationAndGame()
223+
const [token] = await createUserAndToken({}, organisation)
224+
225+
const player = await new PlayerFactory([game]).state('dev build').one()
226+
const feedback = await new GameFeedbackFactory(game).with(() => ({ playerAlias: player.aliases[0] })).many(10)
227+
await (<EntityManager>global.em).persistAndFlush(feedback)
228+
229+
const res = await request(global.app)
230+
.get(`/games/${game.id}/game-feedback`)
231+
.query({ page: 0 })
232+
.auth(token, { type: 'bearer' })
233+
.expect(200)
234+
235+
expect(res.body.feedback).toHaveLength(0)
236+
})
220237
})

0 commit comments

Comments
 (0)