1
0
Fork 0
mirror of https://github.com/classchartsapi/classcharts-api-js.git synced 2026-05-14 03:56:59 +00:00

Update studentClient.ts

This commit is contained in:
Veloi 2023-09-18 18:00:07 +01:00 committed by GitHub
parent fb45ed5f08
commit 5997f0dd78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
import { API_BASE_STUDENT, BASE_URL } from "../utils/consts.ts";
import { BaseClient } from "./baseClient.ts";
import { parseCookies } from "../utils/utils.ts";
import { RewardPurchaseResponse, RewardsResponse } from "../types.ts"
/**
* Student Client
@ -58,4 +59,34 @@ export class StudentClient extends BaseClient {
const user = await this.getStudentInfo();
this.studentId = user.data.user.id;
}
/**
* Gets the current student's rewards shop
* @returns Array of purchasable items
*/
async getRewards(): Promise<RewardsResponse> {
return (
await this.makeAuthedRequest(
this.API_BASE + "/rewards/" + this.studentId,
{
method: "GET",
},
)
);
}
/**
* Purchase a reward item from the current student's rewards shop
* @param itemId number
* @returns An object containg balence and id
*/
async postRewardPurchase(itemId: number): Promise<RewardPurchaseResponse> {
return (
await this.makeAuthedRequest(
this.API_BASE + "/purchase/" + itemId,
{
method: "POST",
body: `pupil_id=${this.studentId}`
}
)
)
}
}