Skip to content

Commit

Permalink
feat(server): added player payouts
Browse files Browse the repository at this point in the history
  • Loading branch information
foundrium committed Feb 19, 2022
1 parent 8eed75a commit 97dfbc2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
9 changes: 8 additions & 1 deletion examples/server/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dotenv/config';
import { Haste } from '@hastearcade/server';
import { Haste, HasteConfiguration } from '@hastearcade/server';
import { Player } from '@hastearcade/models';

async function initialize() {
// see Testing for more details
Expand All @@ -10,11 +11,17 @@ async function initialize() {
// Retrieve from Developer Portal
process.env.HASTE_SERVER_CLIENT_SECRET,
environment,
new HasteConfiguration(environment, 'api.foundrium.hastearcade.com', 'https', 443),
);

const leaderBoards = haste.game.leaderboards();
// eslint-disable-next-line no-console
console.log(leaderBoards);

const player = new Player(process.env.PLAYER_ID);
const payouts = await haste.game.payouts(player);
// eslint-disable-next-line no-console
console.log(JSON.stringify(payouts, null, 2));
}

async function run() {
Expand Down
5 changes: 3 additions & 2 deletions examples/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"start": "tsc index.tsx && node index.js"
},
"dependencies": {
"@hastearcade/models": "^1.3.1",
"@hastearcade/server": "1.5.3-next.1",
"dotenv": "^16.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/models/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export { TokenResponse } from './tokenResponse';
export { Leaderboard } from './leaderboard';
export { HasteEnvironment } from './hasteEnvironment';
export { TopScore } from './topScore';
export { Payout } from './payout';
18 changes: 18 additions & 0 deletions packages/models/src/models/payout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export class PayoutDetail {
userId: string;
createdAt: Date;
payeeHandle: string;
payerHandle: string;
paymentAmount: number;
}

export class PayoutEvent {
eventId: string;
details: PayoutDetail;
}

export class Payout {
startingAfter: string;
endingBefore: string;
events: PayoutEvent[];
}
12 changes: 11 additions & 1 deletion packages/server/src/api/resources/game/gameResource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreatePlay, Play, CreateScore, Score, Leaderboard, Game, Player, TopScore } from '@hastearcade/models';
import { CreatePlay, Play, CreateScore, Score, Leaderboard, Game, Player, TopScore, Payout } from '@hastearcade/models';
import { HasteConfiguration } from '../../../config/hasteConfiguration';
import { BaseResource } from '../baseResource';

Expand Down Expand Up @@ -49,4 +49,14 @@ export class GameResource extends BaseResource {
const result = await this.get<Leaderboard>(path);
return result.leaders;
}

async payouts(player: Player, startingAfter?: string, endingBefore?: string) {
const path = `/arcades/${this.configuration.arcadeId}/games/${this.configuration.gameId}/payouts/${
player.id
}?limit=1${startingAfter ? `&starting_after=${startingAfter}` : ''}${
endingBefore ? `&endingBefore=${endingBefore}` : ''
}`;
const result = await this.get<Payout>(path);
return result;
}
}

0 comments on commit 97dfbc2

Please sign in to comment.