Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

last event support passion list #102

Merged
merged 2 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/server-extension/query/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GROUP BY ce.id, DATE(e.timestamp)
ORDER BY DATE(e.timestamp)`


export const lastEventQuery = `SELECT
export const lastEventQuery = (whereCondition: string) => `SELECT
DISTINCT ne.id as id,
ne.name as name,
ne.issuer as issuer,
Expand All @@ -35,6 +35,7 @@ FROM event e
WHERE
e.interaction = $1
AND ne.burned = false
${whereCondition}
GROUP BY ne.id, me.id, e.current_owner, me.image
ORDER BY MAX(e.timestamp) DESC
LIMIT $2 OFFSET $3`
9 changes: 7 additions & 2 deletions src/server-extension/resolvers/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { EntityManager } from 'typeorm'
import { NFTEntity } from '../../model/generated'
import { LastEventEntity } from '../model/event.model'
import { lastEventQuery } from '../query/event'
import { makeQuery } from "../utils";
import { makeQuery, toSqlInParams } from "../utils";
import { Interaction } from '../../model'

@Resolver()
Expand All @@ -13,10 +13,15 @@ export class EventResolver {
@Query(() => [LastEventEntity])
async lastEvent(
@Arg('interaction', { nullable: true, defaultValue: Interaction.LIST }) interaction: Interaction,
@Arg('passionList', () => [String!], { nullable: true }) passionList: string[],
@Arg('limit', { nullable: true, defaultValue: 20 }) limit: number,
@Arg('offset', { nullable: true, defaultValue: 0 }) offset: number,
): Promise<[LastEventEntity]> {
const result: [LastEventEntity] = await makeQuery(this.tx, NFTEntity, lastEventQuery, [interaction, limit, offset])

const selectFromPassionList = passionList && passionList.length > 0
? `AND ne.issuer in (${toSqlInParams(passionList)})`
: ''
const result: [LastEventEntity] = await makeQuery(this.tx, NFTEntity, lastEventQuery(selectFromPassionList), [interaction, limit, offset])
return result
}

Expand Down