diff --git a/src/server/knex/migrations/20240519053307_hash_primary_key.ts b/src/server/knex/migrations/20240519053307_hash_primary_key.ts new file mode 100644 index 00000000..0963136a --- /dev/null +++ b/src/server/knex/migrations/20240519053307_hash_primary_key.ts @@ -0,0 +1,521 @@ +//---------------------------------------------------------------------------------------------------------------------- +// HashID Primary Key Conversion +//---------------------------------------------------------------------------------------------------------------------- + +import { Knex } from 'knex'; + +//---------------------------------------------------------------------------------------------------------------------- + +export async function up(knex : Knex) : Promise +{ + //------------------------------------------------------------------------------------------------------------------ + // Step 1: Rename tables, drop indexes + //------------------------------------------------------------------------------------------------------------------ + + await knex.schema.renameTable('account', 'bk_account'); + await knex.schema.renameTable('account_role', 'bk_account_role'); + await knex.schema.renameTable('ugc_mod_comment', 'bk_ugc_mod_comment'); + await knex.schema.renameTable('note', 'bk_note'); + await knex.schema.renameTable('note_page', 'bk_note_page'); + await knex.schema.renameTable('character', 'bk_character'); + + //------------------------------------------------------------------------------------------------------------------ + // Step 2: Declare new tables + //------------------------------------------------------------------------------------------------------------------ + + // Account Table + await knex.schema.createTable('account', (table) => + { + table.string('account_id').primary(); + table.text('email').notNullable(); + table.text('name'); + table.text('avatar'); + table.json('permissions').notNullable() + .defaultTo('[]'); + table.json('settings').notNullable() + .defaultTo('{}'); + table.timestamp('created').notNullable() + .defaultTo(knex.fn.now()); + }); + + // Account Role Table + await knex.schema.createTable('account_role', (table) => + { + table.string('account_id') + .references('account.account_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('CASCADE'); + table.integer('role_id') + .references('role.role_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('CASCADE'); + }); + + // Mod Comment Table + await knex.schema.createTable('ugc_mod_comment', (table) => + { + table.increments('comment_id').primary(); + table.text('comment').notNullable(); + table.string('account_id') + .references('account.account_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('CASCADE'); + table.integer('mod_id') + .references('ugc_moderation.mod_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('CASCADE'); + table.timestamp('created').notNullable() + .defaultTo(knex.fn.now()); + table.json('metadata').notNullable() + .defaultTo('{}'); + }); + + // The `notes` table + await knex.schema.createTable('note', (table) => + { + table.string('note_id').primary(); + }); + + // The `notes_pages` table + await knex.schema.createTable('note_page', (table) => + { + table.integer('page_id').primary(); + table.text('title').notNullable(); + table.string('content'); + table.string('note_id') + .references('note.note_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('CASCADE'); + }); + + // The `character` table + await knex.schema.createTable('character', (table) => + { + table.string('character_id').primary(); + table.string('system').notNullable() + .index(); + table.string('name').notNullable(); + table.text('description'); + table.string('portrait'); + table.string('thumbnail'); + table.string('color'); + table.text('campaign'); + table.json('details').notNullable() + .defaultTo('{}'); + table.string('note_id') + .references('note.note_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('RESTRICT'); + table.string('account_id') + .references('account.account_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('CASCADE'); + }); + + //------------------------------------------------------------------------------------------------------------------ + // Step 3: Copy tables. + //------------------------------------------------------------------------------------------------------------------ + + // Select out all the data from the old tables + const accounts = await knex('bk_account').select(); + const account_roles = await knex('bk_account_role').select(); + const ugc_mod_comments = await knex('bk_ugc_mod_comment').select(); + const notes = await knex('bk_note').select(); + const note_pages = await knex('bk_note_page').select(); + const characters = await knex('bk_character').select(); + + // Insert the data into the new tables + if(accounts.length > 0) + { + await knex('account') + .insert(accounts.map((account) => + { + return { + account_id: account.hash_id, + email: account.email, + name: account.name, + avatar: account.avatar, + permissions: account.permissions, + settings: account.settings, + created: account.created + }; + })); + } + + if(account_roles.length > 0) + { + await knex('account_role') + .insert(account_roles.map((account_role) => + { + const account = accounts.find((acc) => acc.account_id === account_role.account_id); + return { + account_id: account.hash_id, + role_id: account_role.role_id + }; + })); + } + + if(ugc_mod_comments.length > 0) + { + await knex('ugc_mod_comment') + .insert(ugc_mod_comments.map((comment) => + { + const account = accounts.find((acc) => acc.account_id === comment.account_id); + return { + comment_id: comment.comment_id, + comment: comment.comment, + account_id: account.hash_id, + mod_id: comment.mod_id, + created: comment.created, + metadata: comment.metadata + }; + })); + } + + if(notes.length > 0) + { + await knex('note') + .insert(notes.map((note) => + { + return { + note_id: note.hash_id + }; + })); + } + + if(note_pages.length > 0) + { + await knex('note_page') + .insert(note_pages.map((page) => + { + const note = notes.find((nt) => nt.note_id === page.note_id); + return { + page_id: page.page_id, + title: page.title, + content: page.content, + note_id: note.hash_id + }; + })); + } + + if(characters.length > 0) + { + await knex('character') + .insert(characters.map((character) => + { + const note = notes.find((nt) => nt.note_id === character.note_id); + const account = accounts.find((acc) => acc.account_id === character.account_id); + return { + character_id: character.hash_id, + system: character.system, + name: character.name, + description: character.description, + portrait: character.portrait, + thumbnail: character.thumbnail, + color: character.color, + campaign: character.campaign, + details: character.details, + note_id: note.hash_id, + account_id: account.hash_id + }; + })); + } + + //------------------------------------------------------------------------------------------------------------------ + // Step 4: Delete bk_* tables + //------------------------------------------------------------------------------------------------------------------ + + await knex.schema.dropTable('bk_account'); + await knex.schema.dropTable('bk_account_role'); + await knex.schema.dropTable('bk_ugc_mod_comment'); + await knex.schema.dropTable('bk_note'); + await knex.schema.dropTable('bk_note_page'); + await knex.schema.dropTable('bk_character'); + + //------------------------------------------------------------------------------------------------------------------ + // Step 5: Re-add Indexes + //------------------------------------------------------------------------------------------------------------------ + + knex.schema.table('account', (table) => + { + table.dropUnique([ 'email' ]); + table.unique('email'); + }); + + knex.schema.table('account_role', (table) => + { + table.dropIndex([ 'account_id', 'role_id' ]); + table.unique([ 'account_id', 'role_id' ]); + }); +} + +//---------------------------------------------------------------------------------------------------------------------- + +export async function down(knex : Knex) : Promise +{ + //------------------------------------------------------------------------------------------------------------------ + // Step 1: Rename tables, drop indexes + //------------------------------------------------------------------------------------------------------------------ + + await knex.schema.renameTable('account', 'bk_account'); + await knex.schema.renameTable('account_role', 'bk_account_role'); + await knex.schema.renameTable('ugc_mod_comment', 'bk_ugc_mod_comment'); + await knex.schema.renameTable('note', 'bk_note'); + await knex.schema.renameTable('note_page', 'bk_note_page'); + await knex.schema.renameTable('character', 'bk_character'); + + //------------------------------------------------------------------------------------------------------------------ + // Step 2: Declare new tables + //------------------------------------------------------------------------------------------------------------------ + + // Account Table + await knex.schema.createTable('account', (table) => + { + table.integer('account_id').primary(); + table.string('hash_id').notNullable(); + table.text('email').notNullable() + .unique() + .index(); + table.text('name'); + table.text('avatar'); + table.json('permissions').notNullable() + .defaultTo('[]'); + table.json('settings').notNullable() + .defaultTo('{}'); + table.timestamp('created').notNullable() + .defaultTo(knex.fn.now()); + }); + + // Account Role Table + await knex.schema.createTable('account_role', (table) => + { + table.integer('account_id') + .references('account.account_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('CASCADE'); + table.integer('role_id') + .references('role.role_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('CASCADE'); + }); + + // Mod Comment Table + await knex.schema.createTable('ugc_mod_comment', (table) => + { + table.increments('comment_id').primary(); + table.text('comment').notNullable(); + table.integer('account_id') + .references('account.account_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('CASCADE'); + table.integer('mod_id') + .references('ugc_moderation.mod_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('CASCADE'); + table.timestamp('created').notNullable() + .defaultTo(knex.fn.now()); + table.json('metadata').notNullable() + .defaultTo('{}'); + }); + + // The `notes` table + await knex.schema.createTable('note', (table) => + { + table.integer('note_id').primary(); + table.string('hash_id').notNullable() + .unique() + .index(); + }); + + // The `notes_pages` table + await knex.schema.createTable('note_page', (table) => + { + table.integer('page_id').primary(); + table.text('title').notNullable(); + table.string('content'); + table.integer('note_id') + .references('note.note_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('CASCADE'); + }); + + // The `character` table + await knex.schema.createTable('character', (table) => + { + table.integer('character_id').primary(); + table.string('system').notNullable() + .index(); + table.string('name').notNullable(); + table.text('description'); + table.string('portrait'); + table.string('thumbnail'); + table.string('color'); + table.text('campaign'); + table.json('details').notNullable() + .defaultTo('{}'); + table.integer('note_id') + .references('note.note_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('RESTRICT'); + table.integer('account_id') + .references('account.account_id') + .notNullable() + .onUpdate('CASCADE') + .onDelete('CASCADE'); + }); + + //------------------------------------------------------------------------------------------------------------------ + // Step 3: Copy tables. + //------------------------------------------------------------------------------------------------------------------ + + // Select out all the data from the old tables + const accounts = await knex('bk_account').select(); + const account_roles = await knex('bk_account_role').select(); + const ugc_mod_comments = await knex('bk_ugc_mod_comment').select(); + const notes = await knex('bk_note').select(); + const note_pages = await knex('bk_note_page').select(); + const characters = await knex('bk_character').select(); + + // Insert the data into the new tables + if(accounts.length > 0) + { + await knex('account') + .insert(accounts.map((account, idx) => + { + return { + account_id: idx, + hash_id: account.hash_id, + email: account.email, + name: account.name, + avatar: account.avatar, + permissions: account.permissions, + settings: account.settings, + created: account.created + }; + })); + } + + if(account_roles.length > 0) + { + await knex('account_role') + .insert(account_roles.map((account_role) => + { + const accountID = accounts.findIndex((acc) => acc.account_id === account_role.account_id); + return { + account_id: accountID, + role_id: account_role.role_id + }; + })); + } + + if(ugc_mod_comments.length > 0) + { + await knex('ugc_mod_comment') + .insert(ugc_mod_comments.map((comment) => + { + const accountID = accounts.findIndex((acc) => acc.account_id === comment.account_id); + return { + comment_id: comment.comment_id, + comment: comment.comment, + account_id: accountID, + mod_id: comment.mod_id, + created: comment.created, + metadata: comment.metadata + }; + })); + } + + if(notes.length > 0) + { + + await knex('note') + .insert(notes.map((note, idx) => + { + return { + note_id: idx, + hash_id: note.note_id + }; + })); + } + + if(note_pages.length > 0) + { + await knex('note_page') + .insert(note_pages.map((page) => + { + const noteID = notes.findIndex((nt) => nt.note_id === page.note_id); + return { + page_id: page.page_id, + title: page.title, + content: page.content, + note_id: noteID + }; + })); + } + + if(characters.length > 0) + { + await knex('character') + .insert(characters.map((character, idx) => + { + const noteID = notes.findIndex((nt) => nt.note_id === character.note_id); + const accountID = accounts.findIndex((acc) => acc.account_id === character.account_id); + return { + character_id: idx, + hash_id: character.character_id, + system: character.system, + name: character.name, + description: character.description, + portrait: character.portrait, + thumbnail: character.thumbnail, + color: character.color, + campaign: character.campaign, + details: character.details, + note_id: noteID, + account_id: accountID + }; + })); + } + + //------------------------------------------------------------------------------------------------------------------ + // Step 4: Delete bk_* tables + //------------------------------------------------------------------------------------------------------------------ + + await knex.schema.dropTable('bk_account'); + await knex.schema.dropTable('bk_account_role'); + await knex.schema.dropTable('bk_ugc_mod_comment'); + await knex.schema.dropTable('bk_note'); + await knex.schema.dropTable('bk_note_page'); + await knex.schema.dropTable('bk_character'); + + //------------------------------------------------------------------------------------------------------------------ + // Step 5: Re-add Indexes + //------------------------------------------------------------------------------------------------------------------ + + knex.schema.table('account', (table) => + { + table.dropUnique([ 'email' ]); + table.unique('email'); + }); + + knex.schema.table('account_role', (table) => + { + table.dropIndex([ 'account_id', 'role_id' ]); + table.unique([ 'account_id', 'role_id' ]); + }); +} + +//---------------------------------------------------------------------------------------------------------------------- diff --git a/src/server/knex/seeds/admin_role.ts b/src/server/knex/seeds/admin_role.ts index f04b78ec..a74d468e 100644 --- a/src/server/knex/seeds/admin_role.ts +++ b/src/server/knex/seeds/admin_role.ts @@ -18,8 +18,7 @@ exports.seed = async(knex) => // Check for admin records, and add them if they're not already there. const admins = [ { - account_id: 1, - hash_id: '3VAAgA', + account_id: '3VAAgA', email: 'chris.case@g33xnexus.com', name: 'Morgul', avatar: 'https://lh3.googleusercontent.com/-r8fmbWdlFvg/AAAAAAAAAAI/AAAAAAAAA9g/oWyh8pnmDSY/s96-c/photo.jpg?sz=512', @@ -28,8 +27,7 @@ exports.seed = async(knex) => created: knex.fn.now() }, { - account_id: 2, - hash_id: '3VzoXi', + account_id: '3VzoXi', email: 'null23544@gmail.com', name: 'Lord Null', avatar: 'https://lh6.googleusercontent.com/-uCa4jsA-_i0/AAAAAAAAAAI/AAAAAAAAAB4/chnr3xPv3_c/s96-c/photo.jpg?sz=512', @@ -41,15 +39,13 @@ exports.seed = async(knex) => const mods = [ { - account_id: 3, - hash_id: '3Ks11R', + account_id: '3Ks11R', email: 'travis.a.odom@gmail.com', name: 'Burstaholic', avatar: 'https://lh6.googleusercontent.com/-Cm7eBAJV2gQ/AAAAAAAAAAI/AAAAAAAAAXE/KLFM6YmcWm8/s96-c/photo.jpg?sz=512', permissions: '[]', settings: '{}', created: knex.fn.now() - } ]; diff --git a/src/server/managers/account.ts b/src/server/managers/account.ts index 85bbe500..9fe43656 100644 --- a/src/server/managers/account.ts +++ b/src/server/managers/account.ts @@ -27,7 +27,7 @@ export async function list(filters : AccountFilters) : Promise const db = await getDB(); const query = db('account') .select( - 'hash_id as id', + 'account_id as id', 'email', 'name', 'avatar', @@ -37,7 +37,7 @@ export async function list(filters : AccountFilters) : Promise if(filters.id) { - query.where({ hash_id: filters.id }); + query.where({ account_id: filters.id }); } if(filters.email) @@ -61,19 +61,18 @@ export async function getGroups(accountID : string) : Promise .join('account_role as ar', 'ac.account_id', '=', 'ar.account_id') .join('role as r', 'ar.role_id', '=', 'r.role_id') .where({ - 'ac.hash_id': accountID + 'ac.account_id': accountID }); return roles.map((role) => role.name); } -export async function getRaw(accountID : string) : Promise> +export async function get(accountID : string) : Promise { const db = await getDB(); const accounts = await db('account') .select( - 'account_id', - 'hash_id as id', + 'account_id as id', 'email', 'name', 'avatar', @@ -81,7 +80,7 @@ export async function getRaw(accountID : string) : Promise 1) @@ -95,22 +94,16 @@ export async function getRaw(accountID : string) : Promise -{ - const { account_id, ...restAccount } = await getRaw(accountID); - return Account.fromDB(restAccount); -} - export async function getByEmail(email : string) : Promise { const db = await getDB(); const accounts = await db('account') .select( - 'hash_id as id', + 'account_id as id', 'email', 'name', 'avatar', @@ -164,7 +157,7 @@ export async function update(accountID : string, accountUpdate : Record { const db = await getDB(); await db('account') - .where({ hash_id: accountID }) + .where({ account_id: accountID }) .delete(); return { status: 'ok' }; diff --git a/src/server/managers/character.ts b/src/server/managers/character.ts index 39cf812c..9c584195 100644 --- a/src/server/managers/character.ts +++ b/src/server/managers/character.ts @@ -3,7 +3,6 @@ //---------------------------------------------------------------------------------------------------------------------- // Managers -import * as accountMan from './account'; import * as notebookMan from './notebook'; import systemMan from './system'; @@ -25,7 +24,7 @@ export async function get(id : string) : Promise const db = await getDB(); const characters = await db('character as char') .select( - 'char.hash_id as id', + 'char.character_id as id', 'char.system', 'char.name', 'char.description', @@ -34,12 +33,12 @@ export async function get(id : string) : Promise 'char.color', 'char.campaign', 'char.details', - 'acc.hash_id as accountID', - 'note.hash_id as noteID' + 'acc.account_id as accountID', + 'note.note_id as noteID' ) .join('note', 'note.note_id', '=', 'char.note_id') .join('account as acc', 'acc.account_id', '=', 'char.account_id') - .where({ 'char.hash_id': id }); + .where({ 'char.character_id': id }); if(characters.length > 1) { @@ -54,14 +53,14 @@ export async function get(id : string) : Promise const char = Character.fromDB(characters[0]); return systemMan.validateCharacterDetails(char); } -} // get +} export async function list(filters : Record = {}) : Promise { const db = await getDB(); let query = db('character as char') .select( - 'char.hash_id as id', + 'char.character_id as id', 'char.system', 'char.name', 'char.description', @@ -70,8 +69,8 @@ export async function list(filters : Record = {}) : Promise 'char.color', 'char.campaign', 'char.details', - 'acc.hash_id as accountID', - 'note.hash_id as noteID' + 'acc.account_id as accountID', + 'note.note_id as noteID' ) .join('note', 'note.note_id', '=', 'char.note_id') .join('account as acc', 'acc.account_id', '=', 'char.account_id'); @@ -90,13 +89,9 @@ export async function add(accountID : string, newCharacter : Record { const db = await getDB(); await db('character') - .where({ hash_id: charID }) + .where({ character_id: charID }) .delete(); // Broadcast the update diff --git a/src/server/managers/notebook.ts b/src/server/managers/notebook.ts index d3134a78..2cb8cdba 100644 --- a/src/server/managers/notebook.ts +++ b/src/server/managers/notebook.ts @@ -26,12 +26,12 @@ export async function get(notebookID : string) : Promise const pages = (await db('note_page as np') .select( 'page_id as id', - 'n.hash_id as notebookID', + 'n.note_id as notebookID', 'content', 'title' ) .join('note as n', 'n.note_id', '=', 'np.note_id') - .where({ 'n.hash_id': notebookID })) + .where({ 'n.note_id': notebookID })) .map(NotebookPage.fromDB); return Notebook.fromDB({ id: notebookID, pages }); @@ -41,15 +41,15 @@ export async function list(filters : NoteFilters) : Promise { const db = await getDB(); const query = db('note as n') - .select('n.hash_id as notebookID') - .distinct('n.hash_id') + .select('n.note_id as notebookID') + .distinct('n.note_id') .leftJoin('note_page as np', 'np.note_id', '=', 'n.note_id') .join('character as c', 'c.note_id', '=', 'n.note_id') .join('account as a', 'a.account_id', '=', 'c.account_id'); if(filters.id) { - query.where({ 'n.hash_id': filters.id }); + query.where({ 'n.note_id': filters.id }); } if(filters.email) @@ -69,34 +69,13 @@ export async function list(filters : NoteFilters) : Promise })); } -export async function getRaw(notebookID : string) : Promise> -{ - const db = await getDB(); - const notebooks = await db('note') - .select() - .where({ hash_id: notebookID }); - - if(notebooks.length > 1) - { - throw new MultipleResultsError('notebook'); - } - else if(notebooks.length === 0) - { - throw new NotFoundError(`No notebook record found for notebook '${ notebookID }'.`); - } - else - { - return notebooks[0]; - } -} - export async function getPage(pageID : string | number) : Promise { const db = await getDB(); const pages = await db('note_page as np') .select( 'page_id as id', - 'n.hash_id as notebookID', + 'n.note_id as notebookID', 'content', 'title' ) @@ -122,16 +101,8 @@ export async function addPage(notebookID : string, page : Record - { - throw new NotFoundError(`No notebook record found for id '${ notebookID }'`); - }); - const [ pageID ] = await db('note_page') - .insert({ ...notePage.toDB(), note_id: notebook.id }); + .insert(notePage.toDB()); // Return the notebook page return getPage(pageID); @@ -143,7 +114,7 @@ export async function add(pages : Record[] = []) : Promise @@ -170,8 +141,7 @@ export async function updatePage(pageID : string | number, pageUpdate : Record { const db = await getDB(); await db('note') - .where({ hash_id: notebookID }) + .where({ note_id: notebookID }) .delete(); return { status: 'ok' }; diff --git a/src/server/managers/supplement.ts b/src/server/managers/supplement.ts index 244706aa..cbc94712 100644 --- a/src/server/managers/supplement.ts +++ b/src/server/managers/supplement.ts @@ -7,7 +7,6 @@ import { Knex } from 'knex'; import logging from '@strata-js/util-logging'; // Managers -import * as accountMan from './account'; import * as permMan from './permissions'; // Models @@ -40,13 +39,10 @@ async function $checkViewAccess( // Generally, this is just going to be admins; but hey, why not let admins see everything? if(!permMan.hasPerm(account, `${ systemPrefix }/canViewContent`)) { - // FIXME: This hack should be removed, and `hash_id` should be the foreign_key - const { account_id } = await accountMan.getRaw(account.id); - // Add scoping in query = query.where(function() { - this.where({ scope: 'public' }).orWhere({ scope: 'user', owner: account_id }); + this.where({ scope: 'public' }).orWhere({ scope: 'user', owner: account.id }); }); } } @@ -127,7 +123,7 @@ export async function get(id : number, type : string, systemPrefix : string, acc const tableName = `${ systemPrefix }_${ type }`; const db = await getDB(); const query = db(`${ tableName } as t`) - .select('t.*', 'a.hash_id as ownerHash') + .select('t.*', 'a.account_id as ownerHash') .leftJoin('account as a', 'a.account_id', '=', 't.owner') .where({ id }); @@ -157,7 +153,7 @@ export async function list( const tableName = `${ systemPrefix }_${ type }`; const db = await getDB(); let query = db(`${ tableName } as t`) - .select('t.*', 'a.hash_id as ownerHash') + .select('t.*', 'a.account_id as ownerHash') .leftJoin('account as a', 'a.account_id', '=', 't.owner'); // Add filters for only what we have access to @@ -218,20 +214,8 @@ export async function add( throw new DuplicateSupplementError(`${ systemPrefix }/${ type }/${ supplement.name }`); } - // ===================================================================================== - // FIXME: This hack should be removed, and `hash_id` should be the foreign_key - - let owner; - if(supplement.scope === 'user' && supplement.owner) - { - const { account_id } = await accountMan.getRaw(supplement.owner); - owner = account_id; - } - - // ===================================================================================== - // Now, we insert the supplement - const [ id ] = await db(tableName).insert({ ...supplement.toDB(), owner }); + const [ id ] = await db(tableName).insert(supplement.toDB()); // Return the inserted supplement return get(id, type, systemPrefix, account); @@ -269,21 +253,9 @@ export async function update( // Make sure we have permission to modify await $checkModAccess(newSupplement, systemPrefix, type, account); - // ===================================================================================== - // FIXME: This hack should be removed, and `hash_id` should be the foreign_key - - let owner; - if(newSupplement.scope === 'user' && newSupplement.owner) - { - const { account_id } = await accountMan.getRaw(newSupplement.owner); - owner = account_id; - } - - // ===================================================================================== - // Now, we update the supplement await db(tableName) - .update({ ...newSupplement.toDB(), owner }) + .update(newSupplement.toDB()) .where({ id }); // Return the updated supplement diff --git a/src/server/models/account.ts b/src/server/models/account.ts index ad48f7e9..f2c6e84e 100644 --- a/src/server/models/account.ts +++ b/src/server/models/account.ts @@ -53,10 +53,9 @@ export class Account public toDB() : Record { - const { id, groups, ...jsonObj } = this.toJSON(); + const { groups, ...jsonObj } = this.toJSON(); return { ...jsonObj, - hash_id: id, permissions: JSON.stringify(this.permissions), settings: JSON.stringify(this.settings) }; diff --git a/src/server/models/character.ts b/src/server/models/character.ts index e166da8f..aed56783 100644 --- a/src/server/models/character.ts +++ b/src/server/models/character.ts @@ -70,7 +70,7 @@ export class Character
return { ...jsonObj, details: JSON.stringify(details), - hash_id: id, + character_id: id, account_id: accountID, note_id: noteID }; diff --git a/src/server/models/notebook.ts b/src/server/models/notebook.ts index 8b969b6b..009b48de 100644 --- a/src/server/models/notebook.ts +++ b/src/server/models/notebook.ts @@ -99,7 +99,7 @@ export class Notebook public toDB() : Record { return { - hash_id: this.id + note_id: this.id }; }