Skip to content

Commit

Permalink
[TASK] added load all matches endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisBurger committed Jan 22, 2022
1 parent 7d4c6bb commit 39e72b8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/http/responses/LoadAllMatchesResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {MatchInterface} from '../../models/Match';

export interface LoadAllMatchesResponse {
data: {
next_page_token?: string;
matches: MatchInterface[];
};
}
23 changes: 23 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

import HttpService from './http/HttpService';
import { FastMatchTeaserResponse } from './http/responses/FastMatchTeaserResponse';
import { LoadAllMatchesResponse } from './http/responses/LoadAllMatchesResponse';
import { Recommendations } from './http/responses/Recommendations';
import Update, { UpdateInterface } from './http/responses/Update';
import LikePreview from './models/LikePreview';
import Match from './models/Match';
import User from './models/User';

export interface TinderJsConfig {
Expand Down Expand Up @@ -95,6 +97,27 @@ class TinderJS {
return (await this.HttpClient.get<FastMatchTeaserResponse>('/v2/fast-match/teasers'))
.data.results.map(preview => new LikePreview(preview.user));
}

/**
* Fetches all matches from the Tinder API
*
* @param {(string|null)} [pageToken=null] The pageToken of the next page
* @param {number} [count=60] The count of entries
* @return {*} {Promise<Match[]>} All matches
* @memberof TinderJS
*/
public async loadAllMatches(pageToken: string|null = null, count = 60): Promise<Match[]> {
let route = `/v2/matches?count=${count}`;
if (pageToken) {
route = `${route}&page_token=${pageToken}`;
}
const data = (await this.HttpClient.get<LoadAllMatchesResponse>(route)).data;
const matches: Match[] = data.matches.map(match => new Match(match));
if (data.next_page_token) {
matches.concat(await this.loadAllMatches(data.next_page_token));
}
return matches;
}
}

export default TinderJS;

0 comments on commit 39e72b8

Please sign in to comment.