2021-04-27 09:16:44 +02:00
|
|
|
import { IUnleashStores } from '../types/stores';
|
|
|
|
import { IUnleashConfig } from '../types/option';
|
|
|
|
import { Logger } from '../logger';
|
2021-08-12 15:04:37 +02:00
|
|
|
import { ISession, ISessionStore } from '../types/stores/session-store';
|
2021-04-27 09:16:44 +02:00
|
|
|
|
|
|
|
export default class SessionService {
|
|
|
|
private logger: Logger;
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
private sessionStore: ISessionStore;
|
2021-04-27 09:16:44 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
{ sessionStore }: Pick<IUnleashStores, 'sessionStore'>,
|
|
|
|
{ getLogger }: Pick<IUnleashConfig, 'getLogger'>,
|
|
|
|
) {
|
|
|
|
this.logger = getLogger('lib/services/session-service.ts');
|
|
|
|
this.sessionStore = sessionStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getActiveSessions(): Promise<ISession[]> {
|
|
|
|
return this.sessionStore.getActiveSessions();
|
|
|
|
}
|
|
|
|
|
|
|
|
async getSessionsForUser(userId: number): Promise<ISession[]> {
|
|
|
|
return this.sessionStore.getSessionsForUser(userId);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getSession(sid: string): Promise<ISession> {
|
2021-08-12 15:04:37 +02:00
|
|
|
return this.sessionStore.get(sid);
|
2021-04-27 09:16:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async deleteSessionsForUser(userId: number): Promise<void> {
|
|
|
|
return this.sessionStore.deleteSessionsForUser(userId);
|
|
|
|
}
|
|
|
|
|
|
|
|
async deleteSession(sid: string): Promise<void> {
|
2021-08-12 15:04:37 +02:00
|
|
|
return this.sessionStore.delete(sid);
|
2021-04-27 09:16:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async insertSession({
|
|
|
|
sid,
|
|
|
|
sess,
|
|
|
|
}: Pick<ISession, 'sid' | 'sess'>): Promise<ISession> {
|
|
|
|
return this.sessionStore.insertSession({ sid, sess });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = SessionService;
|