Skip to content

Commit

Permalink
feat: add method for publicEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Volland committed May 2, 2024
1 parent d5738d7 commit ad8bae6
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/service/GenericEntityService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,58 @@ export abstract class GenericEntityService<T extends BaseEntity> extends Permiss
}
}

async getIsPublic(id: string | number, fetchOpts?: RequestInit): Promise<boolean> {
try {
const response = await fetch(`${this.basePath}/${id}/permissions/public`, {
method: 'GET',
headers: {
...getBearerTokenHeader(this.keycloak)
},
...fetchOpts
});
const result = await response.json();
return result.public;
} catch (error) {
throw new Error(`Error while checking if an entity is public: ${error}`);
}
}

async setPublic(id: string | number, fetchOpts?: RequestInit): Promise<void> {
try {
const response = await fetch(`${this.basePath}/${id}/permissions/public`, {
method: 'POST',
headers: {
...getBearerTokenHeader(this.keycloak)
},
...fetchOpts
});

if (!response.ok) {
throw new Error(`HTTP error status: ${response.status}`);
}
} catch (error) {
throw new Error(`Error while setting an entity as public: ${error}`);
}
}

async revokePublic(id: string | number, fetchOpts?: RequestInit): Promise<void> {
try {
const response = await fetch(`${this.basePath}/${id}/permissions/public`, {
method: 'DELETE',
headers: {
...getBearerTokenHeader(this.keycloak)
},
...fetchOpts
});

if (!response.ok) {
throw new Error(`HTTP error status: ${response.status}`);
}
} catch (error) {
throw new Error(`Error while setting an entity as not public: ${error}`);
}
}

getBasePath(): string {
return this.basePath;
}
Expand Down

0 comments on commit ad8bae6

Please # to comment.