1
0
Fork 0
mirror of https://github.com/classchartsapi/classcharts-api-js.git synced 2026-05-14 11:58:13 +00:00

feat: add rewards shop methods

This commit is contained in:
veloii 2023-09-15 19:51:46 +01:00
parent d39eda7bf3
commit 4d6c676376
2 changed files with 61 additions and 0 deletions

View file

@ -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<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}`
}
)
)
}
}

View file

@ -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<RewardsData, RewardsMeta>;
export interface RewardPurchaseData {
single_purchase: "yes" | "no";
order_id: number;
balence: number;
}
export type RewardPurchaseResponse = ClassChartsResponse<RewardPurchaseData, []>;