From fdfe9ab31ab06d324a6e343ec69a79cb1d8d1229 Mon Sep 17 00:00:00 2001 From: "Christopher S. Case" Date: Mon, 20 May 2024 00:32:04 -0500 Subject: [PATCH] moved to plain account model. --- src/common/interfaces/models/account.ts | 5 +- src/server/auth/serialization.ts | 2 +- src/server/decoders/account.ts | 28 --- src/server/express-shim.d.ts | 12 +- src/server/managers/account.ts | 154 ++------------ src/server/managers/permissions.ts | 2 +- src/server/managers/supplement.ts | 2 +- src/server/models/account.ts | 81 ------- src/server/models/character.ts | 2 +- src/server/models/notebook.ts | 4 +- src/server/models/reference.ts | 2 +- src/server/models/role.ts | 2 +- src/server/models/supplement.ts | 2 +- src/server/resource-access/account.ts | 197 ++++++++++++++++++ .../resource-access/transforms/account.ts | 44 ++++ src/server/routes/accounts.ts | 11 +- src/server/routes/characters.ts | 9 +- src/server/routes/notebook.ts | 5 +- src/server/routes/systems/index.ts | 5 +- src/server/routes/systems/utils/supplement.ts | 13 +- src/server/systems/eote/validations.ts | 2 +- src/server/tsconfig.json | 3 +- 22 files changed, 299 insertions(+), 288 deletions(-) delete mode 100644 src/server/decoders/account.ts delete mode 100644 src/server/models/account.ts create mode 100644 src/server/resource-access/account.ts create mode 100644 src/server/resource-access/transforms/account.ts diff --git a/src/common/interfaces/models/account.ts b/src/common/interfaces/models/account.ts index cddf9d8c..bc32bb84 100644 --- a/src/common/interfaces/models/account.ts +++ b/src/common/interfaces/models/account.ts @@ -2,9 +2,8 @@ // Account //---------------------------------------------------------------------------------------------------------------------- -// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface AccountSettings { - // TODO: Figure out some settings... + colorMode ?: 'light' | 'dark' | 'auto'; } export interface AccountOptions { @@ -20,4 +19,6 @@ export interface AccountOptions { // FIXME: Once Models are removed, `AccountOptions` should be named 'Account'. export type Account = AccountOptions; +export type NewAccount = Omit; + //---------------------------------------------------------------------------------------------------------------------- diff --git a/src/server/auth/serialization.ts b/src/server/auth/serialization.ts index 6fda30b7..2d2fb056 100644 --- a/src/server/auth/serialization.ts +++ b/src/server/auth/serialization.ts @@ -8,7 +8,7 @@ import passport from 'passport'; import * as accountMan from '../managers/account'; // Models -import { Account } from '../models/account'; +import { Account } from '../../common/interfaces/models/account'; //---------------------------------------------------------------------------------------------------------------------- diff --git a/src/server/decoders/account.ts b/src/server/decoders/account.ts deleted file mode 100644 index 5cb31d38..00000000 --- a/src/server/decoders/account.ts +++ /dev/null @@ -1,28 +0,0 @@ -// --------------------------------------------------------------------------------------------------------------------- -// Account Decoders -// --------------------------------------------------------------------------------------------------------------------- - -import { array, email, inexact, string, object } from 'decoders'; -import { jsonArrayString, jsonObjectString, stringWithLength, withDefault } from './utils'; - -// --------------------------------------------------------------------------------------------------------------------- - -export const accountRecDecoder = object({ - id: string, - email, - name: stringWithLength(3, 255), - avatar: stringWithLength(3, 255), - permissions: jsonArrayString(string), - settings: jsonObjectString(inexact({})) -}); - -export const accountJsonDecoder = object({ - id: string, - email, - name: stringWithLength(3, 255), - avatar: stringWithLength(3, 255), - permissions: withDefault(array(string), []), - settings: withDefault(inexact({}), {}) -}); - -// --------------------------------------------------------------------------------------------------------------------- diff --git a/src/server/express-shim.d.ts b/src/server/express-shim.d.ts index 6d42b51d..ad88eb63 100644 --- a/src/server/express-shim.d.ts +++ b/src/server/express-shim.d.ts @@ -3,13 +3,21 @@ // --------------------------------------------------------------------------------------------------------------------- // Models -import { Account } from './models/account'; +import { Account } from '../../common/interfaces/models/account'; // --------------------------------------------------------------------------------------------------------------------- +declare global { + namespace Express { + interface User { + email : string; + id : string; + } + } +} + declare global { export namespace Express { - // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface User extends Account {} export interface Request { user ?: User; diff --git a/src/server/managers/account.ts b/src/server/managers/account.ts index 9fe43656..94f8b5ab 100644 --- a/src/server/managers/account.ts +++ b/src/server/managers/account.ts @@ -3,174 +3,46 @@ // --------------------------------------------------------------------------------------------------------------------- // Models -import { Account } from '../models/account'; +import { Account, NewAccount } from '../../common/interfaces/models/account'; -// Errors -import { MultipleResultsError, NotFoundError } from '../errors'; - -// Utils -import { getDB } from '../utils/database'; -import { shortID } from '../utils/misc'; - -// --------------------------------------------------------------------------------------------------------------------- - -export interface AccountFilters { - id : unknown, - email : unknown, - name : unknown -} +// Resource Access +import * as accountRA from '../resource-access/account'; // --------------------------------------------------------------------------------------------------------------------- -export async function list(filters : AccountFilters) : Promise +export async function list(filters : accountRA.AccountFilters) : Promise { - const db = await getDB(); - const query = db('account') - .select( - 'account_id as id', - 'email', - 'name', - 'avatar', - 'permissions', - 'settings' - ); - - if(filters.id) - { - query.where({ account_id: filters.id }); - } - - if(filters.email) - { - query.where({ email: filters.email }); - } - - if(filters.name) - { - query.where({ name: filters.name }); - } - - return (await query).map(Account.fromDB); + return accountRA.list(filters); } export async function getGroups(accountID : string) : Promise { - const db = await getDB(); - const roles = await db('account as ac') - .select('r.name as name', 'r.role_id as id') - .join('account_role as ar', 'ac.account_id', '=', 'ar.account_id') - .join('role as r', 'ar.role_id', '=', 'r.role_id') - .where({ - 'ac.account_id': accountID - }); - - return roles.map((role) => role.name); + return accountRA.getGroups(accountID); } export async function get(accountID : string) : Promise { - const db = await getDB(); - const accounts = await db('account') - .select( - 'account_id as id', - 'email', - 'name', - 'avatar', - 'permissions', - 'settings' - ) - .where({ - account_id: accountID - }); - - if(accounts.length > 1) - { - throw new MultipleResultsError('account'); - } - else if(accounts.length === 0) - { - throw new NotFoundError(`No account record found for account '${ accountID }'.`); - } - else - { - const groups = await getGroups(accountID); - return Account.fromDB({ ...accounts[0], groups }); - } + return accountRA.get(accountID); } export async function getByEmail(email : string) : Promise { - const db = await getDB(); - const accounts = await db('account') - .select( - 'account_id as id', - 'email', - 'name', - 'avatar', - 'permissions', - 'settings' - ) - .where({ email }); - - if(accounts.length > 1) - { - throw new MultipleResultsError('account'); - } - else if(accounts.length === 0) - { - throw new NotFoundError(`No account record found with email '${ email }'.`); - } - else - { - const groups = await getGroups(accounts[0].id); - return Account.fromDB({ ...accounts[0], groups }); - } + return accountRA.getByEmail(email); } -export async function add(newAccount : Record) : Promise +export async function add(newAccount : NewAccount) : Promise { - const account = Account.fromJSON({ ...newAccount, id: shortID(), created: Date.now() }); - const db = await getDB(); - await db('account') - .insert(account.toDB()); - - return get(account.id); + return accountRA.add(newAccount); } -export async function update(accountID : string, accountUpdate : Record) : Promise +export async function update(accountID : string, accountUpdate : Partial) : Promise { - // Get the current account - const account = await get(accountID); - - // Mix the current account with the allowed updates. - const allowedUpdate = { - ...account.toJSON(), - name: accountUpdate.name ?? account.name, - avatar: accountUpdate.avatar ?? account.avatar, - settings: accountUpdate.settings ?? account.settings - }; - - // Make a new account object - const newAccount = Account.fromJSON(allowedUpdate); - - // Update the database - const db = await getDB(); - await db('account') - .update(newAccount.toDB()) - .where({ account_id: accountID }); - - // Return the updated record - return get(accountID); + return accountRA.update(accountID, accountUpdate); } export async function remove(accountID : string) : Promise<{ status : 'ok' }> { - const db = await getDB(); - await db('account') - .where({ account_id: accountID }) - .delete(); - - return { status: 'ok' }; + return accountRA.remove(accountID); } // --------------------------------------------------------------------------------------------------------------------- diff --git a/src/server/managers/permissions.ts b/src/server/managers/permissions.ts index cd94d035..6a8ca6f4 100644 --- a/src/server/managers/permissions.ts +++ b/src/server/managers/permissions.ts @@ -8,7 +8,7 @@ import tp from 'trivialperms'; import * as rolesMan from './roles'; // Models -import { Account } from '../models/account'; +import { Account } from '../../common/interfaces/models/account'; //---------------------------------------------------------------------------------------------------------------------- diff --git a/src/server/managers/supplement.ts b/src/server/managers/supplement.ts index cbc94712..cac01e78 100644 --- a/src/server/managers/supplement.ts +++ b/src/server/managers/supplement.ts @@ -10,7 +10,7 @@ import logging from '@strata-js/util-logging'; import * as permMan from './permissions'; // Models -import { Account } from '../models/account'; +import { Account } from '../../common/interfaces/models/account'; import { Supplement } from '../models/supplement'; // Utilities diff --git a/src/server/models/account.ts b/src/server/models/account.ts deleted file mode 100644 index f2c6e84e..00000000 --- a/src/server/models/account.ts +++ /dev/null @@ -1,81 +0,0 @@ -//---------------------------------------------------------------------------------------------------------------------- -// Account -//---------------------------------------------------------------------------------------------------------------------- - -import * as JsonDecoder from 'decoders'; - -// Models -import { AccountOptions, AccountSettings } from '../../common/interfaces/models/account'; - -// Decoders -import { accountJsonDecoder, accountRecDecoder } from '../decoders/account'; - -//---------------------------------------------------------------------------------------------------------------------- - -export class Account -{ - public readonly id : string; - public readonly email : string = ''; - - public name = ''; - public avatar = ''; - public permissions : string[] = []; - public groups : string[] = []; - public settings : AccountSettings = {}; - - constructor(options : AccountOptions) - { - this.id = options.id; - this.email = options.email; - this.name = options.name ?? options.email.split('@')[0]; - this.avatar = options.avatar || ''; - this.permissions = options.permissions ?? []; - this.groups = options.groups ?? []; - this.settings = options.settings ?? {}; - } - - //------------------------------------------------------------------------------------------------------------------ - // Serialization - //------------------------------------------------------------------------------------------------------------------ - - public toJSON() : Record - { - return { - id: this.id, - email: this.email, - name: this.name, - avatar: this.avatar, - permissions: this.permissions, - groups: this.groups, - settings: this.settings - }; - } // end - - public toDB() : Record - { - const { groups, ...jsonObj } = this.toJSON(); - return { - ...jsonObj, - permissions: JSON.stringify(this.permissions), - settings: JSON.stringify(this.settings) - }; - } - - //------------------------------------------------------------------------------------------------------------------ - // Deserialization - //------------------------------------------------------------------------------------------------------------------ - - static fromDB(accountRecord : Record) : Account - { - const decoder = JsonDecoder.guard(accountRecDecoder); - return new Account(decoder(accountRecord)); - } - - static fromJSON(jsonObj : Record) : Account - { - const decoder = JsonDecoder.guard(accountJsonDecoder); - return new Account(decoder(jsonObj)); - } -} - -//---------------------------------------------------------------------------------------------------------------------- diff --git a/src/server/models/character.ts b/src/server/models/character.ts index aed56783..ed75881a 100644 --- a/src/server/models/character.ts +++ b/src/server/models/character.ts @@ -62,7 +62,7 @@ export class Character
campaign: this.campaign, details: this.details }; - } // end + } public toDB() : Record { diff --git a/src/server/models/notebook.ts b/src/server/models/notebook.ts index 009b48de..378876ec 100644 --- a/src/server/models/notebook.ts +++ b/src/server/models/notebook.ts @@ -38,7 +38,7 @@ export class NotebookPage content: this.content, notebookID: this.notebookID }; - } // end + } public toDB() : Record { @@ -94,7 +94,7 @@ export class Notebook id: this.id, pages: this.pages.map((page) => page.toJSON()) }; - } // end + } public toDB() : Record { diff --git a/src/server/models/reference.ts b/src/server/models/reference.ts index 812f9ff4..3062bde2 100644 --- a/src/server/models/reference.ts +++ b/src/server/models/reference.ts @@ -36,7 +36,7 @@ export class Reference name: this.name, productCode: this.productCode }; - } // end + } public toDB() : Record { diff --git a/src/server/models/role.ts b/src/server/models/role.ts index ca4e8821..478f568e 100644 --- a/src/server/models/role.ts +++ b/src/server/models/role.ts @@ -36,7 +36,7 @@ export class Role name: this.name, permissions: this.permissions }; - } // end + } public toDB() : Record { diff --git a/src/server/models/supplement.ts b/src/server/models/supplement.ts index dd2a8534..36542761 100644 --- a/src/server/models/supplement.ts +++ b/src/server/models/supplement.ts @@ -52,7 +52,7 @@ export class Supplement scope: this.scope, official: this.official }; - } // end + } public toDB() : Record { diff --git a/src/server/resource-access/account.ts b/src/server/resource-access/account.ts new file mode 100644 index 00000000..2e1f4385 --- /dev/null +++ b/src/server/resource-access/account.ts @@ -0,0 +1,197 @@ +// --------------------------------------------------------------------------------------------------------------------- +// Account Resource Access +// --------------------------------------------------------------------------------------------------------------------- + +// Models +import { Account, NewAccount } from '../../common/interfaces/models/account'; + +// Transforms +import * as AccountTransforms from './transforms/account'; + +// Utils +import { getDB } from '../utils/database'; +import { shortID } from '../utils/misc'; + +// Errors +import { MultipleResultsError, NotFoundError } from '../errors'; + +// --------------------------------------------------------------------------------------------------------------------- + +export interface AccountFilters { + id ?: string | string[], + email ?: string | string[] + name ?: string | string[] +} + +// --------------------------------------------------------------------------------------------------------------------- + +export async function list(filters : AccountFilters) : Promise +{ + const db = await getDB(); + const query = db('account') + .select( + 'account_id', + 'email', + 'name', + 'avatar', + 'permissions', + 'settings' + ); + + if(filters.id) + { + if(Array.isArray(filters.id)) + { + query.whereIn('account_id', filters.id); + } + else + { + query.where({ account_id: filters.id }); + } + } + + if(filters.email) + { + if(Array.isArray(filters.email)) + { + query.whereIn('email', filters.email); + } + else + { + query.where({ email: filters.email }); + } + } + + if(filters.name) + { + if(Array.isArray(filters.name)) + { + query.whereIn('name', filters.name); + } + else + { + query.where({ name: filters.name }); + } + } + + return (await query).map(AccountTransforms.fromDB); +} + +export async function getGroups(accountID : string) : Promise +{ + const db = await getDB(); + const roles = await db('account as ac') + .select('r.name as name', 'r.role_id as id') + .join('account_role as ar', 'ac.account_id', '=', 'ar.account_id') + .join('role as r', 'ar.role_id', '=', 'r.role_id') + .where({ + 'ac.account_id': accountID + }); + + return roles.map((role) => role.name); +} + +export async function get(accountID : string) : Promise +{ + const db = await getDB(); + const accounts = await db('account') + .select( + 'account_id', + 'email', + 'name', + 'avatar', + 'permissions', + 'settings' + ) + .where({ + account_id: accountID + }); + + if(accounts.length > 1) + { + throw new MultipleResultsError('account'); + } + else if(accounts.length === 0) + { + throw new NotFoundError(`No account record found for account '${ accountID }'.`); + } + else + { + const groups = await getGroups(accountID); + return AccountTransforms.fromDB({ ...accounts[0], groups }); + } +} + +export async function getByEmail(email : string) : Promise +{ + const db = await getDB(); + const accounts = await db('account') + .select( + 'account_id', + 'email', + 'name', + 'avatar', + 'permissions', + 'settings' + ) + .where({ email }); + + if(accounts.length > 1) + { + throw new MultipleResultsError('account'); + } + else if(accounts.length === 0) + { + throw new NotFoundError(`No account record found with email '${ email }'.`); + } + else + { + const groups = await getGroups(accounts[0].account_id); + return AccountTransforms.fromDB({ ...accounts[0], groups }); + } +} + +export async function add(newAccount : NewAccount) : Promise +{ + const account = AccountTransforms.toDB(newAccount); + const db = await getDB(); + await db('account') + .insert({ ...account, id: shortID(), created: db.fn.now() }); + + return get(account.account_id); +} + +export async function update(accountID : string, accountUpdate : Partial) : Promise +{ + // Get the current account + const account = await get(accountID); + + // Mix the current account with the allowed updates. + const allowedUpdate = { + ...account, + name: accountUpdate.name ?? account.name, + avatar: accountUpdate.avatar ?? account.avatar, + settings: accountUpdate.settings ?? account.settings ?? { colorMode: 'auto' } + }; + + // Update the database + const db = await getDB(); + await db('account') + .update(AccountTransforms.toDB(allowedUpdate)) + .where({ account_id: accountID }); + + // Return the updated record + return get(accountID); +} + +export async function remove(accountID : string) : Promise<{ status : 'ok' }> +{ + const db = await getDB(); + await db('account') + .where({ account_id: accountID }) + .delete(); + + return { status: 'ok' }; +} + +// --------------------------------------------------------------------------------------------------------------------- diff --git a/src/server/resource-access/transforms/account.ts b/src/server/resource-access/transforms/account.ts new file mode 100644 index 00000000..dbd1cddb --- /dev/null +++ b/src/server/resource-access/transforms/account.ts @@ -0,0 +1,44 @@ +// --------------------------------------------------------------------------------------------------------------------- +// Account Database Transform +// --------------------------------------------------------------------------------------------------------------------- + +import { Account, NewAccount } from '../../../common/interfaces/models/account'; + +// --------------------------------------------------------------------------------------------------------------------- + +export interface AccountDBSchema { + account_id : string; + email : string; + name ?: string; + avatar ?: string; + permissions : string; + settings : string; +} + +// --------------------------------------------------------------------------------------------------------------------- + +export function toDB(account : NewAccount | Account) : AccountDBSchema +{ + // Cast to Account to handle `id` correctly + const { id, groups, ...rest } = account as Account; + return { + ...rest, + account_id: id, + permissions: JSON.stringify(this.permissions ?? []), + settings: JSON.stringify(this.settings ?? {}) + }; +} + +export function fromDB(account : AccountDBSchema) : Account +{ + return { + id: account.account_id, + email: account.email, + name: account.name, + avatar: account.avatar, + permissions: JSON.parse(account.permissions) ?? [], + settings: JSON.parse(account.settings) ?? {} + }; +} + +// --------------------------------------------------------------------------------------------------------------------- diff --git a/src/server/routes/accounts.ts b/src/server/routes/accounts.ts index f536c452..60a447b6 100644 --- a/src/server/routes/accounts.ts +++ b/src/server/routes/accounts.ts @@ -9,7 +9,7 @@ import * as accountMan from '../managers/account'; import * as permsMan from '../managers/permissions'; // Models -import { Account } from '../models/account'; +// import { Account } from '../models/account'; // Utils import { convertQueryToRecord, ensureAuthenticated, errorHandler } from './utils'; @@ -27,7 +27,12 @@ const router = express.Router(); router.get('/', async(req, resp) => { const query = convertQueryToRecord(req); - const filters = { id: query.id, email: query.email, name: query.name }; + const filters = { + id: query.id, + email: query.email, + name: query.name + }; + resp.json((await accountMan.list(filters)).map((accountObj) => { const { permissions, settings, groups, ...restAccount } = accountObj; @@ -37,7 +42,7 @@ router.get('/', async(req, resp) => router.get('/:accountID', async(req, resp) => { - const user = req.user as Account; + const user = req.user; const account = await accountMan.get(req.params.accountID); const sameOrAdmin = user && (user.id === req.params.accountID || permsMan.hasPerm(user, `Accounts/canViewDetails`)); diff --git a/src/server/routes/characters.ts b/src/server/routes/characters.ts index 54897d2b..045e10fb 100644 --- a/src/server/routes/characters.ts +++ b/src/server/routes/characters.ts @@ -12,7 +12,6 @@ import sysMan from '../managers/system'; // Utils import { convertQueryToRecord, ensureAuthenticated, errorHandler, interceptHTML, parseQuery } from './utils'; -import { Account } from '../models/account'; // Logger import logging from '@strata-js/util-logging'; @@ -52,6 +51,8 @@ router.get('/', async(req, resp) => const filters = parseQuery(query); + console.log('filters:', filters); + resp.json(await charMan.list(filters)); }); }); @@ -63,7 +64,7 @@ router.post('/', ensureAuthenticated, async(req, resp) => if(system) { - resp.json(await charMan.add((req.user as Account).id, char)); + resp.json(await charMan.add(req.user.id, char)); } else { @@ -94,7 +95,7 @@ router.patch('/:charID', ensureAuthenticated, async(req, resp) => if(system) { // Allow either the owner, or moderators/admins to modify the character - if(char.accountID === (req.user as Account).id || permsMan.hasPerm(req.user as Account, `${ char.system }/canModifyChar`)) + if(char.accountID === req.user.id || permsMan.hasPerm(req.user, `${ char.system }/canModifyChar`)) { // Update the character resp.json(await charMan.update(req.params.charID, req.body)); @@ -141,7 +142,7 @@ router.delete('/:charID', ensureAuthenticated, async(req, resp) => } // Allow either the owner, or moderators/admins to delete the character - if(char.accountID === (req.user as Account).id || permsMan.hasPerm(req.user as Account, `${ char.system }/canDeleteChar`)) + if(char.accountID === req.user.id || permsMan.hasPerm(req.user, `${ char.system }/canDeleteChar`)) { // Delete the character resp.json(await charMan.remove(req.params.charID)); diff --git a/src/server/routes/notebook.ts b/src/server/routes/notebook.ts index cbbdfec4..f8227132 100644 --- a/src/server/routes/notebook.ts +++ b/src/server/routes/notebook.ts @@ -10,9 +10,6 @@ import { convertQueryToRecord, ensureAuthenticated, errorHandler } from './utils import * as noteMan from '../managers/notebook'; import { hasPerm } from '../managers/permissions'; -// Models -import { Account } from '../models/account'; - // Logger import logging from '@strata-js/util-logging'; const logger = logging.getLogger(module.filename); @@ -25,7 +22,7 @@ const router = express.Router(); router.get('/', async(req, resp) => { - if(req.isAuthenticated() && await hasPerm(req.user as Account, 'Notes/canViewAll')) + if(req.isAuthenticated() && await hasPerm(req.user, 'Notes/canViewAll')) { const query = convertQueryToRecord(req); const filters = { id: query.id, email: query.email, title: query.title }; diff --git a/src/server/routes/systems/index.ts b/src/server/routes/systems/index.ts index 8c5555a0..77cf082a 100644 --- a/src/server/routes/systems/index.ts +++ b/src/server/routes/systems/index.ts @@ -2,7 +2,6 @@ // Routes for system operations //---------------------------------------------------------------------------------------------------------------------- -import _ from 'lodash'; import express from 'express'; // Managers @@ -11,7 +10,6 @@ import systemMan from '../../managers/system'; // Utils import { errorHandler, interceptHTML } from '../utils'; -import { Account } from '../../models/account'; // Sub-routes import eoteRouter from './eote'; @@ -33,8 +31,7 @@ router.get('/', (request, response) => const systems = systemMan.systems .filter((system) => { - const user = _.get(request, 'user', { permissions: [], groups: [] }); - return permMan.hasPerm(user as Account, 'Systems/viewDisabled') || system.status !== 'disabled'; + return permMan.hasPerm(request.user, 'Systems/viewDisabled') || system.status !== 'disabled'; }); response.json(systems); diff --git a/src/server/routes/systems/utils/supplement.ts b/src/server/routes/systems/utils/supplement.ts index fa424d08..3339a7c2 100644 --- a/src/server/routes/systems/utils/supplement.ts +++ b/src/server/routes/systems/utils/supplement.ts @@ -7,9 +7,6 @@ import { IRouter } from 'express'; // Managers import * as suppMan from '../../../managers/supplement'; -// Models -import { Account } from '../../../models/account'; - // Utils import { ensureAuthenticated, parseQuery, convertQueryToRecord } from '../../utils'; @@ -25,7 +22,7 @@ export function buildSupplementRoute(router : IRouter, path : string, type : str { const query = convertQueryToRecord(req); const filters = parseQuery(query); - resp.json(await suppMan.list(filters, type, systemPrefix, req.user as Account)); + resp.json(await suppMan.list(filters, type, systemPrefix, req.user)); }); router.get(`${ path }/:suppID`, async(req, resp) => @@ -33,7 +30,7 @@ export function buildSupplementRoute(router : IRouter, path : string, type : str const suppID = parseInt(req.params.suppID); if(Number.isFinite(suppID)) { - resp.json(await suppMan.get(suppID, type, systemPrefix, req.user as Account)); + resp.json(await suppMan.get(suppID, type, systemPrefix, req.user)); } else { @@ -47,7 +44,7 @@ export function buildSupplementRoute(router : IRouter, path : string, type : str router.post(path, ensureAuthenticated, async(req, resp) => { - resp.json(await suppMan.add(req.body, type, systemPrefix, req.user as Account)); + resp.json(await suppMan.add(req.body, type, systemPrefix, req.user)); }); router.patch(`${ path }/:suppID`, ensureAuthenticated, async(req, resp) => @@ -55,7 +52,7 @@ export function buildSupplementRoute(router : IRouter, path : string, type : str const suppID = parseInt(req.params.suppID); if(Number.isFinite(suppID)) { - resp.json(await suppMan.update(suppID, req.body, type, systemPrefix, req.user as Account)); + resp.json(await suppMan.update(suppID, req.body, type, systemPrefix, req.user)); } else { @@ -72,7 +69,7 @@ export function buildSupplementRoute(router : IRouter, path : string, type : str const suppID = parseInt(req.params.suppID); if(Number.isFinite(suppID)) { - resp.json(await suppMan.remove(suppID, type, systemPrefix, req.user as Account)); + resp.json(await suppMan.remove(suppID, type, systemPrefix, req.user)); } else { diff --git a/src/server/systems/eote/validations.ts b/src/server/systems/eote/validations.ts index 34042478..6d74dca5 100644 --- a/src/server/systems/eote/validations.ts +++ b/src/server/systems/eote/validations.ts @@ -3,7 +3,7 @@ //---------------------------------------------------------------------------------------------------------------------- // Models -import { Account } from '../../models/account'; +import { Account } from '../../../common/interfaces/models/account'; import { Character } from '../../models/character'; // Managers diff --git a/src/server/tsconfig.json b/src/server/tsconfig.json index 9fdcd624..c534ae61 100644 --- a/src/server/tsconfig.json +++ b/src/server/tsconfig.json @@ -14,7 +14,8 @@ "resolveJsonModule": true }, "files": [ - "./server.ts" + "./server.ts", + "express-shim.d.ts" ], "include": [ "../common/**/*.ts",