Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/module app/appsettings/getter #2577

Merged
merged 13 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(appClient): same client method getting and updating settings base…
…d on in params
  • Loading branch information
eikeland authored and odinr committed Dec 2, 2024
commit a6f0d11a9773f15ea114102028bc9e0b8dcfc0de
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