aboutsummaryrefslogtreecommitdiff
path: root/src/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.ts')
-rw-r--r--src/index.ts59
1 files changed, 51 insertions, 8 deletions
diff --git a/src/index.ts b/src/index.ts
index 54ff848..c6adf32 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,9 +1,13 @@
/* 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 User } from './db/model/User';
+import { default as UserGroup } from './db/model/UserGroup';
const DEFAULT_PORT: number = 3000;
@@ -12,10 +16,49 @@ 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'
+ });
+
+ await admin.save();
+
+ console.log(admin.id);
+
+ const root: User = new User({
+ username: 'hafeez',
+ password: 'pass',
+ userGroup: admin
+ });
+
+ root.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}`);
+ }
+ });
+})();