diff options
| author | josh97josh | 2018-04-20 23:47:19 +0100 |
|---|---|---|
| committer | josh97josh | 2018-04-20 23:47:19 +0100 |
| commit | 9ea66944ccb2c7c4dfa5f80bf1ef4637636d9a9f (patch) | |
| tree | 5923488d4ea27371557972ff0dd238f228d8b284 /src | |
| parent | Merge branch 'trh/gets' into 'jl247/permissions' (diff) | |
| download | medicine-9ea66944ccb2c7c4dfa5f80bf1ef4637636d9a9f.tar.gz medicine-9ea66944ccb2c7c4dfa5f80bf1ef4637636d9a9f.zip | |
get project fixed
Diffstat (limited to 'src')
| -rw-r--r-- | src/FileRouter.ts | 9 | ||||
| -rw-r--r-- | src/db/model/Project.ts | 20 |
2 files changed, 14 insertions, 15 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 0882272..dc57ab2 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -14,6 +14,7 @@ import { uuid } from './uuid'; import UserHasPrivilege from './db/model/UserHasPrivilege'; import { Contains } from 'sequelize-typescript'; import UserJoinsProject from './db/model/UserJoinsProject'; +import { appendFileSync } from 'fs'; /** @@ -481,9 +482,9 @@ const getProjects: Middleware = async( User ] }); - res.locals.data = projects.map( - (p: Project): ProjectFullInfo => p.fullInfo - ); + res.locals.data = Promise.all(projects.map( + (p: Project): Promise<ProjectFullInfo> => p.getFullInfo() + )); next(); }; @@ -513,7 +514,7 @@ const getProjectName: Middleware = async( if (project == null) { return next(new RequestError(404, 'project_not_found')); } else { - res.locals.data = project.fullInfo; + res.locals.data = await project.getFullInfo(); next(); } }; diff --git a/src/db/model/Project.ts b/src/db/model/Project.ts index a7f1199..fa49fea 100644 --- a/src/db/model/Project.ts +++ b/src/db/model/Project.ts @@ -100,41 +100,39 @@ export default class Project extends Model<Project> { projectName: this.name } }) - const people: String[] = ujps.map((ujp: UserJoinsProject): String => { + const people: String[] = await ujps.map((ujp: UserJoinsProject): String => { if(ujp.contributorGroup != undefined){ - console.log(ujp.contributorGroupName) return ujp.contributorGroupName } else{ throw new Error(`unimplemented, ${this}`); } }) - //console.log(people); - return await people; + return people; } - public getUserInfo(user: User): UserInfo { + public async getUserInfo(user: User): Promise<UserInfo> { return { username: user.username, - access_level: this.getAccessLevel(user).toString() + access_level: (await this.getAccessLevel(user)).join() }; } - public get fullInfo(): ProjectFullInfo { + public async getFullInfo(): Promise<ProjectFullInfo> { if (this.contributors === undefined) { throw new Error('contributors undefined'); } + //console.log(await this.getUserInfo(this.contributors[0])) return { project_name: this.name, - users: this.contributors - .map((u: User): UserInfo => this.getUserInfo(u)), + users: await Promise.all(this.contributors + .map( (u: User): Promise<UserInfo> => this.getUserInfo(u))), public_metadata: { creation_date: this.creationDate }, - // TODO: Check if we have anything to use these for yet? private_metadata: {}, admin_metadata: {} - }; + } } } |
