anonymous-student
v1.1.2
Published
Anonymous student is used to retrieve and save information from our website users.
Downloads
4
Maintainers
Readme
Anonymous-Student
Anonymous student is a client which can be used to save and retrieve information about the student whether the user is logged in or not. This application also implements caching of data to reduce the number of requests made to the StudentAPI. The client is available by subscribing to the AnonymousStudentServiceReady
event using the EventAggregationService
, please refer to Events for more details.
Table of contents
Usage
All AnonymousStudent interfaces can be installed using
npm install @studyportals/anonymous-student-interfaces
Interface
import { Actor, IStudent, StudentField } from '@studyportals/studentdomain';
interface IAnonymousStudent {
setStudentData(studentData: IStudent, Actor?: Actor): Promise<void>;
getStudentData(studentFields: StudentField[]): Promise<IStudent>;
getStudentDataCompleteness(studentFields: StudentField[]): Promise<number>;
addDisciplines(ids: number[]): Promise<void>;
removeDisciplines(ids: number[]): Promise<void>;
addInterest(type: InterestType, ids: number[]): Promise<void>;
removeInterest(type: InterestType, ids: number[]): Promise<void>;
setName(name: string): Promise<void>;
setGPA(grade_type: string, grade_value: any): Promise<void>;
}
States
The anonymous student application has multiple states which each handle the retrieval and save requests differently.
Pending
In this state, the application does not yet know if the user is logged in or not. To handle this the "Pending" state keeps all request open until it knows if the user is logged in or not. After this, the requests are resolved.
Online
This is the state where the user is logged in. The data will first try to retrieve data from the local cache. If that data is not saved in the local cache (LocalStorage) than it will retrieve data from the student system.
Offline
This state is active whenever the user is not logged in. The data saved will be stored in local storage until the user logs in. When the user logs in, the data is synced to the Online
state. After syncing the AnonymousStudentProfileSynced
is triggered.
State synchronization
Whenever a new session is created application state will change from Online
to Offline
. As part of this state change any previously saved data in the Offline
state will be synced to the Online
state. This will follow the following rules:
Events
AnonymousStudentServiceReady is triggered when the Anonymous Student Service is ready. A ready-for-use instance of the service is provided as a property of the event. This event has following interface:
interface AnonymousStudentServiceReady {
static EventType: string;
eventType: string;
timestamp: Date;
anonymousStudentService: IAnonymousStudentService;
}
AnonymousStudentProfileSynced is triggered when information has been synced from the Offline
state to the Online
state.
interface AnonymousStudentProfileSynced {
static EventType: string;
eventType: string;
timestamp: Date;
state: StudentRepositoryStateType;
}
AnonymousStudentProfileUpdated is triggered when student information has been updated. This event has following interface:
import { IStudent } from '@studyportals/studentdomain';
interface AnonymousStudentProfileUpdated {
static EventType: string;
eventType: string;
timestamp: Date;
state: StudentRepositoryStateType;
changes: IStudent;
}
AnonymousStudentStateChanged is triggered when anonymous student changes its state:
import { StudentRepositoryStateType } from '@studyportals/studentdomain';
interface AnonymousStudentStateChanged {
static EventType: string;
eventType: string;
timestamp: Date;
oldState: StudentRepositoryStateType;
newState: StudentRepositoryStateType;
}
Dependencies
EventAggregationService
The above events can be listened to by using the EventAggregationService
. Refer to the EventAggregationService documentation for more information on subscribing to domain events.
SessionService
The AnonymousStudent
service depends on the SessionService
being available. Refer to the SessionService documentation for more information.
StudentDomain
A number of domain interfaces and enums in the Student domain are required for this service. Refer to StudentDomain documentation for more information.