Skip to content

Commit

Permalink
upgrade to express v5.
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgul committed May 16, 2024
1 parent a86f05f commit 42da33f
Show file tree
Hide file tree
Showing 14 changed files with 462 additions and 428 deletions.
666 changes: 342 additions & 324 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"@strata-js/util-config": "^0.6.0",
"@strata-js/util-logging": "^1.2.0",
"axios": "^1.2.2",
"better-sqlite3": "^9.6.0",
"better-sqlite3": "^10.0.0",
"body-parser": "^1.19.0",
"connect-session-knex": "^4.0.0",
"cookie-parser": "^1.4.3",
"decoders": "^1.23.3",
"dotenv": "^16.3.1",
"express": "^4.17.1",
"express": "^5.0.0-beta.3",
"express-session": "^1.17.1",
"helmet": "^7.1.0",
"if-env": "^1.0.4",
Expand Down
3 changes: 3 additions & 0 deletions src/client/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ declare module 'vue' {
BFormCheckbox: typeof import('bootstrap-vue-next')['BFormCheckbox']
BFormGroup: typeof import('bootstrap-vue-next')['BFormGroup']
BFormInput: typeof import('bootstrap-vue-next')['BFormInput']
BFormRadio: typeof import('bootstrap-vue-next')['BFormRadio']
BFormRow: typeof import('bootstrap-vue-next')['BFormRow']
BFormSelect: typeof import('bootstrap-vue-next')['BFormSelect']
BFormSpinbutton: typeof import('bootstrap-vue-next')['BFormSpinbutton']
BImg: typeof import('bootstrap-vue-next')['BImg']
BInputGroup: typeof import('bootstrap-vue-next')['BInputGroup']
BInputGroupAppend: typeof import('bootstrap-vue-next')['BInputGroupAppend']
BInputGroupPrepend: typeof import('bootstrap-vue-next')['BInputGroupPrepend']
BInputGroupText: typeof import('bootstrap-vue-next')['BInputGroupText']
BListGroup: typeof import('bootstrap-vue-next')['BListGroup']
BListGroupItem: typeof import('bootstrap-vue-next')['BListGroupItem']
BModal: typeof import('bootstrap-vue-next')['BModal']
Expand All @@ -44,6 +46,7 @@ declare module 'vue' {
BRow: typeof import('bootstrap-vue-next')['BRow']
BTab: typeof import('bootstrap-vue-next')['BTab']
BTable: typeof import('bootstrap-vue-next')['BTable']
BTableLite: typeof import('bootstrap-vue-next')['BTableLite']
BTableSimple: typeof import('bootstrap-vue-next')['BTableSimple']
BTabs: typeof import('bootstrap-vue-next')['BTabs']
BTbody: typeof import('bootstrap-vue-next')['BTbody']
Expand Down
23 changes: 13 additions & 10 deletions src/server/routes/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

import express from 'express';

import { ensureAuthenticated, errorHandler, wrapAsync } from './utils';

// Managers
import * as accountMan from '../managers/account';
import * as permsMan from '../managers/permissions';

// Models
import { Account } from '../models/account';
import * as permsMan from '../managers/permissions';

// Utils
import { convertQueryToRecord, ensureAuthenticated, errorHandler } from './utils';

// Logger
import logging from '@strata-js/util-logging';
Expand All @@ -22,17 +24,18 @@ const router = express.Router();

//----------------------------------------------------------------------------------------------------------------------

router.get('/', wrapAsync(async(req, resp) =>
router.get('/', async(req, resp) =>
{
const filters = { id: req.query.id, email: req.query.email, name: req.query.name };
const query = convertQueryToRecord(req);
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;
return restAccount;
}));
}));
});

router.get('/:accountID', wrapAsync(async(req, resp) =>
router.get('/:accountID', async(req, resp) =>
{
const user = req.user as Account;
const account = await accountMan.get(req.params.accountID);
Expand All @@ -48,14 +51,14 @@ router.get('/:accountID', wrapAsync(async(req, resp) =>
const { permissions, groups, settings, ...restAccount } = account;
resp.json(restAccount);
}
}));
});

router.patch('/:accountID', ensureAuthenticated, wrapAsync(async(req, resp) =>
router.patch('/:accountID', ensureAuthenticated, async(req, resp) =>
{
// Update the account
const newAccount = await accountMan.update(req.params.accountID, req.body);
resp.json(newAccount);
}));
});

//----------------------------------------------------------------------------------------------------------------------
// Error Handling
Expand Down
25 changes: 14 additions & 11 deletions src/server/routes/characters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as permsMan from '../managers/permissions';
import sysMan from '../managers/system';

// Utils
import { ensureAuthenticated, errorHandler, interceptHTML, parseQuery, wrapAsync } from './utils';
import { convertQueryToRecord, ensureAuthenticated, errorHandler, interceptHTML, parseQuery } from './utils';
import { Account } from '../models/account';

// Logger
Expand All @@ -28,12 +28,14 @@ router.get('/', async(req, resp) =>
{
interceptHTML(resp, async() =>
{
const query = convertQueryToRecord(req);

// If we pass in `owner`, it'll be an email address, so we need to look that up first, and shove the correct
// account id into the filters as if that was passed in.
let owner = req.query.owner;
let owner = query.owner;
if(owner)
{
delete req.query.owner;
delete query.owner;

if(Array.isArray(owner))
{
Expand All @@ -44,16 +46,17 @@ router.get('/', async(req, resp) =>
{
owner = owner.toLowerCase();
const account = await accountMan.getByEmail(owner);
req.query.accountID = `${ account.id }`;
query.accountID = `${ account.id }`;
}
}

const filters = parseQuery(req.query as Record<string, string>);
const filters = parseQuery(query);

resp.json(await charMan.list(filters));
});
});

router.post('/', ensureAuthenticated, wrapAsync(async(req, resp) =>
router.post('/', ensureAuthenticated, async(req, resp) =>
{
const char = { ...req.body };
const system = sysMan.get(char.system);
Expand All @@ -70,7 +73,7 @@ router.post('/', ensureAuthenticated, wrapAsync(async(req, resp) =>
message: `The character with id '${ char.id }' has an invalid or unknown system '${ char.system }'.`
});
}
}));
});

router.get('/:charID', (req, resp) =>
{
Expand All @@ -80,7 +83,7 @@ router.get('/:charID', (req, resp) =>
});
});

router.patch('/:charID', ensureAuthenticated, wrapAsync(async(req, resp) =>
router.patch('/:charID', ensureAuthenticated, async(req, resp) =>
{
// First, retrieve the character
const char = await charMan.get(req.params.charID);
Expand Down Expand Up @@ -113,9 +116,9 @@ router.patch('/:charID', ensureAuthenticated, wrapAsync(async(req, resp) =>
message: `You are not authorized to update character '${ req.params.charID }'.`
});
}
}));
});

router.delete('/:charID', ensureAuthenticated, wrapAsync(async(req, resp) =>
router.delete('/:charID', ensureAuthenticated, async(req, resp) =>
{
let char;
try
Expand Down Expand Up @@ -151,7 +154,7 @@ router.delete('/:charID', ensureAuthenticated, wrapAsync(async(req, resp) =>
message: `You are not authorized to update character '${ req.params.charID }'.`
});
}
}));
});

//----------------------------------------------------------------------------------------------------------------------
// Error Handling
Expand Down
33 changes: 17 additions & 16 deletions src/server/routes/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import express from 'express';

import { ensureAuthenticated, errorHandler, wrapAsync } from './utils';
import { convertQueryToRecord, ensureAuthenticated, errorHandler } from './utils';

// Managers
import * as noteMan from '../managers/notebook';
Expand All @@ -23,11 +23,12 @@ const router = express.Router();

//----------------------------------------------------------------------------------------------------------------------

router.get('/', wrapAsync(async(req, resp) =>
router.get('/', async(req, resp) =>
{
if(req.isAuthenticated() && await hasPerm(req.user as Account, 'Notes/canViewAll'))
{
const filters = { id: req.query.id, email: req.query.email, title: req.query.title };
const query = convertQueryToRecord(req);
const filters = { id: query.id, email: query.email, title: query.title };
resp.json(await noteMan.list(filters));
}
else
Expand All @@ -39,20 +40,20 @@ router.get('/', wrapAsync(async(req, resp) =>
message: `You are not authorized to view all notes.`
});
}
}));
});

router.post('/', ensureAuthenticated, wrapAsync(async(req, resp) =>
router.post('/', ensureAuthenticated, async(req, resp) =>
{
const pages = req.body.pages;
resp.json(await noteMan.add(pages));
}));
});

router.get('/:noteID', wrapAsync(async(req, resp) =>
router.get('/:noteID', async(req, resp) =>
{
resp.json(await noteMan.get(req.params.noteID));
}));
});

router.post('/:noteID/pages', ensureAuthenticated, wrapAsync(async(req, resp) =>
router.post('/:noteID/pages', ensureAuthenticated, async(req, resp) =>
{
const page = req.body;

Expand All @@ -65,22 +66,22 @@ router.post('/:noteID/pages', ensureAuthenticated, wrapAsync(async(req, resp) =>

// Update the note
resp.json(await noteMan.addPage(note.id, page));
}));
});

router.patch('/:noteID/pages/:pageID', ensureAuthenticated, wrapAsync(async(req, resp) =>
router.patch('/:noteID/pages/:pageID', ensureAuthenticated, async(req, resp) =>
{
// Update the note
const newPage = await noteMan.updatePage(req.params.pageID, req.body);
resp.json(newPage);
}));
});

router.delete('/:noteID', ensureAuthenticated, wrapAsync(async(req, resp) =>
router.delete('/:noteID', ensureAuthenticated, async(req, resp) =>
{
// We don't check for existence, so we can be idempotent
resp.json(await noteMan.remove(req.params.noteID));
}));
});

router.delete('/:noteID/pages/:pageID', ensureAuthenticated, wrapAsync(async(req, resp) =>
router.delete('/:noteID/pages/:pageID', ensureAuthenticated, async(req, resp) =>
{
const notebook = await noteMan.get(req.params.noteID);
const page = (notebook.pages.filter((pageInst) => pageInst.id == req.params.pageID))[0];
Expand All @@ -95,7 +96,7 @@ router.delete('/:noteID/pages/:pageID', ensureAuthenticated, wrapAsync(async(req
// We don't throw an error, so we can be idempotent
resp.json({ status: 'ok' });
}
}));
});

//----------------------------------------------------------------------------------------------------------------------
// Error Handling
Expand Down
6 changes: 3 additions & 3 deletions src/server/routes/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import express from 'express';

import { errorHandler, wrapAsync } from './utils';
import { errorHandler } from './utils';

// Managers
import * as rolesMan from '../managers/roles';
Expand All @@ -19,10 +19,10 @@ const router = express.Router();

//----------------------------------------------------------------------------------------------------------------------

router.get('/', wrapAsync(async(_req, resp) =>
router.get('/', async(_req, resp) =>
{
resp.json((await rolesMan.list()));
}));
});

//----------------------------------------------------------------------------------------------------------------------
// Error Handling
Expand Down
9 changes: 5 additions & 4 deletions src/server/routes/systems/eote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import refMan from '../../managers/references';

// Utils
import { buildSupplementRoute } from './utils/supplement';
import { errorHandler, wrapAsync, parseQuery } from '../utils';
import { errorHandler, parseQuery, convertQueryToRecord } from '../utils';

// Logger
import logging from '@strata-js/util-logging';
Expand All @@ -30,11 +30,12 @@ buildSupplementRoute(router, '/talents', 'talent', 'eote');
buildSupplementRoute(router, '/weapons', 'weapon', 'eote');
buildSupplementRoute(router, '/forcepowers', 'forcepower', 'eote');

router.get('/references', wrapAsync(async(req, resp) =>
router.get('/references', async(req, resp) =>
{
const filters = parseQuery(req.query as Record<string, string>);
const query = convertQueryToRecord(req);
const filters = parseQuery(query);
resp.json(await refMan.getFiltered(filters, 'eote_reference'));
}));
});

//----------------------------------------------------------------------------------------------------------------------
// Error Handling
Expand Down
9 changes: 5 additions & 4 deletions src/server/routes/systems/genesys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import refMan from '../../managers/references';

// Utils
import { buildSupplementRoute } from './utils/supplement';
import { errorHandler, parseQuery, wrapAsync } from '../utils';
import { convertQueryToRecord, errorHandler, parseQuery } from '../utils';

// Logger
import logging from '@strata-js/util-logging';
Expand All @@ -30,11 +30,12 @@ buildSupplementRoute(router, '/talents', 'talent', 'genesys');
buildSupplementRoute(router, '/weapons', 'weapon', 'genesys');
buildSupplementRoute(router, '/motivations', 'motivation', 'genesys');

router.get('/references', wrapAsync(async(req, resp) =>
router.get('/references', async(req, resp) =>
{
const filters = parseQuery(req.query as Record<string, string>);
const query = convertQueryToRecord(req);
const filters = parseQuery(query);
resp.json(await refMan.getFiltered(filters, 'genesys_reference'));
}));
});

//----------------------------------------------------------------------------------------------------------------------
// Error Handling
Expand Down

0 comments on commit 42da33f

Please sign in to comment.