From 281f9adedbd5a7914d6ad075ebc1fae878789879 Mon Sep 17 00:00:00 2001 From: Tben Date: Sun, 13 Aug 2023 15:58:20 +0100 Subject: [PATCH] Bugfixes --- engine/engine/recoverMainJsonFromDb.js | 113 ------------------------- engine/user/social/github-auth.js | 2 +- package.json | 2 +- users/social/github-auth.js | 2 +- 4 files changed, 3 insertions(+), 116 deletions(-) delete mode 100644 engine/engine/recoverMainJsonFromDb.js diff --git a/engine/engine/recoverMainJsonFromDb.js b/engine/engine/recoverMainJsonFromDb.js deleted file mode 100644 index 854ef5b..0000000 --- a/engine/engine/recoverMainJsonFromDb.js +++ /dev/null @@ -1,113 +0,0 @@ -// @ts-check - -const fs = require("fs"); -require("dotenv").config({ path: "./../.env" }); - -//////////////////////////////////////// - -const dbHandler = require("./utils/dbHandler"); -const varDatabaseDbHandler = require("./utils/varDatabaseDbHandler"); - -/** ****************************************************************************** */ - -const userId = process.argv.indexOf("--userId") >= 0 ? process.argv[process.argv.indexOf("--userId") + 1] : null; - -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ - -/** - * Grab Schema - * - * @description Grab Schema - */ -async function recoverMainJsonFromDb() { - if (!userId) { - console.log("No user Id provided"); - return; - } - - const databases = await dbHandler({ - query: `SELECT * FROM user_databases WHERE user_id = ?`, - values: [userId], - }); - - /** @type {*[]} */ - const dbWrite = []; - - for (let i = 0; i < databases.length; i++) { - const { id, db_name, db_slug, db_full_name, db_image, db_description } = databases[i]; - - const dbObject = { - dbName: db_name, - dbSlug: db_slug, - dbFullName: db_full_name, - dbDescription: db_description, - dbImage: db_image, - /** @type {*[]} */ - tables: [], - }; - - const tables = await dbHandler({ - query: `SELECT * FROM user_database_tables WHERE user_id = ? AND db_id = ?`, - values: [userId, id], - }); - - for (let j = 0; j < tables.length; j++) { - const { table_name, table_slug, table_description } = tables[j]; - - const tableObject = { - tableName: table_slug, - tableFullName: table_name, - /** @type {*[]} */ - fields: [], - /** @type {*[]} */ - indexes: [], - }; - - const tableFields = await varDatabaseDbHandler({ - database: db_full_name, - queryString: `SHOW COLUMNS FROM ${table_slug}`, - }); - - if (tableFields) { - for (let k = 0; k < tableFields.length; k++) { - const { Field, Type, Null, Default, Key } = tableFields[k]; - - const fieldObject = { - fieldName: Field, - dataType: Type.toUpperCase(), - }; - - if (Default?.match(/./) && !Default?.match(/timestamp/i)) fieldObject["defaultValue"] = Default; - if (Key?.match(/pri/i)) { - fieldObject["primaryKey"] = true; - fieldObject["autoIncrement"] = true; - } - if (Default?.match(/timestamp/i)) fieldObject["defaultValueLiteral"] = Default; - if (Null?.match(/yes/i)) fieldObject["nullValue"] = true; - if (Null?.match(/no/i)) fieldObject["notNullValue"] = true; - - tableObject.fields.push(fieldObject); - } - } - - dbObject.tables.push(tableObject); - } - - dbWrite.push(dbObject); - } - - fs.writeFileSync(`./../jsonData/dbSchemas/users/user-${userId}/main.json`, JSON.stringify(dbWrite, null, 4), "utf-8"); - - process.exit(); -} - -//////////////////////////////////////// -//////////////////////////////////////// -//////////////////////////////////////// - -recoverMainJsonFromDb(); diff --git a/engine/user/social/github-auth.js b/engine/user/social/github-auth.js index 63a2a37..11e48ea 100644 --- a/engine/user/social/github-auth.js +++ b/engine/user/social/github-auth.js @@ -35,7 +35,7 @@ const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT || ""; * @param {string} [params.email] * @param {string} params.clientId * @param {string} params.clientSecret - * @param {string[]} [params.additionalFields] + * @param {object} [params.additionalFields] * @param {import("../../../types/database-schema.td").DSQL_DatabaseSchemaType} params.dbSchema */ async function localGithubAuth({ res, code, email, clientId, clientSecret, additionalFields, dbSchema }) { diff --git a/package.json b/package.json index 36ecb64..73f9181 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasquirel", - "version": "1.7.6", + "version": "1.7.7", "description": "Cloud-based SQL data management tool", "main": "index.js", "bin": { diff --git a/users/social/github-auth.js b/users/social/github-auth.js index c67ec35..3cd50a9 100644 --- a/users/social/github-auth.js +++ b/users/social/github-auth.js @@ -43,7 +43,7 @@ const localGithubAuth = require("../../engine/user/social/github-auth"); * @param {http.ServerResponse} params.response - HTTPS response object * @param {string} params.encryptionKey - Encryption key * @param {string} params.encryptionSalt - Encryption salt - * @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object + * @param {object} [params.additionalFields] - Additional Fields to be added to the user object * * @returns { Promise } */