From 2c704a544f4e31a8e8e833a9a62ba016bcfa6c7c Mon Sep 17 00:00:00 2001 From: Sabir Hassan Date: Mon, 6 Jun 2022 17:24:19 +0500 Subject: [PATCH] fix: refactor sas/js session controller classes to inherit from base session controller class --- api/src/controllers/internal/Session.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/api/src/controllers/internal/Session.ts b/api/src/controllers/internal/Session.ts index 4f7eac4..c1d5d40 100644 --- a/api/src/controllers/internal/Session.ts +++ b/api/src/controllers/internal/Session.ts @@ -17,12 +17,14 @@ import { const execFilePromise = promisify(execFile) -export class SASSessionController { - private sessions: Session[] = [] +abstract class SessionController { + protected sessions: Session[] = [] - private getReadySessions = (): Session[] => + protected getReadySessions = (): Session[] => this.sessions.filter((sess: Session) => sess.ready && !sess.consumed) + protected abstract createSession(): Promise + public async getSession() { const readySessions = this.getReadySessions() @@ -34,8 +36,10 @@ export class SASSessionController { return session } +} - private async createSession(): Promise { +export class SASSessionController extends SessionController { + protected async createSession(): Promise { const sessionId = generateUniqueFileName(generateTimestamp()) const sessionFolder = path.join(getSessionsFolder(), sessionId) @@ -152,8 +156,8 @@ ${autoExecContent}` } } -export class JSSessionController { - public async getSession() { +export class JSSessionController extends SessionController { + protected async createSession(): Promise { const sessionId = generateUniqueFileName(generateTimestamp()) const sessionFolder = path.join(getSessionsFolder(), sessionId) @@ -179,6 +183,7 @@ export class JSSessionController { const headersPath = path.join(session.path, 'stpsrv_header.txt') await createFile(headersPath, 'Content-type: application/json') + this.sessions.push(session) return session } }