Skip to content

Commit 1f3f283

Browse files
committed
fix(tokens): fix repository token getter
1 parent a68f774 commit 1f3f283

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/api/db/build.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ export function getBuild(id: number): Promise<any> {
6464
return run;
6565
});
6666

67-
build.repository.access_token = build.repository.access_token.token || null;
67+
if (build.repository.access_token && build.repository.access_token) {
68+
build.repository.access_token = build.repository.access_token.token;
69+
} else {
70+
build.repository.access_token = null;
71+
}
72+
6873
return build;
6974
})
7075
.then(build => {

src/api/db/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export class AccessToken extends Bookshelf.Model<any> {
1616
export class Repository extends Bookshelf.Model<any> {
1717
get tableName() { return 'repositories'; }
1818
get hasTimestamps() { return true; }
19-
builds() { return this.hasMany(Build, 'repositories_id'); }
2019
access_token() { return this.belongsTo(AccessToken, 'access_tokens_id'); }
20+
builds() { return this.hasMany(Build, 'repositories_id'); }
2121
}
2222

2323
export class Build extends Bookshelf.Model<any> {

src/api/db/repository.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ export function getRepository(id: number): Promise<any> {
4242

4343
export function getRepositoryOnly(id: number): Promise<any> {
4444
return new Promise((resolve, reject) => {
45-
new Repository({ id: id }).fetch({ withRelated: ['access_token.user'] }).then(repo => {
45+
new Repository({ id: id }).fetch({ withRelated: ['access_token'] }).then(repo => {
4646
if (!repo) {
4747
reject(repo);
4848
} else {
4949
repo = repo.toJSON();
50-
repo.access_token = repo.access_token.token || null;
50+
51+
repo.access_token = repo.access_token && repo.access_token.token ?
52+
repo.access_token.token : null;
5153

5254
resolve(repo);
5355
}

0 commit comments

Comments
 (0)