Updates
This commit is contained in:
@@ -23,10 +23,8 @@ export default async function addUsersTableToDb({
|
||||
database,
|
||||
payload,
|
||||
dbId,
|
||||
}: Param): Promise<any> {
|
||||
}: Param): Promise<boolean> {
|
||||
try {
|
||||
const dbFullName = database;
|
||||
|
||||
const userPreset = grabNewUsersTableSchema({ payload });
|
||||
if (!userPreset) throw new Error("Couldn't Get User Preset!");
|
||||
|
||||
@@ -51,32 +49,13 @@ export default async function addUsersTableToDb({
|
||||
|
||||
writeUpdatedDbSchema({ dbSchema: targetDatabase, userId });
|
||||
|
||||
const targetDb = (await dbHandler({
|
||||
query: `SELECT id FROM user_databases WHERE user_id=? AND db_slug=?`,
|
||||
values: [userId, database],
|
||||
})) as any[];
|
||||
|
||||
if (targetDb?.[0]) {
|
||||
const newTableEntry = await addDbEntry({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_database_tables",
|
||||
data: {
|
||||
user_id: userId,
|
||||
db_id: targetDb[0].id,
|
||||
db_slug: targetDatabase.dbSlug,
|
||||
table_name: "Users",
|
||||
table_slug: "users",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const dbShellUpdate = await createDbFromSchema({
|
||||
userId,
|
||||
targetDatabase: dbFullName,
|
||||
dbId,
|
||||
});
|
||||
|
||||
return `Done!`;
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
return dbShellUpdate;
|
||||
} catch (error: any) {
|
||||
console.log(`addUsersTableToDb.ts ERROR: ${error.message}`);
|
||||
|
||||
serverError({
|
||||
@@ -84,6 +63,7 @@ export default async function addUsersTableToDb({
|
||||
message: error.message,
|
||||
user: { id: userId },
|
||||
});
|
||||
return error.message;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,8 @@ export default function grabNewUsersTableSchema(params: {
|
||||
})
|
||||
: [];
|
||||
|
||||
console.log("supplementalFields", supplementalFields);
|
||||
|
||||
const allFields = [...userPreset.fields, ...supplementalFields];
|
||||
|
||||
console.log("allFields", allFields);
|
||||
|
||||
const finalFields = [
|
||||
...defaultFields.slice(0, 2),
|
||||
...allFields,
|
||||
@@ -35,7 +31,7 @@ export default function grabNewUsersTableSchema(params: {
|
||||
userPreset.fields = [...finalFields];
|
||||
|
||||
return userPreset;
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
} catch (error: any) {
|
||||
console.log(`grabNewUsersTableSchema.ts ERROR: ${error.message}`);
|
||||
|
||||
serverError({
|
||||
|
||||
Reference in New Issue
Block a user