From 11a4c1f4d90a53bd3a245cbf87a9c57e2373a543 Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Fri, 11 Oct 2024 10:26:00 +0100 Subject: [PATCH] update types --- client/auth/google/getAccessToken.js | 27 +++------ client/media/imageInputFileToBase64.js | 11 +--- types/general.td.js | 11 +++- types/user.td.js | 82 +++++++++++++++++++++++++- users/add-user.js | 29 +-------- users/get-user.js | 19 +----- users/reauth-user.js | 11 +--- users/update-user.js | 8 +-- 8 files changed, 104 insertions(+), 94 deletions(-) diff --git a/client/auth/google/getAccessToken.js b/client/auth/google/getAccessToken.js index b42cefc..a6cbb72 100644 --- a/client/auth/google/getAccessToken.js +++ b/client/auth/google/getAccessToken.js @@ -1,21 +1,3 @@ -/** - * Type Definitions - * =============================================================================== - */ - -/** - * @typedef {object} GoogleIdentityPromptNotification - * @property {function(): string} getMomentType - Notification moment type - * @property {function(): string} getDismissedReason - Notification get Dismissed Reason - * @property {function(): string} getNotDisplayedReason - Notification get Not Displayed Reason - * @property {function(): string} getSkippedReason - Notification get Skipped Reason - * @property {function(): boolean} isDismissedMoment - Notification is Dismissed Moment - * @property {function(): boolean} isDisplayMoment - Notification is Display Moment - * @property {function(): boolean} isDisplayed - Notification is Displayed - * @property {function(): boolean} isNotDisplayed - Notification is Not Displayed - * @property {function(): boolean} isSkippedMoment - Notification is Skipped Moment - */ - ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// @@ -38,7 +20,12 @@ * * @returns {Promise} - Return */ -module.exports = async function getAccessToken({ clientId, element, triggerPrompt, readyStateDispatch }) { +module.exports = async function getAccessToken({ + clientId, + element, + triggerPrompt, + readyStateDispatch, +}) { /** * == Initialize * @@ -91,7 +78,7 @@ module.exports = async function getAccessToken({ clientId, element, triggerPromp /** * Google prompt notification callback * ======================================================== - * @param {GoogleIdentityPromptNotification} notification - Notification object + * @param {import("../../../types/user.td").GoogleIdentityPromptNotification} notification - Notification object */ (notification) => { notification.isDisplayed(); diff --git a/client/media/imageInputFileToBase64.js b/client/media/imageInputFileToBase64.js index 078e1e9..6247cf5 100644 --- a/client/media/imageInputFileToBase64.js +++ b/client/media/imageInputFileToBase64.js @@ -1,12 +1,3 @@ -/** - * @typedef {{ - * imageBase64: string, - * imageBase64Full: string, - * imageName: string, - * imageSize: number, - * }} FunctionReturn - */ - /** * ============================================================================== * Main Function @@ -19,7 +10,7 @@ * imagePreviewNode?: HTMLImageElement, * }} params - Single object passed * - * @returns { Promise } - Return Object + * @returns { Promise } - Return Object */ module.exports = async function imageInputFileToBase64({ imageInputFile, diff --git a/types/general.td.js b/types/general.td.js index a92814a..6fc2612 100644 --- a/types/general.td.js +++ b/types/general.td.js @@ -8,4 +8,13 @@ const http = require("http"); * @typedef {http.ServerResponse} Response */ -module.exports = { Request, Response }; +/** + * @typedef {{ + * imageBase64: string, + * imageBase64Full: string, + * imageName: string, + * imageSize: number, + * }} ImageInputFileToBase64FunctionReturn + */ + +module.exports = { Request, Response, ImageInputFileToBase64FunctionReturn }; diff --git a/types/user.td.js b/types/user.td.js index 46e9f9f..8b66a62 100644 --- a/types/user.td.js +++ b/types/user.td.js @@ -46,4 +46,84 @@ * @property {number} [userId] - An optional message */ -module.exports = { DATASQUIREL_LoggedInUser, AuthenticatedUser }; +/** + * @typedef {object} SuccessUserObject + * @property {number} id + * @property {string} first_name + * @property {string} last_name + * @property {string} email + */ + +/** + * @typedef {object} AddUserFunctionReturn + * @property {boolean} success - Did the function run successfully? + * @property {SuccessUserObject | null} [payload] - Payload + * @property {string} [msg] + * @property {any} [sqlResult] + */ + +/** + * @typedef {object} GoogleIdentityPromptNotification + * @property {function(): string} getMomentType - Notification moment type + * @property {function(): string} getDismissedReason - Notification get Dismissed Reason + * @property {function(): string} getNotDisplayedReason - Notification get Not Displayed Reason + * @property {function(): string} getSkippedReason - Notification get Skipped Reason + * @property {function(): boolean} isDismissedMoment - Notification is Dismissed Moment + * @property {function(): boolean} isDisplayMoment - Notification is Display Moment + * @property {function(): boolean} isDisplayed - Notification is Displayed + * @property {function(): boolean} isNotDisplayed - Notification is Not Displayed + * @property {function(): boolean} isSkippedMoment - Notification is Skipped Moment + */ + +/** + * @typedef {object} UserDataPayload + * @property {string} first_name - First Name *Required + * @property {string} last_name - Last Name *Required + * @property {string} email - Email *Required + * @property {string} password - Password *Required + * @property {string?} username - Username (Optional) + */ + +/** + * @typedef {object} GetUserFunctionReturn + * @property {boolean} success - Did the function run successfully? + * @property {{ + * id: number, + * first_name: string, + * last_name: string, + * username: string, + * email: string, + * phone: string, + * social_id: [string], + * image: string, + * image_thumbnail: string, + * verification_status: [number=0], + * }} payload - Payload + */ + +/** + * @typedef {object} ReauthUserFunctionReturn + * @property {boolean} success - Did the function run successfully? + * @property {import("../types/user.td").DATASQUIREL_LoggedInUser | null} payload - Payload + * @property {string} [msg] - Response Message + * @property {number} [userId] - user ID + * @property {string} [token] - new Token + */ + +/** + * @typedef {object} UpdateUserFunctionReturn + * @property {boolean} success - Did the function run successfully? + * @property {(Object[]|string)} [payload=[]] - Payload + */ + +module.exports = { + DATASQUIREL_LoggedInUser, + AuthenticatedUser, + AddUserFunctionReturn, + SuccessUserObject, + GoogleIdentityPromptNotification, + UserDataPayload, + GetUserFunctionReturn, + ReauthUserFunctionReturn, + UpdateUserFunctionReturn, +}; diff --git a/users/add-user.js b/users/add-user.js index 9e621c6..6a57ceb 100644 --- a/users/add-user.js +++ b/users/add-user.js @@ -18,31 +18,6 @@ const localAddUser = require("../engine/user/add-user"); /** ****************************************************************************** */ /** ****************************************************************************** */ -/** - * @typedef {object} SuccessUserObject - * @property {number} id - * @property {string} first_name - * @property {string} last_name - * @property {string} email - */ - -/** - * @typedef {object} FunctionReturn - * @property {boolean} success - Did the function run successfully? - * @property {SuccessUserObject | null} [payload] - Payload - * @property {string} [msg] - * @property {any} [sqlResult] - */ - -/** - * @typedef {object} UserDataPayload - * @property {string} first_name - First Name *Required - * @property {string} last_name - Last Name *Required - * @property {string} email - Email *Required - * @property {string} password - Password *Required - * @property {string?} username - Username (Optional) - */ - /** * Add User to Database * ============================================================================== @@ -51,11 +26,11 @@ const localAddUser = require("../engine/user/add-user"); * @param {object} props - Single object passed * @param {string} props.key - FULL ACCESS API Key * @param {string} props.database - Database Name - * @param {UserDataPayload} props.payload - User Data Payload + * @param {import("../types/user.td").UserDataPayload} props.payload - User Data Payload * @param {string} props.encryptionKey * @param {string} [props.encryptionSalt] * - * @returns { Promise } + * @returns { Promise } */ async function addUser({ key, diff --git a/users/get-user.js b/users/get-user.js index 5183081..c95fcd6 100644 --- a/users/get-user.js +++ b/users/get-user.js @@ -14,23 +14,6 @@ const getLocalUser = require("../engine/user/get-user"); /** ****************************************************************************** */ /** ****************************************************************************** */ -/** - * @typedef {object} FunctionReturn - * @property {boolean} success - Did the function run successfully? - * @property {{ - * id: number, - * first_name: string, - * last_name: string, - * username: string, - * email: string, - * phone: string, - * social_id: [string], - * image: string, - * image_thumbnail: string, - * verification_status: [number=0], - * }} payload - Payload - */ - /** * ============================================================================== * Main Function @@ -43,7 +26,7 @@ const getLocalUser = require("../engine/user/get-user"); * @param {number} params.userId - user id * @param {string[]} [params.fields] - fields to select * - * @returns { Promise} + * @returns { Promise} */ async function getUser({ key, userId, database, fields }) { /** diff --git a/users/reauth-user.js b/users/reauth-user.js index c232d53..514985c 100644 --- a/users/reauth-user.js +++ b/users/reauth-user.js @@ -21,15 +21,6 @@ const localReauthUser = require("../engine/user/reauth-user"); /** ****************************************************************************** */ /** ****************************************************************************** */ -/** - * @typedef {object} FunctionReturn - * @property {boolean} success - Did the function run successfully? - * @property {import("../types/user.td").DATASQUIREL_LoggedInUser | null} payload - Payload - * @property {string} [msg] - Response Message - * @property {number} [userId] - user ID - * @property {string} [token] - new Token - */ - /** * ============================================================================== * Main Function @@ -47,7 +38,7 @@ const localReauthUser = require("../engine/user/reauth-user"); * @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object * @param {string} [params.token] - access token to use instead of getting from cookie header * - * @returns { Promise } + * @returns { Promise } */ async function reauthUser({ key, diff --git a/users/update-user.js b/users/update-user.js index 39b2077..b93b334 100644 --- a/users/update-user.js +++ b/users/update-user.js @@ -18,12 +18,6 @@ const localUpdateUser = require("../engine/user/update-user"); /** ****************************************************************************** */ /** ****************************************************************************** */ -/** - * @typedef {object} FunctionReturn - * @property {boolean} success - Did the function run successfully? - * @property {(Object[]|string)} [payload=[]] - Payload - */ - /** * ============================================================================== * Main Function @@ -35,7 +29,7 @@ const localUpdateUser = require("../engine/user/update-user"); * @param {String} params.database - Target Database * @param {{ id: number } & Object.} params.payload - User Object: ID is required * - * @returns { Promise} + * @returns { Promise} */ async function updateUser({ key, payload, database }) { /**