Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Commit 7cadf54

Browse files
committed
feat: stubs for data providers
1 parent 49589b5 commit 7cadf54

File tree

5 files changed

+86
-3
lines changed

5 files changed

+86
-3
lines changed

apps/client/src/interfaces/DataProvider.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ export type Notice<TAudience> = {
2626
};
2727

2828
// Fetch output must be serialisable to JSON
29-
export interface DataProvider<TAudience> {
29+
export interface DataProvider<TAudience = never> {
3030
activate(): void;
3131
deactivate(): void;
3232
isActivated(): boolean;
3333

3434
config: {
3535
name: LongOrShortString;
36-
description: LongOrShortString;
36+
description: string;
3737
};
3838

3939
barcode?: {
@@ -58,6 +58,7 @@ export interface DataProvider<TAudience> {
5858
};
5959

6060
newsletter?: {
61-
newsletterDownloadUrl: string;
61+
downloadUrl: string;
62+
name: string;
6263
};
6364
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { NoticeYear } from "../../../consumers/sbhsApi/schemas";
2+
import { DataProvider, Notice, Period } from "../../../interfaces/DataProvider";
3+
import { DateTime } from "luxon";
4+
5+
export class SbhsDataProvider implements DataProvider<NoticeYear> {
6+
activate(): void {
7+
throw new Error("Method not implemented.");
8+
}
9+
deactivate(): void {
10+
throw new Error("Method not implemented.");
11+
}
12+
isActivated(): boolean {
13+
throw new Error("Method not implemented.");
14+
}
15+
16+
config = {
17+
name: { short: "SBHS", long: "SBHS Student Portal" },
18+
description: "Accesses timetable and notices from the SBHS Student Portal.",
19+
};
20+
21+
barcode?:
22+
| { fetch: () => Promise<unknown>; parse: (data: unknown) => string }
23+
| undefined;
24+
25+
dtt?:
26+
| {
27+
fetch: (date: DateTime) => Promise<unknown>;
28+
parse: (data: unknown) => Period[];
29+
}
30+
| undefined;
31+
32+
cycle?:
33+
| { fetch: () => Promise<unknown>; parse: (data: unknown) => Period[] }
34+
| undefined;
35+
36+
notices?:
37+
| {
38+
fetch: () => Promise<unknown>;
39+
parse: (data: unknown) => Notice<NoticeYear>[];
40+
}
41+
| undefined;
42+
43+
newsletter = { downloadUrl: "https://sbhs.co/hnpdf", name: "High Notes" };
44+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { SbhsDataProvider } from "./SbhsDataProvider";
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { DataProvider } from "../../../interfaces/DataProvider";
2+
import { z } from "zod";
3+
4+
export class TestDataProvider implements DataProvider {
5+
private activated = false;
6+
7+
activate = () => {
8+
this.activated = true;
9+
};
10+
11+
deactivate = () => {
12+
this.activated = false;
13+
};
14+
15+
isActivated = () => this.activated;
16+
17+
config = {
18+
name: { short: "Test" },
19+
description: "Test",
20+
};
21+
22+
// Example implentation of fetch and parse
23+
barcode = {
24+
fetch: async () => ({
25+
barcode: "Test Barcode", // In reality, this would be fetched from the API
26+
}),
27+
28+
parse: (data: unknown) => {
29+
const barcodeSchema = z.object({
30+
barcode: z.string(),
31+
});
32+
const { barcode } = barcodeSchema.parse(data);
33+
34+
return barcode;
35+
},
36+
};
37+
}

apps/client/src/services/dataProviders/TestDataProvider/index.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)