Skip to content

Commit

Permalink
fix(appClient): same client method getting and updating settings base…
Browse files Browse the repository at this point in the history
…d on in params
  • Loading branch information
eikeland committed Nov 15, 2024
1 parent e11a258 commit c86ff99
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions packages/modules/app/src/AppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ export class AppClient implements IAppClient {
#manifest: Query<AppManifest, { appKey: string }>;
#manifests: Query<AppManifest[], { filterByCurrentUser?: boolean } | undefined>;
#config: Query<AppConfig, { appKey: string; tag?: string }>;
#settings: Query<AppSettings, { appKey: string }>;
#setSettings: Query<AppSettings, { appKey: string; settings: AppSettings }>;
#settings: Query<AppSettings, { appKey: string; settings?: AppSettings }>;

constructor(client: IHttpClient) {
const expire = 1 * 60 * 1000;
Expand Down Expand Up @@ -132,31 +131,19 @@ export class AppClient implements IAppClient {
expire,
});

this.#settings = new Query<AppSettings, { appKey: string }>({
client: {
fn: ({ appKey }) => {
return client.json(`/persons/me/apps/${appKey}/settings`, {
headers: {
'Api-Version': '1.0',
},
});
},
},
key: (args) => JSON.stringify(args),
expire,
});
this.#setSettings = new Query<AppSettings, { appKey: string; settings: AppSettings }>({
this.#settings = new Query<AppSettings, { appKey: string; settings?: AppSettings }>({
client: {
fn: ({ appKey, settings }) => {
console.log('query', appKey, settings);
return client.fetch(`/persons/me/apps/${appKey}/settings`, {
method: 'PUT',
const init: RequestInit = {
headers: {
'Api-Version': '1.0',
'Content-Type': 'application/json',
},
body: JSON.stringify(settings),
});
};
if (settings) {
init.method = 'PUT';
init.body = JSON.stringify(settings);
}
return client.json(`/persons/me/apps/${appKey}/settings`, init);
},
},
key: (args) => JSON.stringify(args),
Expand Down Expand Up @@ -225,7 +212,7 @@ export class AppClient implements IAppClient {
}

updateAppSettings(args: { appKey: string; settings: AppSettings }): Observable<AppSettings> {
return this.#setSettings.query(args).pipe(
return this.#settings.query(args).pipe(
queryValue,
catchError((err) => {
/** extract cause, since error will be a `QueryError` */
Expand All @@ -247,7 +234,6 @@ export class AppClient implements IAppClient {
this.#manifests.complete();
this.#config.complete();
this.#settings.complete();
this.#setSettings.complete();
}
}

Expand Down

0 comments on commit c86ff99

Please sign in to comment.