From 6612145c4faa7f8fef49d2091b2aa31d54831bce Mon Sep 17 00:00:00 2001 From: Frank Lemanschik Date: Sun, 15 Mar 2020 14:09:39 +0100 Subject: [PATCH] Converted initalizeSession --- src/shared/fun/initializeSession.ts | 71 ++++++++++++++++++++--------- tsconfig.json | 4 +- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/shared/fun/initializeSession.ts b/src/shared/fun/initializeSession.ts index 3e2d807..1eaf41f 100644 --- a/src/shared/fun/initializeSession.ts +++ b/src/shared/fun/initializeSession.ts @@ -1,41 +1,70 @@ -enum Indexes { - clientId = 0, - imageUrl -} +const Indexes = { + clientId: 0, + imageUrl: 1 +}; export default class InitSession { - private _clientSessionId: string | undefined; - private _imageUrl: string | undefined; - - set sessionId(id: string) { - if(id.length !== 8) throw Error("ClientID is not 8 characters"); - this._clientSessionId = id; + constructor() { + /** @type {string | undefined} */ + this._sessionId; + /** @type {string | undefined} */ + this._imageUrl; } - get sessionId(): string { - return this._clientSessionId!; + /** + * Set the session ID for the user + * @param {string} id + */ + setSessionId(id) { + if (id.length !== 8) throw Error("ClientID is not 8 characters"); + this._sessionId = id; } - set imageUrl(url: string) { + /** + * Get the session ID for the user + * @return {string} + */ + getSessionId() { + return this._sessionId; + } + + /** + * Set the image URL for the initial challenge + * @param {string} url + */ + setImageUrl(url: string) { this._imageUrl = url; } - get imageUrl(): string { - return this._imageUrl!; + /** + * Get the image URL for the initial challenge + * @return {string} + */ + getImageUrl() { + return this._imageUrl; } - serialize(): any[] { - if(!this._clientSessionId || !this._imageUrl) { - throw Error("Unable to serialize because missing field(s)") + /** + * Serialize the session into a JSON object + * @return {Array} + */ + serialize() { + if (!this._sessionId || !this._imageUrl) { + throw Error("Unable to serialize because missing field(s)"); } const payload = []; - payload[Indexes.clientId] = this._clientSessionId; + payload[Indexes.clientId] = this._sessionId; payload[Indexes.imageUrl] = this._imageUrl; return payload; } + /** + * Deserialize session data from JSON object + * @param {Array} payload + */ deserialize(payload: any[]) { - + this.setSessionId(payload[Indexes.clientId]); + this.setImageUrl(payload[Indexes.imageUrl]); } -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index 40ac18b..982c864 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,9 +6,9 @@ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ // "allowJs": true, /* Allow javascript files to be compiled. */ - // "checkJs": true, /* Report errors in .js files. */ + "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - // "declaration": true, /* Generates corresponding '.d.ts' file. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */