Skip to content

Commit

Permalink
Merge branch 'v2' into v2-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Sep 17, 2024
2 parents 3f7c7ea + 546febc commit dab3a26
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 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;
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gisce/powerp.js",
"version": "2.3.2",
"version": "2.4.0",
"description": "PowERP Javascript Client",
"module": "./dist/powerpjs.es.js",
"files": [
Expand Down

0 comments on commit dab3a26

Please sign in to comment.