add limit query parameter for FeedApi, check other APIs for missing options

This commit is contained in:
Aarni Halinen
2021-04-08 23:07:04 +03:00
parent 5eef7cb015
commit 6007f44eb4
9 changed files with 52 additions and 15 deletions
+10 -2
View File
@@ -6,15 +6,23 @@ import { getAuthHeader } from "@utils/auth";
export const URL = `${process.env.NEXT_PUBLIC_API_URL}/feed/`;
export interface Options {
limit?: number;
offset?: number;
auth?: boolean;
}
class FeedApi {
static async getFeed(options: Options = {}): Promise<Post[]> {
const { auth } = options;
const {
limit, offset, auth,
} = options;
const params = {
limit,
offset,
};
const headers = auth ? { Authorization: getAuthHeader() } : null;
try {
const resp = await axios.get(URL, { headers });
const resp = await axios.get(URL, { params, headers });
return resp.data.results;
} catch (err) {
console.error(err);