Skip to content

Commit c437d45

Browse files
authored
Merge pull request #7 from Muj-Elektryk/main
2 parents 4a34ff2 + f3018a6 commit c437d45

File tree

12 files changed

+234
-13
lines changed

12 files changed

+234
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"test": "mocha --reporter spec",
99
"type-check": "tsc --noEmit",
1010
"dev": "node ./dev.js",
11-
"dev-ts": "npx ts-node ./dev.ts"
11+
"dev-ts": "yarn run prepublish && npx ts-node ./dev.ts"
1212
},
1313
"repository": "https://github.com/Capure/vulcan-api-js.git",
1414
"author": "Capure",

src/apiHelper.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import dateFormat from "dateformat";
22
import { Api } from "./api";
33
import {
4+
DATA_BY_MESSAGEBOX,
45
DATA_BY_PERIOD,
56
DATA_BY_PERSON,
67
DATA_BY_PUPIL,
7-
DATA_ROOT,
8+
DATA_ROOT
89
} from "./endpoints";
910
import { Account } from "./models";
1011
import { Period } from "./models";
@@ -14,6 +15,7 @@ export enum FilterType {
1415
BY_PUPIL = 0,
1516
BY_PERSON = 1,
1617
BY_PERIOD = 2,
18+
BY_MESSAGEBOX = 3,
1719
}
1820

1921
export const getEndpoint = (type: FilterType) => {
@@ -24,6 +26,8 @@ export const getEndpoint = (type: FilterType) => {
2426
return DATA_BY_PERSON;
2527
case FilterType.BY_PERIOD:
2628
return DATA_BY_PERIOD;
29+
case FilterType.BY_MESSAGEBOX:
30+
return DATA_BY_MESSAGEBOX;
2731
default:
2832
return null;
2933
}
@@ -38,11 +42,13 @@ export class ApiHelper {
3842

3943
public async getList(
4044
endpoint: string,
41-
deleted: boolean,
45+
deleted: boolean = false,
4246
lastSync?: Date,
4347
dateFrom?: Date,
4448
dateTo?: Date,
4549
filterType?: FilterType,
50+
messageBox?: string,
51+
folder?: number,
4652
params?: any
4753
) {
4854
let url = "";
@@ -74,6 +80,11 @@ export class ApiHelper {
7480
query["periodId"] = period.id;
7581
query["pupilId"] = student.pupil.id;
7682
break;
83+
case FilterType.BY_MESSAGEBOX:
84+
if(!messageBox)
85+
throw Error('No messageBox specified!');
86+
query['box'] = messageBox;
87+
break;
7788
default:
7889
break;
7990
}
@@ -83,6 +94,9 @@ export class ApiHelper {
8394
if (dateTo) {
8495
query["dateTo"] = dateFormat(dateTo, "yyyy-mm-dd");
8596
}
97+
if (folder) {
98+
query['folder'] = folder;
99+
}
86100
query["lastId"] = "-2147483648"; // Comment from vulcan-api for python: don't ask, it's just Vulcan
87101
query["pageSize"] = 500;
88102
query["lastSyncDate"] = dateFormat(

src/endpoints.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const DATA_ROOT = "api/mobile";
55
export const DATA_BY_PUPIL = "byPupil";
66
export const DATA_BY_PERSON = "byPerson";
77
export const DATA_BY_PERIOD = "byPeriod";
8+
export const DATA_BY_MESSAGEBOX = "byBox";
89
export const DATA_DELETED = "deleted";
910

1011
export const DATA_INTERNAL_TIME = "internal/time";
@@ -17,3 +18,7 @@ export const DATA_GRADE_AVERAGE = "grade/average";
1718
export const DATA_HOMEWORK = "homework";
1819
export const DATA_TIMETABLE = "schedule";
1920
export const DATA_TIMETABLE_CHANGES = "schedule/changes";
21+
22+
export const DATA_MESSAGEBOX = "messagebox"
23+
export const DATA_MESSAGE = "messagebox/message"
24+
export const DATA_ATTENDANCE = "lesson";

src/index.ts

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import { Api } from "./api";
22
import {
3+
DATA_ATTENDANCE, DATA_EXAM,
34
DATA_GRADE,
5+
DATA_HOMEWORK,
46
DATA_LUCKY_NUMBER,
7+
DATA_MESSAGE,
8+
DATA_MESSAGEBOX,
59
DATA_TIMETABLE,
610
DATA_TIMETABLE_CHANGES,
711
DEVICE_REGISTER,
8-
STUDENT_LIST,
12+
STUDENT_LIST
913
} from "./endpoints";
1014
import { Keystore } from "./keystore";
11-
import { uuid, getBaseUrl, APP_OS } from "./utils";
15+
import { APP_OS, getBaseUrl, uuid } from "./utils";
1216
import { FilterType } from "./apiHelper";
1317
import dateFormat from "dateformat";
14-
import {
15-
Account,
16-
LuckyNumber,
17-
Student,
18-
Lesson,
19-
Grade,
20-
ChangedLesson,
21-
} from "./models";
18+
import { Account, ChangedLesson, Grade, Lesson, LuckyNumber, Student } from "./models";
19+
import { MessageBox } from "./models/messageBox";
20+
import { Message } from "./models/message";
21+
import { Homework } from "./models/homework";
22+
import { Attendance } from "./models/attendance";
23+
import {Exam} from "./models/exam";
2224

2325
export { AccountTools } from "./utils";
2426
export * from "./keystore";
@@ -154,4 +156,78 @@ export class VulcanHebe {
154156
)
155157
)) as Grade[];
156158
}
159+
public async getMessageBoxes() {
160+
const data = await this.api.helper.getList(
161+
DATA_MESSAGEBOX,
162+
);
163+
return (Promise.all(
164+
data.map(async (messageBox: MessageBox) =>
165+
new MessageBox().serialize(messageBox)
166+
)
167+
));
168+
}
169+
public async getMessages(messageBox: string) {
170+
const data = await this.api.helper.getList(
171+
DATA_MESSAGE,
172+
undefined,
173+
undefined,
174+
undefined,
175+
undefined,
176+
FilterType.BY_MESSAGEBOX,
177+
messageBox,
178+
1,
179+
);
180+
return (Promise.all(
181+
data.map(async (message: Message) =>
182+
new Message().serialize(message)
183+
)
184+
));
185+
}
186+
public async getHomework() {
187+
const data = await this.api.helper.getList(
188+
DATA_HOMEWORK,
189+
undefined,
190+
undefined,
191+
undefined,
192+
undefined,
193+
FilterType.BY_PUPIL
194+
);
195+
return (Promise.all(
196+
data.map(async (homework: Homework) =>
197+
new Homework().serialize(homework)
198+
)
199+
));
200+
}
201+
public async getAttendance(from: Date, to: Date) {
202+
const millisInOneDay = 86400000;
203+
to.setTime(to.getTime() + millisInOneDay);
204+
const data = await this.api.helper.getList(
205+
DATA_ATTENDANCE,
206+
false,
207+
undefined,
208+
from,
209+
to,
210+
FilterType.BY_PUPIL
211+
);
212+
return (Promise.all(
213+
data.map(async (attendance: Attendance) =>
214+
new Attendance().serialize(attendance)
215+
)
216+
));
217+
}
218+
public async getExams(lastSync?: Date): Promise<Exam[]> {
219+
const data = await this.api.helper.getList(
220+
DATA_EXAM,
221+
false,
222+
lastSync,
223+
undefined,
224+
undefined,
225+
FilterType.BY_PUPIL
226+
);
227+
return (Promise.all(
228+
data.map(async (exam: any) =>
229+
new Exam().serialize(exam)
230+
)
231+
));
232+
}
157233
}

src/models/address.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { bind, Serializable } from "../serialize";
2+
3+
export class Address extends Serializable {
4+
@bind('GlobalKey') globalKey: string = '';
5+
@bind('Name') name: string = '';
6+
@bind('HasRead') hasRead?: string;
7+
}

src/models/attendance.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { bind, Serializable } from "../serialize";
2+
import { Subject } from "./subject";
3+
import { Teacher } from "./teacher";
4+
import { TeamClass } from "./teamClass";
5+
import { DateTime } from "./dateTime";
6+
import { TimeSlot } from "./timeSlot";
7+
import { PresenceType } from "./presenceType";
8+
import { TeamVirtual } from "./teamVirtual";
9+
10+
export class Attendance extends Serializable {
11+
@bind('LessonId') lessonId: number = 0;
12+
@bind('Id') id: number = 0;
13+
@bind('LessonNumber') lessonNumber: number = 0;
14+
@bind('GlobalKey') globalKey: string = '';
15+
@bind('LessonClassId') lessonClassId: number = 0;
16+
@bind('LessonClassGlobalKey') lessonClassGlobalKey: string = '';
17+
@bind('CalculatePresence') calculcatePresence: boolean = false;
18+
@bind('Replacement') replacement: boolean = false;
19+
@bind('Subject') subject: Subject = new Subject();
20+
@bind('Topic') topic: string = '';
21+
@bind('TeacherPrimary') teacher: Teacher = new Teacher();
22+
@bind('TeacherSecondary') secondTeacher?: Teacher = new Teacher();
23+
@bind('TeacherMod') mainTeacher?: Teacher = new Teacher();
24+
@bind('Clazz') teamClass?: TeamClass = new TeamClass();
25+
@bind('GroupDefinition') classAlias?: string = '';
26+
@bind('Day') date: DateTime = new DateTime();
27+
@bind('TimeSlot') time?: TimeSlot = new TimeSlot();
28+
@bind('DateModify') dateModified?: DateTime = new DateTime();
29+
@bind('AuxPresenceId') auxPresenceId?: number = 0;
30+
@bind('JustificationStatus') justificationStatus?: string = '';
31+
@bind('PresenceType') presenceType?: PresenceType;
32+
@bind('Note') note?: string;
33+
@bind('PublicResources') publicResources?: string;
34+
@bind('RemoteResources') remoteResources?: string;
35+
@bind('Distribution') group?: TeamVirtual;
36+
@bind('Visible') visible?: boolean;
37+
}

src/models/dateTime.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import { bind, Serializable } from "../serialize";
33
export class DateTime extends Serializable {
44
@bind("Timestamp") timestamp!: number;
55
@bind("Date") date!: string;
6+
@bind("DateDisplay") dateDisplay?: string;
67
@bind("Time") time!: string;
78
}

src/models/exam.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {bind, Serializable} from "../serialize";
2+
import {DateTime} from "./dateTime";
3+
import {Teacher} from "./teacher";
4+
import {Subject} from "./subject";
5+
6+
export class Exam extends Serializable {
7+
@bind("Id") id: number = 0;
8+
@bind("Key") key: string = '';
9+
@bind("Type") type: string = '';
10+
@bind("Content") topic: string = '';
11+
@bind("DateCreated") dateCreated: DateTime = new DateTime();
12+
@bind("DateModify") dateModified: DateTime = new DateTime();
13+
@bind("Deadline") deadline: DateTime = new DateTime();
14+
@bind("Creator") creator: Teacher = new Teacher();
15+
@bind("Subject") subject: Subject = new Subject();
16+
@bind("PupilId") pupilId: number = 0;
17+
}

src/models/homework.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { bind, Serializable } from "../serialize";
2+
import { Teacher } from "./teacher";
3+
import { Subject } from "./subject";
4+
import { Attachment } from "./attachment";
5+
export class Homework extends Serializable {
6+
@bind('Id') id: number = 0;
7+
@bind('Key') key: string = '';
8+
@bind('IdHomework') homeworkId: number = 0;
9+
@bind('Content') content: string = '';
10+
@bind('DateCreated') dateCreated: Date = new Date();
11+
@bind('Creator') creator: Teacher = new Teacher();
12+
@bind('Subject') subject: Subject = new Subject();
13+
@bind('Attachments') attachments: Attachment[] = [];
14+
@bind('IsAnswerRequired') isAnswerRequired: Subject = new Subject();
15+
@bind('Deadline') deadline: Date = new Date();
16+
@bind('AnswerDeadline') answerDeadline: Date = new Date();
17+
@bind('AnswerDate') answerDate: Date = new Date();
18+
}

src/models/message.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { bind, Serializable } from "../serialize";
2+
import { Address } from "./address";
3+
import { Attachment } from "./attachment";
4+
5+
export class Message extends Serializable {
6+
constructor() {
7+
super();
8+
}
9+
@bind('Id') id: string = '';
10+
@bind('GlobalKey') globalKey: string = '';
11+
@bind('ThreadKey') threadKey: string = '';
12+
@bind('Subject') subject: string = '';
13+
@bind('Content') content: string = '';
14+
@bind('DateSent') sentDate: Date = new Date();
15+
@bind('Status') status: number = 0;
16+
@bind('Sender') sender: string = '';
17+
@bind('Receiver') receivers: Address[] = [];
18+
@bind('Attachments') attachments: Attachment[] = [];
19+
@bind('DateRead') readDate?: Date = new Date();
20+
}

0 commit comments

Comments
 (0)