Skip to content

Commit

Permalink
feat(api,ui): 🎸 filter by platform
Browse files Browse the repository at this point in the history
✅ Closes: #520
  • Loading branch information
andrew-codes committed Sep 27, 2024
1 parent e3439d1 commit 8adfa23
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,15 @@ export const filterItems: NonNullable<QueryResolvers['filterItems']> = async (
field: 'releaseYear',
})

const platforms = await _ctx.api.platform.getAll()
filterItems.push({
name: 'Platform',
allowedValues: platforms.map((platform) => ({
value: platform.id,
display: platform.name,
})),
field: 'platform.id',
})

return filterItems
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash'
import type { QueryResolvers } from '../../../../../../../.generated/types.generated'
import { GameEntity } from '../../../../resolverTypes'

const { merge } = _
const { get, merge } = _
const exactMatch = /(".*")|('.*')/

export const games: NonNullable<QueryResolvers['games']> = async (
Expand Down Expand Up @@ -45,7 +45,7 @@ export const games: NonNullable<QueryResolvers['games']> = async (
}

return game.releases.some((release) => {
const gameValue = release[filterItem.field]
const gameValue = get(release, filterItem.field)
if (gameValue === undefined) {
return false
}
Expand Down
13 changes: 3 additions & 10 deletions apps/playnite-web/src/server/graphql/modules/platform/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,12 @@ function create(this: DomainApi) {
)

return ids.map((id) =>
results[id] ? omit(results[id], '_id') : null,
results[id] ? results[id] : null,
) as Array<PlatformEntity>
})

return autoBind(this, {
async getById(this: DomainApi, id: string) {
if (id === '00000000-0000-0000-0000-000000000000') {
return {
id: '00000000-0000-0000-0000-000000000000',
name: 'Unknown',
}
}

return loader.load(id)
},
async getAll(this: DomainApi) {
Expand All @@ -41,15 +34,15 @@ function create(this: DomainApi) {
.find()
.toArray()

return items.map((item) => omit(item, ['_id'])) as Array<PlatformEntity>
return items as Array<PlatformEntity>
},
async getBy(this: DomainApi, query: Filter<Document>) {
const items = await (await this.db())
.collection<PlatformDbEntity>('platform')
.find(query)
.toArray()

return items.map((item) => omit(item, ['_id'])) as Array<PlatformEntity>
return items as Array<PlatformEntity>
},
})
}
Expand Down
17 changes: 12 additions & 5 deletions libs/mqtt-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ const createConnectedMqttClient = async (
debug(
`Existing MQTT client not found; creating one with the following options: host=${host}, port=${port}, username=${username}`,
)
const mqttClient = await connectAsync(`tcp://${host}`, {
password,
port,
username,
})
let mqttClient
if (username && password) {
mqttClient = await connectAsync(`tcp://${host}`, {
password,
port,
username,
})
} else {
mqttClient = await connectAsync(`tcp://${host}`, {
port,
})
}
debug('MQTT client connected')

return mqttClient
Expand Down

0 comments on commit 8adfa23

Please sign in to comment.