Skip to content

Commit

Permalink
[code-sync] Update /v1/collection endpoint response
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanp413 authored and roboquat committed Dec 12, 2022
1 parent ab0f640 commit cd289d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class CodeSyncResourceDBSpec {

@test()
async createDeleteCollection(): Promise<void> {
const currentCollections1 = await this.db.getCollections(this.userId);
const currentCollections1 = (await this.db.getCollections(this.userId)).map(({ id }) => id);
expect(currentCollections1).to.be.empty;

const collections: string[] = [];
Expand All @@ -186,20 +186,20 @@ export class CodeSyncResourceDBSpec {
}
expect(collections.length).to.be.equal(5);

const currentCollections2 = await this.db.getCollections(this.userId);
const currentCollections2 = (await this.db.getCollections(this.userId)).map(({ id }) => id);
expect(currentCollections2.sort()).to.deep.equal(collections.slice().sort());

await this.db.deleteCollection(this.userId, collections[0], async () => {});
await this.db.deleteCollection(this.userId, collections[1], async () => {});
collections.shift();
collections.shift();

const currentCollections3 = await this.db.getCollections(this.userId);
const currentCollections3 = (await this.db.getCollections(this.userId)).map(({ id }) => id);
expect(currentCollections3.sort()).to.deep.equal(collections.slice().sort());

await this.db.deleteCollection(this.userId, undefined, async () => {});

const currentCollections4 = await this.db.getCollections(this.userId);
const currentCollections4 = (await this.db.getCollections(this.userId)).map(({ id }) => id);
expect(currentCollections4).to.be.empty;
}

Expand Down
4 changes: 2 additions & 2 deletions components/gitpod-db/src/typeorm/code-sync-resource-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,13 @@ export class CodeSyncResourceDB {
.getMany();
}

async getCollections(userId: string): Promise<string[]> {
async getCollections(userId: string): Promise<{ id: string }[]> {
const connection = await this.typeORM.getConnection();
const result = await connection.manager
.createQueryBuilder(DBCodeSyncCollection, "collection")
.where("collection.userId = :userId AND collection.deleted = 0", { userId })
.getMany();
return result.map((r) => r.collection);
return result.map((r) => ({ id: r.collection }));
}

async isCollection(userId: string, collection: string): Promise<boolean> {
Expand Down

0 comments on commit cd289d4

Please sign in to comment.