Skip to content

Commit

Permalink
add support for the events/:type/:code endpoint
Browse files Browse the repository at this point in the history
this is rarely used but came up in the context of Pres Evoker stats
  • Loading branch information
emallson committed Apr 14, 2024
1 parent ddb2f22 commit 2177e6d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/route/wcl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FastifyPluginAsync } from "fastify";
import fights from "./wcl/fights";
import events from "./wcl/events";
import events, { eventsByType } from "./wcl/events";
import tables from "./wcl/tables";
import graph from "./wcl/graph";
import parses from "./wcl/character-parses";
Expand All @@ -12,6 +12,7 @@ const wcl: FastifyPluginAsync = async (app) => {
app.register(cacheControl);
fights(app);
events(app);
eventsByType(app);
tables(app);
graph(app);
parses(app);
Expand Down
39 changes: 38 additions & 1 deletion src/route/wcl/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as api from "../../wcl/api";
import { gql } from "graphql-request";
import { compress, wrapEndpoint } from "./common";
import { ReportParams, camelCase, compress, wrapEndpoint } from "./common";

// TODO: migrate useAbilityIDs to true.
// requires frontend changes, but means we no longer need to compress the event response (probably)
Expand Down Expand Up @@ -89,3 +89,40 @@ const events = wrapEndpoint<EventsQuery>(
true,
);
export default events;

export const eventsByType = wrapEndpoint<EventsQuery, ReportParams & { type: string }>(
"/i/v1/report/events/:type/:code",
"wcl-events",
async (req) => {
const rawData = await api.query<
EventData,
{
code: string;
translate: boolean;
startTime: number;
endTime: number;
playerId?: number;
filter?: string;
type?: string;
}
>(eventQuery, {
type: req.params.type ? camelCase(req.params.type) : undefined,
code: req.params.code,
translate: req.query.translate !== "false",
startTime: Number(req.query.start),
endTime: Number(req.query.end),
playerId: req.query.actorid ? Number(req.query.actorid) : undefined,
filter: req.query.filter,
});
const { data: events, nextPageTimestamp } =
rawData.reportData.report.events;
const data = {
events: events,
nextPageTimestamp,
count: events.length,
};

return compress(JSON.stringify(data));
},
true,
);

0 comments on commit 2177e6d

Please sign in to comment.