Skip to content

Commit

Permalink
fix(tokens): fix repository token getter
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuri committed Aug 20, 2017
1 parent a68f774 commit 1f3f283
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/api/db/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ export function getBuild(id: number): Promise<any> {
return run;
});

build.repository.access_token = build.repository.access_token.token || null;
if (build.repository.access_token && build.repository.access_token) {
build.repository.access_token = build.repository.access_token.token;
} else {
build.repository.access_token = null;
}

return build;
})
.then(build => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/db/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export class AccessToken extends Bookshelf.Model<any> {
export class Repository extends Bookshelf.Model<any> {
get tableName() { return 'repositories'; }
get hasTimestamps() { return true; }
builds() { return this.hasMany(Build, 'repositories_id'); }
access_token() { return this.belongsTo(AccessToken, 'access_tokens_id'); }
builds() { return this.hasMany(Build, 'repositories_id'); }
}

export class Build extends Bookshelf.Model<any> {
Expand Down
6 changes: 4 additions & 2 deletions src/api/db/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ export function getRepository(id: number): Promise<any> {

export function getRepositoryOnly(id: number): Promise<any> {
return new Promise((resolve, reject) => {
new Repository({ id: id }).fetch({ withRelated: ['access_token.user'] }).then(repo => {
new Repository({ id: id }).fetch({ withRelated: ['access_token'] }).then(repo => {
if (!repo) {
reject(repo);
} else {
repo = repo.toJSON();
repo.access_token = repo.access_token.token || null;

repo.access_token = repo.access_token && repo.access_token.token ?
repo.access_token.token : null;

resolve(repo);
}
Expand Down

0 comments on commit 1f3f283

Please sign in to comment.