@ominira/pomi-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"openapi":"3.0.0","info":{"version":"1.0.0","title":"Pomi","description":"This is the API"},"servers":[{"url":"","description":"POMI"}],"components":{"schemas":{"ProfessorEntity":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"_paths":{"type":"object","properties":{"entity":{"type":"string"}},"required":["entity"]}},"required":["id","name","_paths"],"additionalProperties":false},"ValidationError":{"type":"object","properties":{"message":{"type":"string"},"errors":{"type":"array","items":{"type":"object","properties":{"path":{"type":"array","items":{"type":"string"}},"message":{"type":"string"}},"required":["path","message"]}}},"required":["message","errors"]},"InstituteEntity":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"_paths":{"type":"object","properties":{"classes":{"type":"string"},"coursesOfferings":{"type":"string"},"courses":{"type":"string"}},"required":["classes","coursesOfferings","courses"]}},"required":["id","name","_paths"],"additionalProperties":false},"CourseEntity":{"type":"object","properties":{"id":{"type":"integer"},"code":{"type":"string"},"name":{"type":"string"},"credits":{"type":"integer"},"_paths":{"type":"object","properties":{"classes":{"type":"string"},"courseOfferings":{"type":"string"}},"required":["classes","courseOfferings"],"additionalProperties":false}},"required":["id","code","name","credits","_paths"],"additionalProperties":false},"ClassEntity":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"reservations":{"type":"array","items":{"type":"integer"}},"courseOfferingId":{"type":"integer"},"studyPeriodId":{"type":"integer"},"studyPeriodName":{"type":"string"},"courseId":{"type":"integer"},"courseCode":{"type":"string"},"instituteId":{"type":"integer"},"instituteName":{"type":"string"},"professors":{"type":"array","items":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"}},"required":["id","name"],"additionalProperties":false}},"_paths":{"type":"object","properties":{"studyPeriod":{"type":"string"},"institute":{"type":"string"},"course":{"type":"string"},"courseOffering":{"type":"string"},"class":{"type":"string"},"classSchedules":{"type":"string"},"professors":{"type":"string"}},"required":["studyPeriod","institute","course","courseOffering","class","classSchedules","professors"],"additionalProperties":false}},"required":["id","name","reservations","courseOfferingId","studyPeriodId","studyPeriodName","courseId","courseCode","instituteId","instituteName","professors","_paths"],"additionalProperties":false},"CourseOfferingEntity":{"type":"object","properties":{"id":{"type":"integer"},"instituteId":{"type":"integer"},"instituteName":{"type":"string"},"courseId":{"type":"integer"},"courseCode":{"type":"string"},"studyPeriodId":{"type":"integer"},"studyPeriodName":{"type":"string"},"_paths":{"type":"object","properties":{"entity":{"type":"string"},"institute":{"type":"string"},"studyPeriod":{"type":"string"},"course":{"type":"string"}},"required":["entity","institute","studyPeriod","course"]}},"required":["id","instituteId","instituteName","courseId","courseCode","studyPeriodId","studyPeriodName","_paths"],"additionalProperties":false},"DaysOfWeekEnum":{"type":"string","enum":["MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY","SUNDAY"]},"ClassScheduleEntity":{"type":"object","properties":{"id":{"type":"integer"},"dayOfWeek":{"$ref":"#/components/schemas/DaysOfWeekEnum"},"start":{"type":"string"},"end":{"type":"string"},"roomId":{"type":"integer"},"roomCode":{"type":"string"},"classId":{"type":"integer"},"className":{"type":"string"},"instituteId":{"type":"integer"},"instituteName":{"type":"string"},"courseId":{"type":"integer"},"courseCode":{"type":"string"},"courseOfferingId":{"type":"integer"},"periodId":{"type":"integer"},"periodName":{"type":"string"},"_paths":{"type":"object","properties":{"entity":{"type":"string"},"studyPeriod":{"type":"string"},"institute":{"type":"string"},"course":{"type":"string"},"courseOffering":{"type":"string"},"class":{"type":"string"}},"required":["entity","studyPeriod","institute","course","courseOffering","class"],"additionalProperties":false}},"required":["id","dayOfWeek","start","end","roomId","roomCode","classId","className","instituteId","instituteName","courseId","courseCode","courseOfferingId","periodId","periodName","_paths"],"additionalProperties":false},"StudyPeriodEntity":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"startDate":{"type":"string","format":"date"},"endDate":{"type":"string","format":"date"},"_paths":{"type":"object","properties":{"courseOfferings":{"type":"string"},"classes":{"type":"string"},"classSchedules":{"type":"string"}},"required":["courseOfferings","classes","classSchedules"]}},"required":["id","name","startDate","endDate","_paths"],"additionalProperties":false},"RoomEntity":{"type":"object","properties":{"id":{"type":"integer"},"code":{"type":"string"},"_paths":{"type":"object","properties":{"entity":{"type":"string"}},"required":["entity"]}},"required":["id","code","_paths"],"additionalProperties":false}},"parameters":{}},"paths":{"/professors":{"get":{"tags":["professor"],"parameters":[{"schema":{"type":"integer","nullable":true},"required":false,"name":"classId","in":"query"}],"responses":{"200":{"description":"A list of professors","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ProfessorEntity"}}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"500":{"description":"Internal server error"}}}},"/professors/{id}":{"get":{"tags":["professor"],"parameters":[{"schema":{"type":"integer"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"A professor by id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ProfessorEntity"}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"404":{"description":"Not found"},"500":{"description":"Internal server error"}}}},"/institutes":{"get":{"tags":["institute"],"responses":{"200":{"description":"A list of institutes","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/InstituteEntity"}}}}},"500":{"description":"Internal server error"}}}},"/institutes/{id}":{"get":{"tags":["institute"],"parameters":[{"schema":{"type":"integer"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"An institute by id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InstituteEntity"}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"404":{"description":"Not found"},"500":{"description":"Internal server error"}}}},"/courses":{"get":{"tags":["course"],"responses":{"200":{"description":"A list of courses","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/CourseEntity"}}}}},"500":{"description":"Internal server error"}}}},"/courses/{id}":{"get":{"tags":["course"],"parameters":[{"schema":{"type":"integer"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"A course by id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CourseEntity"}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"404":{"description":"Not found"},"500":{"description":"Internal server error"}}}},"/classes":{"get":{"tags":["class"],"parameters":[{"schema":{"type":"integer","nullable":true},"required":false,"name":"instituteId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"instituteName","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"courseId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"courseCode","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"periodId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"periodName","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"professorId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"professorName","in":"query"}],"responses":{"200":{"description":"A list of classes","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ClassEntity"}}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"500":{"description":"Internal server error"}}}},"/classes/{id}":{"get":{"tags":["class"],"parameters":[{"schema":{"type":"integer"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"A class","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClassEntity"}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"404":{"description":"Not found"},"500":{"description":"Internal server error"}}}},"/course-offerings":{"get":{"tags":["course-offering"],"parameters":[{"schema":{"type":"integer","nullable":true},"required":false,"name":"instituteId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"instituteCode","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"courseId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"courseCode","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"periodId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"periodName","in":"query"}],"responses":{"200":{"description":"A list of course offerings","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/CourseOfferingEntity"}}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"500":{"description":"Internal server error"}}}},"/course-offerings/{id}":{"get":{"tags":["course-offering"],"parameters":[{"schema":{"type":"integer"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"A course offering by id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CourseOfferingEntity"}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"404":{"description":"Not found"},"500":{"description":"Internal server error"}}}},"/class-schedules":{"get":{"tags":["class-schedule"],"parameters":[{"schema":{"type":"integer","nullable":true},"required":false,"name":"periodId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"periodName","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"instituteId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"instituteName","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"courseId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"courseCode","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"roomId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"roomCode","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"classId","in":"query"},{"schema":{"$ref":"#/components/schemas/DaysOfWeekEnum"},"required":false,"name":"dayOfWeek","in":"query"}],"responses":{"200":{"description":"A list of class schedules","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ClassScheduleEntity"}}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"500":{"description":"Internal server error"}}}},"/class-schedules/{id}":{"get":{"tags":["class-schedule"],"parameters":[{"schema":{"type":"integer"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"A class schedule by id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClassScheduleEntity"}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"404":{"description":"Not found"},"500":{"description":"Internal server error"}}}},"/study-periods":{"get":{"tags":["studyPeriod"],"responses":{"200":{"description":"A list of study periods","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/StudyPeriodEntity"}}}}},"500":{"description":"Internal server error"}}}},"/study-periods/{id}":{"get":{"tags":["studyPeriod"],"parameters":[{"schema":{"type":"integer","nullable":true},"required":false,"name":"id","in":"path"}],"responses":{"200":{"description":"A study period by id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/StudyPeriodEntity"}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"404":{"description":"Not found"},"500":{"description":"Internal server error"}}}},"/rooms":{"get":{"tags":["room"],"responses":{"200":{"description":"A list of rooms","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/RoomEntity"}}}}},"500":{"description":"Internal server error"}}}},"/rooms/{id}":{"get":{"tags":["room"],"parameters":[{"schema":{"type":"integer"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"A room by id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RoomEntity"}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"404":{"description":"Not found"},"500":{"description":"Internal server error"}}}}}}
package/src/result.ts ADDED
@@ -0,0 +1,12 @@
1
+ type Result<V, E> =
2
+ { data: V, error: never }
3
+ | { data: never, error: E }
4
+
5
+ function ResultOK<V, E>(data: V): Result<V, E> {
6
+ return { data, error: undefined as never };
7
+ }
8
+ function ResultErr<V, E>(error: E): Result<V, E> {
9
+ return { data: undefined as never, error };
10
+ }
11
+ export { ResultOK, ResultErr }
12
+ export type { Result }
@@ -0,0 +1,55 @@
1
+ import type { ClientType } from "../client";
2
+ import { invalidParamError as invalidParamError, serverError, unknownError, type PomiError } from "../errors";
3
+ import type { ClassScheduleEntitySchema } from "../models";
4
+ import type { paths } from "../openapi/specs";
5
+ import { ResultErr, ResultOK, type Result } from "../result";
6
+
7
+ type ListFilters = paths["/class-schedules"]["get"]["parameters"]["query"];
8
+
9
+ class ClassScheduleService {
10
+ constructor(private client: ClientType) { }
11
+ async get(classScheduleId: number): Promise<Result<ClassScheduleEntitySchema | null, PomiError>> {
12
+ if (false && !Number.isInteger(classScheduleId) || classScheduleId <= 0) {
13
+ return ResultErr(invalidParamError("Invalid class schedule ID", [
14
+ { path: ["classScheduleId"], message: "Must be a positive integer" }
15
+ ]))
16
+ }
17
+ const { data, error, response } = await this.client.GET(`/class-schedules/{id}`, {
18
+ params: {
19
+ path: {
20
+ id: classScheduleId,
21
+ }
22
+ }
23
+ });
24
+ if (error) {
25
+ if (response?.status === 404)
26
+ return ResultOK(null);
27
+ if (response?.status === 400)
28
+ return ResultErr(invalidParamError("Invalid class schedule ID", error.errors ?? [
29
+ { path: ["classScheduleId"], message: "Must be a positive integer" }
30
+ ], { originalError: error, response }));
31
+ if (response?.status === 500)
32
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
33
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
34
+ }
35
+ return ResultOK(data ?? null);
36
+ }
37
+ async list(listFilters?: ListFilters): Promise<Result<ClassScheduleEntitySchema[], PomiError>> {
38
+ const { data, error, response } = await this.client.GET(`/class-schedules`, {
39
+ params: {
40
+ query: listFilters,
41
+ }
42
+ });
43
+ if (response?.status === 400 )
44
+ return ResultErr(invalidParamError("Invalid query parameters", error?.errors ?? [], { originalError: error, response }));
45
+ if (response?.status != 200) {
46
+ if (response?.status === 500)
47
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
48
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
49
+ }
50
+ return ResultOK(data ?? []);
51
+ }
52
+ }
53
+
54
+ export default ClassScheduleService
55
+ export type { ListFilters as ClassScheduleListFilters }
@@ -0,0 +1,50 @@
1
+ import type { ClientType } from "../client";
2
+ import { invalidParamError, serverError, unknownError, type PomiError } from "../errors";
3
+ import type { ClassEntitySchema } from "../models";
4
+ import type { paths } from "../openapi/specs";
5
+ import { ResultErr, ResultOK, type Result } from "../result";
6
+
7
+ type ListFilters = paths["/classes"]["get"]["parameters"]["query"];
8
+
9
+ class ClassService {
10
+ constructor(private client: ClientType) { }
11
+ async get(classId: number): Promise<Result<ClassEntitySchema | null, PomiError>> {
12
+ const { data, error, response } = await this.client.GET(`/classes/{id}`, {
13
+ params: {
14
+ path: {
15
+ id: classId,
16
+ }
17
+ }
18
+ });
19
+ if (error) {
20
+ if (response?.status === 404)
21
+ return ResultOK(null);
22
+ if (response?.status === 400)
23
+ return ResultErr(invalidParamError("Invalid class ID", [
24
+ { path: ["classId"], message: "Must be a positive integer" }
25
+ ], { originalError: error, response }));
26
+ if (response?.status === 500)
27
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
28
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
29
+ }
30
+ return ResultOK(data ?? null);
31
+ }
32
+ async list(listFilters?: ListFilters): Promise<Result<ClassEntitySchema[], PomiError>> {
33
+ const { data, error, response } = await this.client.GET(`/classes`, {
34
+ params: {
35
+ query: listFilters,
36
+ }
37
+ });
38
+ if (error) {
39
+ if (response?.status === 400)
40
+ return ResultErr(invalidParamError("Invalid query parameters", error.errors ?? [], { originalError: error, response }));
41
+ if (response?.status === 500)
42
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
43
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
44
+ }
45
+ return ResultOK(data ?? []);
46
+ }
47
+ }
48
+
49
+ export default ClassService
50
+ export type { ListFilters as ClassListFilters }
@@ -0,0 +1,50 @@
1
+ import type { ClientType } from "../client";
2
+ import { invalidParamError, serverError, unknownError, type PomiError } from "../errors";
3
+ import type { CourseOfferingEntitySchema } from "../models";
4
+ import type { paths } from "../openapi/specs";
5
+ import { ResultErr, ResultOK, type Result } from "../result";
6
+
7
+ type ListFilters = paths["/course-offerings"]["get"]["parameters"]["query"];
8
+
9
+ class CourseOfferingService {
10
+ constructor(private client: ClientType) { }
11
+ async get(courseOfferingId: number): Promise<Result<CourseOfferingEntitySchema | null, PomiError>> {
12
+ const { data, error, response } = await this.client.GET(`/course-offerings/{id}`, {
13
+ params: {
14
+ path: {
15
+ id: courseOfferingId,
16
+ }
17
+ }
18
+ });
19
+ if (error) {
20
+ if (response?.status === 404)
21
+ return ResultOK(null);
22
+ if (response?.status === 400)
23
+ return ResultErr(invalidParamError("Invalid course offering ID", [
24
+ { path: ["courseOfferingId"], message: "Must be a positive integer" }
25
+ ], { originalError: error, response }));
26
+ if (response?.status === 500)
27
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
28
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
29
+ }
30
+ return ResultOK(data ?? null);
31
+ }
32
+ async list(listFilters?: ListFilters): Promise<Result<CourseOfferingEntitySchema[], PomiError>> {
33
+ const { data, error, response } = await this.client.GET(`/course-offerings`, {
34
+ params: {
35
+ query: listFilters,
36
+ }
37
+ });
38
+ if (error) {
39
+ if (response?.status === 400)
40
+ return ResultErr(invalidParamError("Invalid query parameters", error.errors ?? [], { originalError: error, response }));
41
+ if (response?.status === 500)
42
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
43
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
44
+ }
45
+ return ResultOK(data ?? []);
46
+ }
47
+ }
48
+
49
+ export default CourseOfferingService
50
+ export type { ListFilters as CourseOfferingListFilters }
@@ -0,0 +1,40 @@
1
+ import type { ClientType } from "../client";
2
+ import { invalidParamError, serverError, unknownError, type PomiError } from "../errors";
3
+ import type { CourseEntitySchema } from "../models";
4
+ import { ResultErr, ResultOK, type Result } from "../result";
5
+
6
+ class CourseService {
7
+ constructor(private client: ClientType) { }
8
+ async get(courseId: number): Promise<Result<CourseEntitySchema | null, PomiError>> {
9
+ const { data, error, response } = await this.client.GET(`/courses/{id}`, {
10
+ params: {
11
+ path: {
12
+ id: courseId,
13
+ }
14
+ }
15
+ });
16
+ if (error) {
17
+ if (response?.status === 404)
18
+ return ResultOK(null);
19
+ if (response?.status === 400)
20
+ return ResultErr(invalidParamError("Invalid course ID", [
21
+ { path: ["courseId"], message: "Must be a positive integer" }
22
+ ], { originalError: error, response }));
23
+ if (response?.status === 500)
24
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
25
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
26
+ }
27
+ return ResultOK(data ?? null);
28
+ }
29
+ async list(): Promise<Result<CourseEntitySchema[], PomiError>> {
30
+ const { data, error, response } = await this.client.GET(`/courses`, {});
31
+ if (error) {
32
+ if (response?.status === 500)
33
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
34
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
35
+ }
36
+ return ResultOK(data ?? []);
37
+ }
38
+ }
39
+
40
+ export default CourseService
@@ -0,0 +1,40 @@
1
+ import { type ClientType } from "../client";
2
+ import { invalidParamError, serverError, unknownError, type PomiError } from "../errors";
3
+ import type { InstituteEntitySchema } from "../models";
4
+ import { ResultErr, ResultOK, type Result } from "../result";
5
+
6
+ class InstituteService {
7
+ constructor(private client: ClientType) { }
8
+ async get(instituteId: number): Promise<Result<InstituteEntitySchema | null, PomiError>> {
9
+ const { data, error, response } = await this.client.GET(`/institutes/{id}`, {
10
+ params: {
11
+ path: {
12
+ id: instituteId,
13
+ }
14
+ }
15
+ });
16
+ if (error) {
17
+ if (response?.status === 404)
18
+ return ResultOK(null);
19
+ if (response?.status === 400)
20
+ return ResultErr(invalidParamError("Invalid institute ID", [
21
+ { path: ["instituteId"], message: "Must be a positive integer" }
22
+ ], { originalError: error, response }));
23
+ if (response?.status === 500)
24
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
25
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
26
+ }
27
+ return ResultOK(data ?? null);
28
+ }
29
+ async list(): Promise<Result<InstituteEntitySchema[], PomiError>> {
30
+ const { data, error, response } = await this.client.GET(`/institutes`, {});
31
+ if (error) {
32
+ if (response?.status === 500)
33
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
34
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
35
+ }
36
+ return ResultOK(data ?? []);
37
+ }
38
+ }
39
+
40
+ export default InstituteService
@@ -0,0 +1,50 @@
1
+ import type { ClientType } from "../client";
2
+ import { invalidParamError, serverError, unknownError, type PomiError } from "../errors";
3
+ import type { ProfessorEntitySchema } from "../models";
4
+ import type { paths } from "../openapi/specs";
5
+ import { ResultErr, ResultOK, type Result } from "../result";
6
+
7
+ type ListFilters = paths["/professors"]["get"]["parameters"]["query"];
8
+
9
+ class ProfessorService {
10
+ constructor(private client: ClientType) { }
11
+ async get(professorId: number): Promise<Result<ProfessorEntitySchema | null, PomiError>> {
12
+ const { data, error, response } = await this.client.GET(`/professors/{id}`, {
13
+ params: {
14
+ path: {
15
+ id: professorId,
16
+ }
17
+ }
18
+ });
19
+ if (error) {
20
+ if (response?.status === 404)
21
+ return ResultOK(null);
22
+ if (response?.status === 400)
23
+ return ResultErr(invalidParamError("Invalid professor ID", error.errors ?? [
24
+ { path: ["professorId"], message: "Must be a positive integer" }
25
+ ], { originalError: error, response }));
26
+ if (response?.status === 500)
27
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
28
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
29
+ }
30
+ return ResultOK(data ?? null);
31
+ }
32
+ async list(listFilters?: ListFilters): Promise<Result<ProfessorEntitySchema[], PomiError>> {
33
+ const { data, error, response } = await this.client.GET(`/professors`, {
34
+ params: {
35
+ query: listFilters,
36
+ }
37
+ });
38
+ if (error) {
39
+ if (response?.status === 400)
40
+ return ResultErr(invalidParamError("Invalid query parameters", error.errors ?? [], { originalError: error, response }));
41
+ if (response?.status === 500)
42
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
43
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
44
+ }
45
+ return ResultOK(data ?? []);
46
+ }
47
+ }
48
+
49
+ export default ProfessorService
50
+ export type { ListFilters as ProfessorListFilters }
@@ -0,0 +1,40 @@
1
+ import type { ClientType } from "../client";
2
+ import { invalidParamError, serverError, unknownError, type PomiError } from "../errors";
3
+ import type { StudyPeriodEntitySchema } from "../models";
4
+ import { ResultErr, ResultOK, type Result } from "../result";
5
+
6
+ class StudyPeriodService {
7
+ constructor(private client: ClientType) { }
8
+ async get(studyPeriodId: number): Promise<Result<StudyPeriodEntitySchema | null, PomiError>> {
9
+ const { data, error, response } = await this.client.GET(`/study-periods/{id}`, {
10
+ params: {
11
+ path: {
12
+ id: studyPeriodId,
13
+ }
14
+ }
15
+ });
16
+ if (error) {
17
+ if (response?.status === 404)
18
+ return ResultOK(null);
19
+ if (response?.status === 400)
20
+ return ResultErr(invalidParamError("Invalid study period ID", [
21
+ { path: ["studyPeriodId"], message: "Must be a positive integer" }
22
+ ], { originalError: error, response }));
23
+ if (response?.status === 500)
24
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
25
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
26
+ }
27
+ return ResultOK(data ?? null);
28
+ }
29
+ async list(): Promise<Result<StudyPeriodEntitySchema[], PomiError>> {
30
+ const { data, error, response } = await this.client.GET(`/study-periods`, {});
31
+ if (error) {
32
+ if (response?.status === 500)
33
+ return ResultErr(serverError("Server error occurred", { originalError: error, response }));
34
+ return ResultErr(unknownError("An unknown error occurred", { originalError: error, response }));
35
+ }
36
+ return ResultOK(data ?? []);
37
+ }
38
+ }
39
+
40
+ export default StudyPeriodService
@@ -0,0 +1,6 @@
1
+ import ClassScheduleService from "./services/classScheduleService";
2
+ import ClassService from "./services/classService";
3
+ import CourseService from "./services/courseService";
4
+ import CourseOfferingService from "./services/courseOfferingService";
5
+ import ProfessorService from "./services/professorService";
6
+ import StudyPeriodService from "./services/studyPeriodService";
package/src/specs.json ADDED
@@ -0,0 +1 @@
1
+ {"openapi":"3.0.0","info":{"version":"1.0.0","title":"Pomi","description":"This is the API"},"servers":[{"url":"","description":"POMI"}],"components":{"schemas":{"ProfessorEntity":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"_paths":{"type":"object","properties":{"entity":{"type":"string"}},"required":["entity"]}},"required":["id","name","_paths"],"additionalProperties":false},"InstituteEntity":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"_paths":{"type":"object","properties":{"classes":{"type":"string"},"coursesOfferings":{"type":"string"},"courses":{"type":"string"}},"required":["classes","coursesOfferings","courses"]}},"required":["id","name","_paths"],"additionalProperties":false},"CourseEntity":{"type":"object","properties":{"id":{"type":"integer"},"code":{"type":"string"},"name":{"type":"string"},"credits":{"type":"integer"},"_paths":{"type":"object","properties":{"classes":{"type":"string"},"courseOfferings":{"type":"string"}},"required":["classes","courseOfferings"],"additionalProperties":false}},"required":["id","code","name","credits","_paths"],"additionalProperties":false},"ClassEntity":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"reservations":{"type":"array","items":{"type":"integer"}},"courseOfferingId":{"type":"integer"},"studyPeriodId":{"type":"integer"},"studyPeriodName":{"type":"string"},"courseId":{"type":"integer"},"courseCode":{"type":"string"},"instituteId":{"type":"integer"},"instituteName":{"type":"string"},"professors":{"type":"array","items":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"}},"required":["id","name"],"additionalProperties":false}},"_paths":{"type":"object","properties":{"studyPeriod":{"type":"string"},"institute":{"type":"string"},"course":{"type":"string"},"courseOffering":{"type":"string"},"class":{"type":"string"},"classSchedules":{"type":"string"},"professors":{"type":"string"}},"required":["studyPeriod","institute","course","courseOffering","class","classSchedules","professors"],"additionalProperties":false}},"required":["id","name","reservations","courseOfferingId","studyPeriodId","studyPeriodName","courseId","courseCode","instituteId","instituteName","professors","_paths"],"additionalProperties":false},"CourseOfferingEntity":{"type":"object","properties":{"id":{"type":"integer"},"instituteId":{"type":"integer"},"instituteName":{"type":"string"},"courseId":{"type":"integer"},"courseCode":{"type":"string"},"studyPeriodId":{"type":"integer"},"studyPeriodName":{"type":"string"},"_paths":{"type":"object","properties":{"entity":{"type":"string"},"institute":{"type":"string"},"studyPeriod":{"type":"string"},"course":{"type":"string"}},"required":["entity","institute","studyPeriod","course"]}},"required":["id","instituteId","instituteName","courseId","courseCode","studyPeriodId","studyPeriodName","_paths"],"additionalProperties":false},"DaysOfWeekEnum":{"type":"string","enum":["MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY","SUNDAY"]},"ClassScheduleEntity":{"type":"object","properties":{"id":{"type":"integer"},"dayOfWeek":{"$ref":"#/components/schemas/DaysOfWeekEnum"},"start":{"type":"string"},"end":{"type":"string"},"roomId":{"type":"integer"},"roomCode":{"type":"string"},"classId":{"type":"integer"},"className":{"type":"string"},"instituteId":{"type":"integer"},"instituteName":{"type":"string"},"courseId":{"type":"integer"},"courseCode":{"type":"string"},"courseOfferingId":{"type":"integer"},"periodId":{"type":"integer"},"periodName":{"type":"string"},"_paths":{"type":"object","properties":{"entity":{"type":"string"},"studyPeriod":{"type":"string"},"institute":{"type":"string"},"course":{"type":"string"},"courseOffering":{"type":"string"},"class":{"type":"string"}},"required":["entity","studyPeriod","institute","course","courseOffering","class"],"additionalProperties":false}},"required":["id","dayOfWeek","start","end","roomId","roomCode","classId","className","instituteId","instituteName","courseId","courseCode","courseOfferingId","periodId","periodName","_paths"],"additionalProperties":false},"StudyPeriodEntity":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"startDate":{"type":"string","format":"date"},"endDate":{"type":"string","format":"date"},"_paths":{"type":"object","properties":{"courseOfferings":{"type":"string"},"classes":{"type":"string"},"classSchedules":{"type":"string"}},"required":["courseOfferings","classes","classSchedules"]}},"required":["id","name","startDate","endDate","_paths"],"additionalProperties":false},"RoomEntity":{"type":"object","properties":{"id":{"type":"integer"},"code":{"type":"string"},"_paths":{"type":"object","properties":{"entity":{"type":"string"}},"required":["entity"]}},"required":["id","code","_paths"],"additionalProperties":false}},"parameters":{}},"paths":{"/professors":{"get":{"tags":["professor"],"parameters":[{"schema":{"type":"integer","nullable":true},"required":false,"name":"classId","in":"query"}],"responses":{"200":{"description":"A list of professors","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ProfessorEntity"}}}}}}}},"/professors/{id}":{"get":{"tags":["professor"],"parameters":[{"schema":{"type":"integer"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"A list of professors","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ProfessorEntity"}}}}}}},"/institutes":{"get":{"tags":["institute"],"responses":{"200":{"description":"A list of institutes","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/InstituteEntity"}}}}}}}},"/institutes/{id}":{"get":{"tags":["institute"],"parameters":[{"schema":{"type":"integer"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"A list of institutes","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InstituteEntity"}}}}}}},"/courses":{"get":{"tags":["course"],"responses":{"200":{"description":"A list of courses","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/CourseEntity"}}}}}}}},"/courses/{id}":{"get":{"tags":["course"],"parameters":[{"schema":{"type":"integer"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"A list of courses","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CourseEntity"}}}},"404":{"description":"Course not found"}}}},"/classes":{"get":{"tags":["class"],"parameters":[{"schema":{"type":"integer","nullable":true},"required":false,"name":"instituteId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"instituteName","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"courseId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"courseCode","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"periodId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"periodName","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"professorId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"professorName","in":"query"}],"responses":{"200":{"description":"A list of classes","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ClassEntity"}}}}}}}},"/classes/{id}":{"get":{"tags":["class"],"parameters":[{"schema":{"type":"integer"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"A class","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClassEntity"}}}}}}},"/course-offerings":{"get":{"tags":["course-offering"],"parameters":[{"schema":{"type":"integer","nullable":true},"required":false,"name":"instituteId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"instituteCode","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"courseId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"courseCode","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"periodId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"periodName","in":"query"}],"responses":{"200":{"description":"A list of course offerings","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/CourseOfferingEntity"}}}}}}}},"/course-offerings/{id}":{"get":{"tags":["course-offering"],"parameters":[{"schema":{"type":"integer"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"A list of course offerings","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CourseOfferingEntity"}}}}}}},"/class-schedules":{"get":{"tags":["class-schedule"],"parameters":[{"schema":{"type":"integer","nullable":true},"required":false,"name":"periodId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"periodName","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"instituteId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"instituteName","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"courseId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"courseCode","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"roomId","in":"query"},{"schema":{"type":"string"},"required":false,"name":"roomCode","in":"query"},{"schema":{"type":"integer","nullable":true},"required":false,"name":"classId","in":"query"},{"schema":{"$ref":"#/components/schemas/DaysOfWeekEnum"},"required":false,"name":"dayOfWeek","in":"query"}],"responses":{"200":{"description":"A list of class schedules","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ClassScheduleEntity"}}}}}}}},"/class-schedules/{id}":{"get":{"tags":["class-schedule"],"parameters":[{"schema":{"type":"integer"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"A class schedule","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClassScheduleEntity"}}}}}}},"/study-periods":{"get":{"tags":["studyPeriod"],"responses":{"200":{"description":"A list of study periods","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/StudyPeriodEntity"}}}}}}}},"/study-periods/{id}":{"get":{"tags":["studyPeriod"],"responses":{"200":{"description":"A study period by id","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/StudyPeriodEntity"}}}}}}}},"/rooms":{"get":{"tags":["room"],"responses":{"200":{"description":"A list of rooms","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/RoomEntity"}}}}}}}},"/rooms/:id":{"get":{"tags":["room"],"responses":{"200":{"description":"A room by id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RoomEntity"}}}}}}}}}
package/tsconfig.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Environment setup & latest features
4
+ "lib": ["ESNext"],
5
+ "target": "ESNext",
6
+ "module": "Preserve",
7
+ "moduleDetection": "force",
8
+ "jsx": "react-jsx",
9
+ "allowJs": true,
10
+
11
+ // Bundler mode
12
+ "moduleResolution": "bundler",
13
+ "allowImportingTsExtensions": true,
14
+ "verbatimModuleSyntax": true,
15
+ "noEmit": true,
16
+
17
+ // Best practices
18
+ "strict": true,
19
+ "skipLibCheck": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ "noUncheckedIndexedAccess": true,
22
+ "noImplicitOverride": true,
23
+
24
+ // Some stricter flags (disabled by default)
25
+ "noUnusedLocals": false,
26
+ "noUnusedParameters": false,
27
+ "noPropertyAccessFromIndexSignature": false,
28
+
29
+ "declaration": true
30
+ }
31
+ }