aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FileRouter.ts30
-rw-r--r--src/db/model/ContributorGroup.ts2
-rw-r--r--src/db/model/File.ts13
-rw-r--r--src/db/model/User.ts3
-rw-r--r--src/index.ts25
-rw-r--r--src/matcher/options.ts9
-rw-r--r--src/matcher/types.ts25
7 files changed, 75 insertions, 32 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts
index 151cdf6..bffc454 100644
--- a/src/FileRouter.ts
+++ b/src/FileRouter.ts
@@ -31,9 +31,12 @@ export class FileRouter {
})
*/
public getProtocols(req: Request, res: Response, next: NextFunction){
- var returnValue = {};
- returnValue['supported'] = ["BE50"];
- returnValue['required'] = "BE01";
+ var returnValue = {
+ supported: [],
+ required: [
+ "BE01"
+ ]
+ };
res.send(JSON.stringify(returnValue));
}
@@ -179,8 +182,12 @@ export class FileRouter {
})
*/
public getUsers(req: Request, res: Response, next: NextFunction){
- User.findAll()
- .then((user) => {
+ User.findAll({
+ include: [
+ UserGroup,
+ Project
+ ]
+ }).then((user) => {
res.json(user.map<any>(
(u: User) => u.getUserFullInfo()
));
@@ -200,7 +207,11 @@ export class FileRouter {
let user: User = await User.findOne({
where: {
username: name
- }
+ },
+ include: [
+ UserGroup,
+ Project
+ ]
});
return user.getUserFullInfo();
@@ -315,8 +326,11 @@ export class FileRouter {
})
*/
public getProjects(req: Request, res: Response, next: NextFunction){
- Project.findAll()
- .then((projects) => {
+ Project.findAll({
+ include: [
+ User
+ ]
+ ).then((projects) => {
res.json(projects.map<any>(
(p: Project) => p.getProjectFullInfo()
));
diff --git a/src/db/model/ContributorGroup.ts b/src/db/model/ContributorGroup.ts
index 8ecb648..0fe859d 100644
--- a/src/db/model/ContributorGroup.ts
+++ b/src/db/model/ContributorGroup.ts
@@ -8,7 +8,7 @@ export default class ContributorGroup extends Model<ContributorGroup> {
name: string;
// "Error: Foreign key for "ContributorGroup" is missing on "UserJoinsProject"."
- // @HasMany(() => UserJoinsProject)
+ @HasMany(() => UserJoinsProject, 'contributorGroupId')
uses: UserJoinsProject[];
@Column
diff --git a/src/db/model/File.ts b/src/db/model/File.ts
index b8cf784..09323e2 100644
--- a/src/db/model/File.ts
+++ b/src/db/model/File.ts
@@ -1,5 +1,5 @@
import {Table, Model, Column, Unique, PrimaryKey, ForeignKey, AllowNull,
- HasMany, BelongsTo, CreatedAt, UpdatedAt} from 'sequelize-typescript';
+ HasMany, BelongsTo, CreatedAt, UpdatedAt, HasOne} from 'sequelize-typescript';
import { default as User } from './User';
import { default as Project } from './Project';
@@ -33,14 +33,9 @@ export default class File extends Model<File> {
@BelongsTo(() => User)
creator: User;
-
- // @ForeignKey(() => Project)
- // @AllowNull
- // @Column
- // rootFolderOfProjectId: string;
- //
- // @BelongsTo(() => Project)
- // rootFolderOf: Project;
+
+ @HasOne(() => Project)
+ rootFolderOf: Project;
@CreatedAt
@Column
diff --git a/src/db/model/User.ts b/src/db/model/User.ts
index 1f7f146..c677fcd 100644
--- a/src/db/model/User.ts
+++ b/src/db/model/User.ts
@@ -45,9 +45,10 @@ export default class User extends Model<User> {
}
getUserFullInfo() : UserFullInfo {
+ console.log(this);
return {
username : this.username,
- privileges : [this.userGroup.name],
+ privileges: [this.userGroup.name],
projects : this.projects.map<ProjectInfo>(
(p: Project) => this.getProjectInfo(p)
),
diff --git a/src/index.ts b/src/index.ts
index a8756ad..5e8a9d0 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,6 +1,9 @@
import { default as seq } from './db/orm';
import { default as app } from './app';
+import { default as User } from './db/model/UserGroup';
+import { default as UserGroup } from './db/model/UserGroup';
+
// use default port 3000 or port supplied by OS
const port: number = process.env.PORT || 3000;
@@ -8,10 +11,32 @@ const port: number = process.env.PORT || 3000;
console.log('Booting PSQL database');
await seq.authenticate();
+
+ console.log('Resetting Database');
+
await seq.sync({
force: true
});
+ let admin: UserGroup = new UserGroup({
+ name: 'admin',
+ canCreateUsers: true,
+ canDeleteUsers: true,
+ canEditUsers: true,
+ canCreateProjects: true,
+ canDeleteProjects: true,
+ canEditProjects: true,
+ isInternal: false,
+ description: 'Systems admin'
+ });
+ admin.save();
+
+ // let user: User = new User({
+ // username: 'Tom',
+ // password: 'woa'
+ // });
+ // user.save();
+
console.log('Booting ExpressJS server');
app.listen(port, (err) => {
diff --git a/src/matcher/options.ts b/src/matcher/options.ts
index 7412675..c1d1aeb 100644
--- a/src/matcher/options.ts
+++ b/src/matcher/options.ts
@@ -75,3 +75,12 @@ export function array(template: Object, values?: Array<Object>) {
let m = match(template) as ((Object) => boolean);
return values.every(m);
}
+
+const options = {
+ match = match,
+ exact = exact,
+ optional = optional,
+ alternative = alternative,
+ array = array
+};
+export default options;
diff --git a/src/matcher/types.ts b/src/matcher/types.ts
index 70b2d47..3870df4 100644
--- a/src/matcher/types.ts
+++ b/src/matcher/types.ts
@@ -4,19 +4,19 @@ function typeCheckerGenerator<T>(test: T): (v: any) => v is T {
return f;
}
-let isObject = typeCheckerGenerator<Object>({});
-let isNumber = typeCheckerGenerator<Number>(0);
-let isString = typeCheckerGenerator<String>("");
-let isBoolean = typeCheckerGenerator<Boolean>(true);
-let isArray = typeCheckerGenerator<Array<any>>([]);
-let isFunction = typeCheckerGenerator<Function>(new Function());
-let isNull = (v) => v === null;
-let isUndefined = (v) => v === undefined;
-let isPresent = (v) => !isUndefined(v);
-let isInteger = (value: any) => isNumber(value)
- && Number.isInteger(value as number);
+export const isObject = typeCheckerGenerator<Object>({});
+export const isNumber = typeCheckerGenerator<Number>(0);
+export const isString = typeCheckerGenerator<String>("");
+export const isBoolean = typeCheckerGenerator<Boolean>(true);
+export const isArray = typeCheckerGenerator<Array<any>>([]);
+export const isFunction = typeCheckerGenerator<Function>(new Function());
+export const isNull = (v) => v === null;
+export const isUndefined = (v) => v === undefined;
+export const isPresent = (v) => !isUndefined(v);
+export const isInteger = (value: any) => isNumber(value)
+ && Number.isInteger(value as number);
-let types = {
+const types = {
object: isObject,
number: isNumber,
string: isString,
@@ -29,5 +29,4 @@ let types = {
undefined: isUndefined,
anything: isPresent
};
-
export default types;