Skip to content

Commit

Permalink
feat: add new read for view method
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed May 14, 2024
1 parent 83610b4 commit 3642af7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ModelFieldsGetOpts,
ModelExportDataOpts,
RequestOptions,
ReadForViewOpts,
} from "./types";
import {
createSearchPayload,
Expand All @@ -32,6 +33,7 @@ import {
createPermReadPayload,
createFieldsGetPayload,
createExportDataPayload,
createReadForViewPayload,
} from "./payloads";

export class Model {
Expand Down Expand Up @@ -400,4 +402,28 @@ export class Model {
options,
});
}

public async read_for_view(
data: ReadForViewOpts,
options?: RequestOptions,
): Promise<any> {
const { view_id, domain = [], context, version } = data;
const { model } = this;
const { database, token } = this.client;

const payload = createReadForViewPayload({
database: database!,
token: token!,
model,
view_id,
context,
domain,
version,
});

return await this.client._fetch({
payload,
options,
});
}
}
27 changes: 27 additions & 0 deletions lib/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ButTreeOpenPayload,
ModelFieldsGetPayload,
ModelExportDataPayload,
ReadForViewPayload,
} from "./types";

export const makeLoginTokenPayload = (options: LoginTokenPayload): Payload => {
Expand Down Expand Up @@ -396,3 +397,29 @@ export const createExportDataPayload = (
context,
];
};

export const createReadForViewPayload = (
options: ReadForViewPayload,
): Payload => {
const {
database,
token,
model,
domain,
view_id,
context = {},
version,
} = options;
return [
"execute",
database,
"token",
token,
model,
"read_for_view",
view_id,
domain,
version,
context,
];
};
9 changes: 9 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,12 @@ export type ModelExportDataPayload = Database &
ModelExportDataOpts;

export type RequestOptions = any;

export type ReadForViewOpts = {
domain?: any[];
view_id: number;
context?: Context;
version?: number;
};

export type ReadForViewPayload = Database & Token & Model & ReadForViewOpts;

0 comments on commit 3642af7

Please sign in to comment.