Skip to content

Commit

Permalink
feat(api): enhance ProtocolService to include tags from config in API…
Browse files Browse the repository at this point in the history
… queries (#43)
  • Loading branch information
hugolxt authored Dec 18, 2024
1 parent 7a12049 commit 1f66aa4
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/api/services/protocol.service.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import config from "merkl.config";
import { api } from "../index.server";
import { fetchWithLogs } from "../utils";

export abstract class ProtocolService {
// ─── Get Many Protocols ──────────────────────────────────────────────

static async get(query: Parameters<typeof api.v4.protocols.index.get>[0]["query"]) {
return await ProtocolService.#fetch(async () => api.v4.protocols.index.get({ query }));
return await ProtocolService.#fetch(async () =>
api.v4.protocols.index.get({
query: Object.assign({ ...query }, config.tags?.[0] ? { tags: config.tags?.[0] } : {}),
}),
);
}

// ─── Get Many Protocols from request ──────────────────────────────────

static async getManyFromRequest(request: Request) {
const query = ProtocolService.#getQueryFromRequest(request);
const protocols = await ProtocolService.#fetch(async () => api.v4.protocols.index.get({ query }));
const count = await ProtocolService.#fetch(async () => api.v4.protocols.count.get({ query }));
const query: Parameters<typeof api.v4.protocols.index.get>[0]["query"] =
ProtocolService.#getQueryFromRequest(request);
const protocols = await ProtocolService.#fetch(async () =>
api.v4.protocols.index.get({
query: Object.assign({ ...query }, config.tags?.[0] ? { tags: config.tags?.[0] } : {}),
}),
);
const count = await ProtocolService.#fetch(async () =>
api.v4.protocols.count.get({
query: Object.assign({ ...query }, config.tags?.[0] ? { tags: config.tags?.[0] } : {}),
}),
);

return { protocols, count };
}
Expand Down

0 comments on commit 1f66aa4

Please sign in to comment.