diff --git a/lib/client.ts b/lib/client.ts index f288bdf..63bad3d 100644 --- a/lib/client.ts +++ b/lib/client.ts @@ -8,6 +8,8 @@ import { AttributeConditionParserOpts, ButTreeOpenOpts, RequestOptions, + SaveViewPrefsOptions, + ReadViewPrefsOptions, } from "./types"; import { createEvalDomainPayload, @@ -16,6 +18,8 @@ import { createIsShortcutFavoritePayload, makeLoginTokenPayload, createButTreeOpenPayload, + createSaveViewPrefsPayload, + createReadViewPrefsPayload, } from "./payloads"; export class Client { host?: string; @@ -284,4 +288,43 @@ export class Client { options, }); } + + public async saveViewPrefs( + payload: SaveViewPrefsOptions, + options?: RequestOptions, + ): Promise { + const { database, token } = this; + const { key, preferences } = payload; + + const saveViewPrefsPayload = createSaveViewPrefsPayload({ + database: database!, + token: token!, + key, + preferences, + }); + + return await this._fetch({ + payload: saveViewPrefsPayload, + options, + }); + } + + public async readViewPrefs( + payload: ReadViewPrefsOptions, + options?: RequestOptions, + ): Promise { + const { database, token } = this; + const { key } = payload; + + const readViewPrefsPayload = createReadViewPrefsPayload({ + database: database!, + token: token!, + key, + }); + + return await this._fetch({ + payload: readViewPrefsPayload, + options, + }); + } } diff --git a/lib/payloads.ts b/lib/payloads.ts index e557e15..7f609c9 100644 --- a/lib/payloads.ts +++ b/lib/payloads.ts @@ -24,6 +24,8 @@ import { ModelExportDataPayload, ReadForViewPayload, ReadAggPayload, + SaveViewPrefsPayload, + ReadViewPrefsPayload, } from "./types"; export const makeLoginTokenPayload = (options: LoginTokenPayload): Payload => { @@ -424,6 +426,7 @@ export const createReadForViewPayload = ( context, ]; }; + export const createReadAggPayload = (options: ReadAggPayload): Payload => { const { database, token, model, domain, aggregate_fields } = options; return [ @@ -437,3 +440,36 @@ export const createReadAggPayload = (options: ReadAggPayload): Payload => { aggregate_fields, ]; }; + +export const createSaveViewPrefsPayload = ( + options: SaveViewPrefsPayload, +): Payload => { + const { database, token, key, preferences } = options; + return [ + "execute", + database, + "token", + token, + "res.users", + "save_view_prefs", + key, + preferences, + {}, + ]; +}; + +export const createReadViewPrefsPayload = ( + options: ReadViewPrefsPayload, +): Payload => { + const { database, token, key } = options; + return [ + "execute", + database, + "token", + token, + "res.users", + "get_view_prefs", + key, + {}, + ]; +}; diff --git a/lib/types.ts b/lib/types.ts index 5c3eb92..2903aa7 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -247,3 +247,16 @@ export type ReadAggOpts = { }; export type ReadAggPayload = Database & Token & Model & ReadAggOpts; + +export type SaveViewPrefsOptions = { + key: string; + preferences: any; +}; + +export type ReadViewPrefsOptions = { + key: string; +}; + +export type SaveViewPrefsPayload = Database & Token & SaveViewPrefsOptions; + +export type ReadViewPrefsPayload = Database & Token & ReadViewPrefsOptions;