mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-14 11:58:13 +00:00
Update studentClient.ts
This commit is contained in:
parent
fb45ed5f08
commit
5997f0dd78
1 changed files with 31 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import { API_BASE_STUDENT, BASE_URL } from "../utils/consts.ts";
|
import { API_BASE_STUDENT, BASE_URL } from "../utils/consts.ts";
|
||||||
import { BaseClient } from "./baseClient.ts";
|
import { BaseClient } from "./baseClient.ts";
|
||||||
import { parseCookies } from "../utils/utils.ts";
|
import { parseCookies } from "../utils/utils.ts";
|
||||||
|
import { RewardPurchaseResponse, RewardsResponse } from "../types.ts"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Student Client
|
* Student Client
|
||||||
|
|
@ -58,4 +59,34 @@ export class StudentClient extends BaseClient {
|
||||||
const user = await this.getStudentInfo();
|
const user = await this.getStudentInfo();
|
||||||
this.studentId = user.data.user.id;
|
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}`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue