-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
280 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Session } from "../Session"; | ||
import { account } from "../types"; | ||
import { getMainAccount, loginFailed } from "../functions"; | ||
|
||
export class Account { | ||
private __account: account; | ||
|
||
constructor(session: Session) { | ||
const { username, password } = session.credentials; | ||
|
||
// Necessary checks | ||
if (!session.loginRes || loginFailed(session.loginRes)) | ||
throw Error("Account class must have valid connection"); | ||
const mainAccount = getMainAccount(session.loginRes.data.accounts); | ||
|
||
if (!session.token) throw Error("Account class MUST have token"); | ||
|
||
this.__account = mainAccount; | ||
} | ||
|
||
get doc() { | ||
return this.__account; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Account } from "./Account"; | ||
import { Session } from "../Session"; | ||
|
||
import { _loginResSuccess, familyAccount } from "../types"; | ||
import { getMainAccount, isFamilyAccount } from "../functions"; | ||
|
||
export class Family extends Account { | ||
public type: "family" = "family"; | ||
private account: familyAccount; | ||
private token: string; | ||
|
||
constructor(private session: Session) { | ||
super(session); | ||
const { username, password } = session.credentials; | ||
|
||
const mainAccount = getMainAccount( | ||
(session.loginRes as _loginResSuccess).data.accounts | ||
); | ||
|
||
if (!isFamilyAccount(mainAccount)) | ||
throw Error("Family class's main account is wrong"); | ||
|
||
if (!session.token) throw Error("Account class MUST have token"); | ||
|
||
this.account = mainAccount; | ||
this.token = session.token; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Account } from "./Account"; | ||
import { Session } from "../Session"; | ||
|
||
import { _loginResSuccess, staffAccount } from "../types"; | ||
import { getMainAccount, isStaffAccount } from "../functions"; | ||
|
||
export class Staff extends Account { | ||
public type: "staff" = "staff"; | ||
private account: staffAccount; | ||
private token: string; | ||
|
||
constructor(private session: Session) { | ||
super(session); | ||
const { username, password } = session.credentials; | ||
|
||
const mainAccount = getMainAccount( | ||
(session.loginRes as _loginResSuccess).data.accounts | ||
); | ||
|
||
if (!isStaffAccount(mainAccount)) | ||
throw Error("Staff class's main account is wrong"); | ||
|
||
if (!session.token) throw Error("Account class MUST have token"); | ||
|
||
this.account = mainAccount; | ||
this.token = session.token; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Account } from "./Account"; | ||
import { Session } from "../Session"; | ||
|
||
import { _loginResSuccess, teacherAccount } from "../types"; | ||
import { getMainAccount, isTeacherAccount } from "../functions"; | ||
|
||
export class Teacher extends Account { | ||
public type: "teacher" = "teacher"; | ||
private account: teacherAccount; | ||
private token: string; | ||
|
||
constructor(private session: Session) { | ||
super(session); | ||
const { username, password } = session.credentials; | ||
|
||
const mainAccount = getMainAccount( | ||
(session.loginRes as _loginResSuccess).data.accounts | ||
); | ||
|
||
if (!isTeacherAccount(mainAccount)) | ||
throw Error("Teacher class's main account is wrong"); | ||
|
||
if (!session.token) throw Error("Account class MUST have token"); | ||
|
||
this.account = mainAccount; | ||
this.token = session.token; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Family } from "./Family"; | ||
import { Staff } from "./Staff"; | ||
import { Student } from "./Student"; | ||
import { Teacher } from "./Teacher"; | ||
|
||
export { Family, Staff, Student, Teacher }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import * as accounts from "./account_types"; | ||
import { Session } from "./Session"; | ||
import * as types from "./types"; | ||
|
||
export { Session, types }; | ||
export { Session, types, accounts }; | ||
|
||
(async () => { | ||
const session = new Session("EDPERSONNEL", "0"); | ||
const account = await session.login(); | ||
console.log(account.type); | ||
})(); |
Oops, something went wrong.