Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test": "mocha --reporter spec",
"type-check": "tsc --noEmit",
"dev": "node ./dev.js",
"dev-ts": "npx ts-node ./dev.ts"
"dev-ts": "yarn run prepublish && npx ts-node ./dev.ts"
},
"repository": "https://github.com/Capure/vulcan-api-js.git",
"author": "Capure",
Expand Down
18 changes: 16 additions & 2 deletions src/apiHelper.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import dateFormat from "dateformat";
import { Api } from "./api";
import {
DATA_BY_MESSAGEBOX,
DATA_BY_PERIOD,
DATA_BY_PERSON,
DATA_BY_PUPIL,
DATA_ROOT,
DATA_ROOT
} from "./endpoints";
import { Account } from "./models";
import { Period } from "./models";
Expand All @@ -14,6 +15,7 @@ export enum FilterType {
BY_PUPIL = 0,
BY_PERSON = 1,
BY_PERIOD = 2,
BY_MESSAGEBOX = 3,
}

export const getEndpoint = (type: FilterType) => {
Expand All @@ -24,6 +26,8 @@ export const getEndpoint = (type: FilterType) => {
return DATA_BY_PERSON;
case FilterType.BY_PERIOD:
return DATA_BY_PERIOD;
case FilterType.BY_MESSAGEBOX:
return DATA_BY_MESSAGEBOX;
default:
return null;
}
Expand All @@ -38,11 +42,13 @@ export class ApiHelper {

public async getList(
endpoint: string,
deleted: boolean,
deleted: boolean = false,
lastSync?: Date,
dateFrom?: Date,
dateTo?: Date,
filterType?: FilterType,
messageBox?: string,
folder?: number,
params?: any
) {
let url = "";
Expand Down Expand Up @@ -74,6 +80,11 @@ export class ApiHelper {
query["periodId"] = period.id;
query["pupilId"] = student.pupil.id;
break;
case FilterType.BY_MESSAGEBOX:
if(!messageBox)
throw Error('No messageBox specified!');
query['box'] = messageBox;
break;
default:
break;
}
Expand All @@ -83,6 +94,9 @@ export class ApiHelper {
if (dateTo) {
query["dateTo"] = dateFormat(dateTo, "yyyy-mm-dd");
}
if (folder) {
query['folder'] = folder;
}
query["lastId"] = "-2147483648"; // Comment from vulcan-api for python: don't ask, it's just Vulcan
query["pageSize"] = 500;
query["lastSyncDate"] = dateFormat(
Expand Down
5 changes: 5 additions & 0 deletions src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const DATA_ROOT = "api/mobile";
export const DATA_BY_PUPIL = "byPupil";
export const DATA_BY_PERSON = "byPerson";
export const DATA_BY_PERIOD = "byPeriod";
export const DATA_BY_MESSAGEBOX = "byBox";
export const DATA_DELETED = "deleted";

export const DATA_INTERNAL_TIME = "internal/time";
Expand All @@ -17,3 +18,7 @@ export const DATA_GRADE_AVERAGE = "grade/average";
export const DATA_HOMEWORK = "homework";
export const DATA_TIMETABLE = "schedule";
export const DATA_TIMETABLE_CHANGES = "schedule/changes";

export const DATA_MESSAGEBOX = "messagebox"
export const DATA_MESSAGE = "messagebox/message"
export const DATA_ATTENDANCE = "lesson";
96 changes: 86 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { Api } from "./api";
import {
DATA_ATTENDANCE, DATA_EXAM,
DATA_GRADE,
DATA_HOMEWORK,
DATA_LUCKY_NUMBER,
DATA_MESSAGE,
DATA_MESSAGEBOX,
DATA_TIMETABLE,
DATA_TIMETABLE_CHANGES,
DEVICE_REGISTER,
STUDENT_LIST,
STUDENT_LIST
} from "./endpoints";
import { Keystore } from "./keystore";
import { uuid, getBaseUrl, APP_OS } from "./utils";
import { APP_OS, getBaseUrl, uuid } from "./utils";
import { FilterType } from "./apiHelper";
import dateFormat from "dateformat";
import {
Account,
LuckyNumber,
Student,
Lesson,
Grade,
ChangedLesson,
} from "./models";
import { Account, ChangedLesson, Grade, Lesson, LuckyNumber, Student } from "./models";
import { MessageBox } from "./models/messageBox";
import { Message } from "./models/message";
import { Homework } from "./models/homework";
import { Attendance } from "./models/attendance";
import {Exam} from "./models/exam";

export { AccountTools } from "./utils";
export * from "./keystore";
Expand Down Expand Up @@ -154,4 +156,78 @@ export class VulcanHebe {
)
)) as Grade[];
}
public async getMessageBoxes() {
const data = await this.api.helper.getList(
DATA_MESSAGEBOX,
);
return (Promise.all(
data.map(async (messageBox: MessageBox) =>
new MessageBox().serialize(messageBox)
)
));
}
public async getMessages(messageBox: string) {
const data = await this.api.helper.getList(
DATA_MESSAGE,
undefined,
undefined,
undefined,
undefined,
FilterType.BY_MESSAGEBOX,
messageBox,
1,
);
return (Promise.all(
data.map(async (message: Message) =>
new Message().serialize(message)
)
));
}
public async getHomework() {
const data = await this.api.helper.getList(
DATA_HOMEWORK,
undefined,
undefined,
undefined,
undefined,
FilterType.BY_PUPIL
);
return (Promise.all(
data.map(async (homework: Homework) =>
new Homework().serialize(homework)
)
));
}
public async getAttendance(from: Date, to: Date) {
const millisInOneDay = 86400000;
to.setTime(to.getTime() + millisInOneDay);
const data = await this.api.helper.getList(
DATA_ATTENDANCE,
false,
undefined,
from,
to,
FilterType.BY_PUPIL
);
return (Promise.all(
data.map(async (attendance: Attendance) =>
new Attendance().serialize(attendance)
)
));
}
public async getExams(lastSync?: Date): Promise<Exam[]> {
const data = await this.api.helper.getList(
DATA_EXAM,
false,
lastSync,
undefined,
undefined,
FilterType.BY_PUPIL
);
return (Promise.all(
data.map(async (exam: any) =>
new Exam().serialize(exam)
)
));
}
}
7 changes: 7 additions & 0 deletions src/models/address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { bind, Serializable } from "../serialize";

export class Address extends Serializable {
@bind('GlobalKey') globalKey: string = '';
@bind('Name') name: string = '';
@bind('HasRead') hasRead?: string;
}
37 changes: 37 additions & 0 deletions src/models/attendance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { bind, Serializable } from "../serialize";
import { Subject } from "./subject";
import { Teacher } from "./teacher";
import { TeamClass } from "./teamClass";
import { DateTime } from "./dateTime";
import { TimeSlot } from "./timeSlot";
import { PresenceType } from "./presenceType";
import { TeamVirtual } from "./teamVirtual";

export class Attendance extends Serializable {
@bind('LessonId') lessonId: number = 0;
@bind('Id') id: number = 0;
@bind('LessonNumber') lessonNumber: number = 0;
@bind('GlobalKey') globalKey: string = '';
@bind('LessonClassId') lessonClassId: number = 0;
@bind('LessonClassGlobalKey') lessonClassGlobalKey: string = '';
@bind('CalculatePresence') calculcatePresence: boolean = false;
@bind('Replacement') replacement: boolean = false;
@bind('Subject') subject: Subject = new Subject();
@bind('Topic') topic: string = '';
@bind('TeacherPrimary') teacher: Teacher = new Teacher();
@bind('TeacherSecondary') secondTeacher?: Teacher = new Teacher();
@bind('TeacherMod') mainTeacher?: Teacher = new Teacher();
@bind('Clazz') teamClass?: TeamClass = new TeamClass();
@bind('GroupDefinition') classAlias?: string = '';
@bind('Day') date: DateTime = new DateTime();
@bind('TimeSlot') time?: TimeSlot = new TimeSlot();
@bind('DateModify') dateModified?: DateTime = new DateTime();
@bind('AuxPresenceId') auxPresenceId?: number = 0;
@bind('JustificationStatus') justificationStatus?: string = '';
@bind('PresenceType') presenceType?: PresenceType;
@bind('Note') note?: string;
@bind('PublicResources') publicResources?: string;
@bind('RemoteResources') remoteResources?: string;
@bind('Distribution') group?: TeamVirtual;
@bind('Visible') visible?: boolean;
}
1 change: 1 addition & 0 deletions src/models/dateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { bind, Serializable } from "../serialize";
export class DateTime extends Serializable {
@bind("Timestamp") timestamp!: number;
@bind("Date") date!: string;
@bind("DateDisplay") dateDisplay?: string;
@bind("Time") time!: string;
}
17 changes: 17 additions & 0 deletions src/models/exam.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {bind, Serializable} from "../serialize";
import {DateTime} from "./dateTime";
import {Teacher} from "./teacher";
import {Subject} from "./subject";

export class Exam extends Serializable {
@bind("Id") id: number = 0;
@bind("Key") key: string = '';
@bind("Type") type: string = '';
@bind("Content") topic: string = '';
@bind("DateCreated") dateCreated: DateTime = new DateTime();
@bind("DateModify") dateModified: DateTime = new DateTime();
@bind("Deadline") deadline: DateTime = new DateTime();
@bind("Creator") creator: Teacher = new Teacher();
@bind("Subject") subject: Subject = new Subject();
@bind("PupilId") pupilId: number = 0;
}
18 changes: 18 additions & 0 deletions src/models/homework.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { bind, Serializable } from "../serialize";
import { Teacher } from "./teacher";
import { Subject } from "./subject";
import { Attachment } from "./attachment";
export class Homework extends Serializable {
@bind('Id') id: number = 0;
@bind('Key') key: string = '';
@bind('IdHomework') homeworkId: number = 0;
@bind('Content') content: string = '';
@bind('DateCreated') dateCreated: Date = new Date();
@bind('Creator') creator: Teacher = new Teacher();
@bind('Subject') subject: Subject = new Subject();
@bind('Attachments') attachments: Attachment[] = [];
@bind('IsAnswerRequired') isAnswerRequired: Subject = new Subject();
@bind('Deadline') deadline: Date = new Date();
@bind('AnswerDeadline') answerDeadline: Date = new Date();
@bind('AnswerDate') answerDate: Date = new Date();
}
20 changes: 20 additions & 0 deletions src/models/message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { bind, Serializable } from "../serialize";
import { Address } from "./address";
import { Attachment } from "./attachment";

export class Message extends Serializable {
constructor() {
super();
}
@bind('Id') id: string = '';
@bind('GlobalKey') globalKey: string = '';
@bind('ThreadKey') threadKey: string = '';
@bind('Subject') subject: string = '';
@bind('Content') content: string = '';
@bind('DateSent') sentDate: Date = new Date();
@bind('Status') status: number = 0;
@bind('Sender') sender: string = '';
@bind('Receiver') receivers: Address[] = [];
@bind('Attachments') attachments: Attachment[] = [];
@bind('DateRead') readDate?: Date = new Date();
}
9 changes: 9 additions & 0 deletions src/models/messageBox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { bind, Serializable } from "../serialize";
export class MessageBox extends Serializable {
constructor() {
super();
}
@bind("Id") id?: number;
@bind('GlobalKey') globalKey: string = '';
@bind('Name') name: string = '';
}
17 changes: 17 additions & 0 deletions src/models/presenceType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { bind, Serializable } from "../serialize";

export class PresenceType extends Serializable {

@bind('Id') id: number = 0;
@bind('Name') name: string = '';
@bind('Symbol') symbol: string = '';
@bind('CategoryId') category_id: number = 0;
@bind('CategoryName') category_name: string = '';
@bind('Position') position: number = 0;
@bind('Presence') presence: boolean = false;
@bind('Absence') absence: boolean = false;
@bind('LegalAbsence') exemption: boolean = false;
@bind('Late') late: boolean = false;
@bind('AbsenceJustified') justified: boolean = false;
@bind('Removed') deleted: boolean = false;
}