Skip to content

Commit

Permalink
Merge branch 'feat/user_view_prefs' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Jul 29, 2024
2 parents 493a45a + 08e04d2 commit fbcd5e6
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
43 changes: 43 additions & 0 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
AttributeConditionParserOpts,
ButTreeOpenOpts,
RequestOptions,
SaveViewPrefsOptions,
ReadViewPrefsOptions,
} from "./types";
import {
createEvalDomainPayload,
Expand All @@ -16,6 +18,8 @@ import {
createIsShortcutFavoritePayload,
makeLoginTokenPayload,
createButTreeOpenPayload,
createSaveViewPrefsPayload,
createReadViewPrefsPayload,
} from "./payloads";
export class Client {
host?: string;
Expand Down Expand Up @@ -284,4 +288,43 @@ export class Client {
options,
});
}

public async saveViewPrefs(
payload: SaveViewPrefsOptions,
options?: RequestOptions,
): Promise<any> {
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<any> {
const { database, token } = this;
const { key } = payload;

const readViewPrefsPayload = createReadViewPrefsPayload({
database: database!,
token: token!,
key,
});

return await this._fetch({
payload: readViewPrefsPayload,
options,
});
}
}
36 changes: 36 additions & 0 deletions lib/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
ModelExportDataPayload,
ReadForViewPayload,
ReadAggPayload,
SaveViewPrefsPayload,
ReadViewPrefsPayload,
} from "./types";

export const makeLoginTokenPayload = (options: LoginTokenPayload): Payload => {
Expand Down Expand Up @@ -424,6 +426,7 @@ export const createReadForViewPayload = (
context,
];
};

export const createReadAggPayload = (options: ReadAggPayload): Payload => {
const { database, token, model, domain, aggregate_fields } = options;
return [
Expand All @@ -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,
{},
];
};
13 changes: 13 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit fbcd5e6

Please sign in to comment.