diff --git a/src/core/baseClient.ts b/src/core/baseClient.ts index 8ba0286..79231ff 100644 --- a/src/core/baseClient.ts +++ b/src/core/baseClient.ts @@ -15,6 +15,8 @@ import type { GetStudentInfoResponse, HomeworksResponse, LessonsResponse, + RewardPurchaseResponse, + RewardsResponse, } from "../types.ts"; import { PING_INTERVAL } from "../utils/consts.ts"; @@ -302,4 +304,34 @@ export class BaseClient { ) ); } + /** + * Gets the current student's rewards shop + * @returns Array of purchasable items + */ + async getRewards(): Promise { + 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 { + return ( + await this.makeAuthedRequest( + this.API_BASE + "/purchase" + itemId, + { + method: "POST", + body: `pupil_id=${this.studentId}` + } + ) + ) + } } diff --git a/src/types.ts b/src/types.ts index 14d1a71..38ea625 100644 --- a/src/types.ts +++ b/src/types.ts @@ -435,3 +435,32 @@ export type AttendanceResponse = ClassChartsResponse< AttendanceData, AttendanceMeta >; + +export interface RewardsData { + id: number; + name: string; + description: string; + photo: string; + stock_control: boolean; + stock: number; + can_purchase: boolean; + unable_to_purchase_reason: string; + once_per_pupil: boolean; + purchased: boolean; + purchase_count: string; + price_balence_difference: number; +}[] + +export interface RewardsMeta { + pupil_score_balence: number; +} + +export type RewardsResponse = ClassChartsResponse; + +export interface RewardPurchaseData { + single_purchase: "yes" | "no"; + order_id: number; + balence: number; +} + +export type RewardPurchaseResponse = ClassChartsResponse;