Upgrades
This commit is contained in:
parent
43287b0329
commit
80e34fa6ec
@ -1,13 +1,12 @@
|
|||||||
|
// @ts-check
|
||||||
|
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
require("dotenv").config({ path: "./../.env" });
|
require("dotenv").config({ path: "./../.env" });
|
||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|
||||||
const noDatabaseDbHandler = require("../functions/backend/noDatabaseDbHandler");
|
const dbHandler = require("./utils/dbHandler");
|
||||||
const varDatabaseDbHandler = require("../functions/backend/varDatabaseDbHandler");
|
const varDatabaseDbHandler = require("./utils/varDatabaseDbHandler");
|
||||||
const createTable = require("./utils/createTable");
|
|
||||||
const slugToCamelTitle = require("./utils/slugToCamelTitle");
|
|
||||||
const updateTable = require("./utils/updateTable");
|
|
||||||
|
|
||||||
/** ****************************************************************************** */
|
/** ****************************************************************************** */
|
||||||
|
|
||||||
@ -31,8 +30,12 @@ async function recoverMainJsonFromDb() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const databases = await global.DB_HANDLER(`SELECT * FROM user_databases WHERE user_id='${userId}'`);
|
const databases = await dbHandler({
|
||||||
|
query: `SELECT * FROM user_databases WHERE user_id = ?`,
|
||||||
|
values: [userId],
|
||||||
|
});
|
||||||
|
|
||||||
|
/** @type {*[]} */
|
||||||
const dbWrite = [];
|
const dbWrite = [];
|
||||||
|
|
||||||
for (let i = 0; i < databases.length; i++) {
|
for (let i = 0; i < databases.length; i++) {
|
||||||
@ -44,10 +47,14 @@ async function recoverMainJsonFromDb() {
|
|||||||
dbFullName: db_full_name,
|
dbFullName: db_full_name,
|
||||||
dbDescription: db_description,
|
dbDescription: db_description,
|
||||||
dbImage: db_image,
|
dbImage: db_image,
|
||||||
|
/** @type {*[]} */
|
||||||
tables: [],
|
tables: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const tables = await global.DB_HANDLER(`SELECT * FROM user_database_tables WHERE user_id='${userId}' AND db_id='${id}'`);
|
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++) {
|
for (let j = 0; j < tables.length; j++) {
|
||||||
const { table_name, table_slug, table_description } = tables[j];
|
const { table_name, table_slug, table_description } = tables[j];
|
||||||
@ -55,7 +62,9 @@ async function recoverMainJsonFromDb() {
|
|||||||
const tableObject = {
|
const tableObject = {
|
||||||
tableName: table_slug,
|
tableName: table_slug,
|
||||||
tableFullName: table_name,
|
tableFullName: table_name,
|
||||||
|
/** @type {*[]} */
|
||||||
fields: [],
|
fields: [],
|
||||||
|
/** @type {*[]} */
|
||||||
indexes: [],
|
indexes: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -64,6 +73,7 @@ async function recoverMainJsonFromDb() {
|
|||||||
queryString: `SHOW COLUMNS FROM ${table_slug}`,
|
queryString: `SHOW COLUMNS FROM ${table_slug}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (tableFields) {
|
||||||
for (let k = 0; k < tableFields.length; k++) {
|
for (let k = 0; k < tableFields.length; k++) {
|
||||||
const { Field, Type, Null, Default, Key } = tableFields[k];
|
const { Field, Type, Null, Default, Key } = tableFields[k];
|
||||||
|
|
||||||
@ -83,6 +93,7 @@ async function recoverMainJsonFromDb() {
|
|||||||
|
|
||||||
tableObject.fields.push(fieldObject);
|
tableObject.fields.push(fieldObject);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dbObject.tables.push(tableObject);
|
dbObject.tables.push(tableObject);
|
||||||
}
|
}
|
||||||
|
@ -1,81 +0,0 @@
|
|||||||
const fs = require("fs");
|
|
||||||
require("dotenv").config({ path: "./../.env" });
|
|
||||||
|
|
||||||
////////////////////////////////////////
|
|
||||||
|
|
||||||
const noDatabaseDbHandler = require("../functions/backend/noDatabaseDbHandler");
|
|
||||||
const serverError = require("../functions/backend/serverError");
|
|
||||||
|
|
||||||
const varDatabaseDbHandler = require("../functions/backend/varDatabaseDbHandler");
|
|
||||||
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
|
|
||||||
async function updateChildrenTablesOnDb() {
|
|
||||||
/**
|
|
||||||
* Grab Schema
|
|
||||||
*
|
|
||||||
* @description Grab Schema
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
const rootDir = "./../jsonData/dbSchemas/users";
|
|
||||||
const userFolders = fs.readdirSync(rootDir);
|
|
||||||
|
|
||||||
for (let i = 0; i < userFolders.length; i++) {
|
|
||||||
const folder = userFolders[i];
|
|
||||||
const userId = folder.replace(/user-/, "");
|
|
||||||
const databases = JSON.parse(fs.readFileSync(`${rootDir}/${folder}/main.json`));
|
|
||||||
|
|
||||||
for (let j = 0; j < databases.length; j++) {
|
|
||||||
const db = databases[j];
|
|
||||||
const dbTables = db.tables;
|
|
||||||
for (let k = 0; k < dbTables.length; k++) {
|
|
||||||
const table = dbTables[k];
|
|
||||||
|
|
||||||
if (table?.childTable) {
|
|
||||||
const originTableName = table.childTableName;
|
|
||||||
const originDbName = table.childTableDbFullName;
|
|
||||||
|
|
||||||
const WHERE_CLAUSE = `WHERE user_id='${userId}' AND db_slug='${db.dbSlug}' AND table_slug='${table.tableName}'`;
|
|
||||||
|
|
||||||
const existingTableInDb = await global.DB_HANDLER(`SELECT * FROM user_database_tables ${WHERE_CLAUSE}`);
|
|
||||||
console.log(existingTableInDb);
|
|
||||||
|
|
||||||
if (existingTableInDb && existingTableInDb[0]) {
|
|
||||||
const updateChildrenTablesInfo = await global.DB_HANDLER(`UPDATE user_database_tables SET child_table='1',child_table_parent_database='${originDbName}',child_table_parent_table='${originTableName}' WHERE id='${existingTableInDb[0].id}'`);
|
|
||||||
|
|
||||||
console.log(updateChildrenTablesInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////
|
|
||||||
////////////////////////////////////////
|
|
||||||
////////////////////////////////////////
|
|
||||||
|
|
||||||
process.exit();
|
|
||||||
|
|
||||||
////////////////////////////////////////
|
|
||||||
////////////////////////////////////////
|
|
||||||
////////////////////////////////////////
|
|
||||||
}
|
|
||||||
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
|
|
||||||
// const userArg = process.argv[process.argv.indexOf("--user")];
|
|
||||||
// const externalUser = process.argv[process.argv.indexOf("--user") + 1];
|
|
||||||
|
|
||||||
updateChildrenTablesOnDb();
|
|
@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const httpsRequest = require("./httpsRequest");
|
const httpsRequest = require("./httpsRequest");
|
||||||
|
const dbHandler = require("../../../engine/utils/dbHandler");
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -122,7 +123,10 @@ async function githubLogin({ code, clientId, clientSecret }) {
|
|||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
if (!gitHubUser?.email) {
|
if (!gitHubUser?.email) {
|
||||||
const existingGithubUser = await global.DB_HANDLER(`SELECT email FROM users WHERE social_login='1' AND social_platform='github' AND social_id='${gitHubUser?.id || ""}'`);
|
const existingGithubUser = await dbHandler({
|
||||||
|
query: `SELECT email FROM users WHERE social_login='1' AND social_platform='github' AND social_id= ?`,
|
||||||
|
values: [gitHubUser?.id || ""],
|
||||||
|
});
|
||||||
|
|
||||||
if (existingGithubUser && existingGithubUser[0] && gitHubUser) {
|
if (existingGithubUser && existingGithubUser[0] && gitHubUser) {
|
||||||
gitHubUser.email = existingGithubUser[0].email;
|
gitHubUser.email = existingGithubUser[0].email;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// @ts-check
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ==============================================================================
|
* ==============================================================================
|
||||||
* Imports
|
* Imports
|
||||||
@ -11,8 +13,8 @@ const fs = require("fs");
|
|||||||
|
|
||||||
const { OAuth2Client } = require("google-auth-library");
|
const { OAuth2Client } = require("google-auth-library");
|
||||||
|
|
||||||
const { hashPassword } = require("../passwordHash");
|
const dbHandler = require("../../../engine/utils/dbHandler");
|
||||||
const serverError = require("../serverError");
|
const hashPassword = require("../../../../functions/hashPassword");
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -44,6 +46,7 @@ module.exports = async function googleLogin({ usertype, foundUser, isSocialValid
|
|||||||
//[CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3]
|
//[CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
const payload = ticket.payload;
|
const payload = ticket.payload;
|
||||||
const userid = payload["sub"];
|
const userid = payload["sub"];
|
||||||
|
|
||||||
@ -63,7 +66,10 @@ module.exports = async function googleLogin({ usertype, foundUser, isSocialValid
|
|||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
let existinEmail = await global.DB_HANDLER(`SELECT * FROM ${usertype} WHERE email='${payload.email}' AND social_login!='1' AND social_platform!='google'`);
|
let existinEmail = await dbHandler({
|
||||||
|
query: `SELECT * FROM ${usertype} WHERE email = ? AND social_login!='1' AND social_platform!='google'`,
|
||||||
|
values: [payload.email],
|
||||||
|
});
|
||||||
|
|
||||||
if (existinEmail && existinEmail[0]) {
|
if (existinEmail && existinEmail[0]) {
|
||||||
loginFailureReason = "Email Exists Already";
|
loginFailureReason = "Email Exists Already";
|
||||||
@ -73,7 +79,10 @@ module.exports = async function googleLogin({ usertype, foundUser, isSocialValid
|
|||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|
||||||
foundUser = await global.DB_HANDLER(`SELECT * FROM ${usertype} WHERE email='${payload.email}' AND social_login='1' AND social_platform='google'`);
|
foundUser = await dbHandler({
|
||||||
|
query: `SELECT * FROM ${usertype} WHERE email = ? AND social_login='1' AND social_platform='google'`,
|
||||||
|
values: [payload.email],
|
||||||
|
});
|
||||||
|
|
||||||
if (foundUser && foundUser[0]) {
|
if (foundUser && foundUser[0]) {
|
||||||
newFoundUser = foundUser;
|
newFoundUser = foundUser;
|
||||||
@ -84,7 +93,8 @@ module.exports = async function googleLogin({ usertype, foundUser, isSocialValid
|
|||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
let newUser = await global.DB_HANDLER(`INSERT INTO ${usertype} (
|
let newUser = await dbHandler({
|
||||||
|
query: `INSERT INTO ${usertype} (
|
||||||
first_name,
|
first_name,
|
||||||
last_name,
|
last_name,
|
||||||
social_platform,
|
social_platform,
|
||||||
@ -114,20 +124,18 @@ module.exports = async function googleLogin({ usertype, foundUser, isSocialValid
|
|||||||
'1',
|
'1',
|
||||||
'${Date()}',
|
'${Date()}',
|
||||||
'${Date.now()}'
|
'${Date.now()}'
|
||||||
)`);
|
)`,
|
||||||
|
});
|
||||||
|
|
||||||
newFoundUser = await global.DB_HANDLER(`SELECT * FROM ${usertype} WHERE id='${newUser.insertId}'`);
|
newFoundUser = await dbHandler({
|
||||||
|
query: `SELECT * FROM ${usertype} WHERE id = ?`,
|
||||||
|
values: [newUser.insertId],
|
||||||
|
});
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
serverError({
|
|
||||||
component: "googleLogin",
|
|
||||||
message: error.message,
|
|
||||||
user: {},
|
|
||||||
});
|
|
||||||
|
|
||||||
loginFailureReason = error;
|
loginFailureReason = error;
|
||||||
|
|
||||||
isUserValid = false;
|
isUserValid = false;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "datasquirel",
|
"name": "datasquirel",
|
||||||
"version": "1.6.9",
|
"version": "1.7.0",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
Loading…
Reference in New Issue
Block a user