aboutsummaryrefslogtreecommitdiff
path: root/src/index.ts
diff options
context:
space:
mode:
authorTom Harley2018-02-22 18:47:08 +0000
committerTom Harley2018-02-22 18:47:08 +0000
commit5dafe924bbbd5cc09901186ff74e4b68a6dcd52f (patch)
treeff4a76d6eaed5773d89d0da6a02d788ffe210abb /src/index.ts
parentMerge branch 'master' into trh/payload-checker (diff)
downloadmedicine-5dafe924bbbd5cc09901186ff74e4b68a6dcd52f.tar.gz
medicine-5dafe924bbbd5cc09901186ff74e4b68a6dcd52f.zip

Revert “Revert”Merge branch ‘trh/error-middleware’ into ‘master’""

This reverts commit 3198c6c2474101623e3b95bd038effe210c176a8.

Diffstat (limited to 'src/index.ts')
-rw-r--r--src/index.ts49
1 files changed, 41 insertions, 8 deletions
diff --git a/src/index.ts b/src/index.ts
index 54ff848..06989ef 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,9 +1,12 @@
/* tslint:disable:no-console
* This only goes here until we have a logging system */
-import app from './app';
+console.log('begin import');
+import { default as app } from './app';
+import { default as seq } from './db/orm';
+console.log('end import');
-console.log('Welcome to the CS3099 Server thingy!');
+import { default as UserGroup } from './db/model/UserGroup';
const DEFAULT_PORT: number = 3000;
@@ -12,10 +15,40 @@ const port: number = process.env.PORT
? process.env.PORT
: DEFAULT_PORT;
-app.listen(port, (err: Error): void => {
- if (err) {
- return console.log(err);
- }
+// tslint:disable:no-floating-promises
+(async(): Promise<void> => {
+ console.log('Booting PSQL database');
- return console.log(`server is listening on port ${port}`);
-});
+ await seq.authenticate();
+
+ console.log('Resetting Database');
+
+ await seq.sync({
+ force: true
+ });
+
+ const admin: UserGroup = new UserGroup({
+ name: 'admin',
+ canCreateUsers: true,
+ canDeleteUsers: true,
+ canEditUsers: true,
+ canCreateProjects: true,
+ canDeleteProjects: true,
+ canEditProjects: true,
+ isInternal: false,
+ description: 'Systems admin'
+ });
+
+ // tslint:disable:no-floating-promises
+ admin.save();
+
+ console.log('Booting ExpressJS server');
+
+ app.listen(port, (err: Error) => {
+ if (err) {
+ return console.log(err);
+ } else {
+ return console.log(`server is listening on port ${port}`);
+ }
+ });
+})();