mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-14 11:58:13 +00:00
feat: reward shop methods, get pupil fields and add meta on detentions (#35)
This commit is contained in:
parent
936057bbd4
commit
41f23e01d0
3 changed files with 105 additions and 5 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { API_BASE_STUDENT, BASE_URL } from "~/src/utils/consts.ts";
|
||||
import { BaseClient } from "~/src/core/baseClient.ts";
|
||||
import { parseCookies } from "~/src/utils/utils.ts";
|
||||
import { RewardPurchaseResponse, RewardsResponse } from "~/src/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 purchaseReward(itemId: number): Promise<RewardPurchaseResponse> {
|
||||
return (
|
||||
await this.makeAuthedRequest(
|
||||
this.API_BASE + "/purchase/" + itemId,
|
||||
{
|
||||
method: "POST",
|
||||
body: `pupil_id=${this.studentId}`,
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue