Skip to content

Commit

Permalink
feat: update sdk to handle optional paramaters
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMunizOdoo committed Jan 3, 2025
1 parent 3a0598a commit cd4ef81
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/sdk-api-client/src/api/mutation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Endpoints, OdooIntegrationContext, MutationMetadataParams } from '../..
import consola from 'consola';

export const mutation: Endpoints['mutation'] = async <ApiParams, ApiResponseType>(context: OdooIntegrationContext, metadata: MutationMetadataParams, params?: ApiParams) => {

if(!metadata || !metadata.mutationName) {
const msg = 'Developer Error: mutationName is required'
consola.error(msg);
Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/src/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ export const odooConnector = (options: Options): Methods => {
};

if (options.ofetch) {
mutation = async <ApiParams, ApiResponseType>(metadata: MutationMetadataParams, params?: ApiParams): Promise<ApiResponseType> => {
return options.ofetch('/api/odoo/mutation', { method: 'POST', body: [metadata, params], cache: 'no-cache', watch: false, ...options.ofetchOptions } as any);
mutation = async <ApiParams, ApiResponseType>(metadata: MutationMetadataParams, params?: ApiParams, opt?: { headers: any }): Promise<ApiResponseType> => {
return options.ofetch('/api/odoo/mutation', { method: 'POST', body: [metadata, params], cache: 'no-cache', watch: false, ...opt } as any);
};

query = async <ApiParams, ApiResponseType>(metadata: QueryMetadataParams, params?: ApiParams): Promise<ApiResponseType> =>{
query = async <ApiParams, ApiResponseType>(metadata: QueryMetadataParams, params?: ApiParams, opt?: { headers: any }): Promise<ApiResponseType> =>{
const cacheKey = metadata.cacheKey || hash({ ...metadata, ...params });
return options.ofetch('/api/odoo/query', { method: 'POST', body: [metadata, params], cache: 'no-cache', watch: false, key: cacheKey, ...options.ofetchOptions } as any);
return options.ofetch('/api/odoo/query', { method: 'POST', body: [metadata, params], cache: 'no-cache', watch: false, key: cacheKey, ...opt } as any);
};

queryNoCache = async <ApiParams, ApiResponseType>(metadata: QueryMetadataParams, params?: ApiParams): Promise<ApiResponseType> =>{
queryNoCache = async <ApiParams, ApiResponseType>(metadata: QueryMetadataParams, params?: ApiParams, opt?: { headers: any }): Promise<ApiResponseType> =>{
const cacheKey = metadata.cacheKey || hash({ ...metadata, ...params });
return options.ofetch('/api/odoo/query-no-cache', { method: 'POST', body: [metadata, params], cache: 'no-cache', watch: false, key: cacheKey, ...options.ofetchOptions } as any);
return options.ofetch('/api/odoo/query-no-cache', { method: 'POST', body: [metadata, params], cache: 'no-cache', watch: false, key: cacheKey, ...opt } as any);
};
}

Expand Down
11 changes: 6 additions & 5 deletions packages/sdk/src/methods/mutation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { MutationMetadataParams } from '@erpgap/odoo-sdk-api-client';
import { client } from '../../index';

/**
* Make the query
*
* @example
* Mutate the Odoo API
* @param metadata The metadata of the mutation - Example: { mutationName: MutationName.CreateUpdatePartner }
* @param params The parameters of the mutation (typed by ApiParams ) - Example: { id: countryId }
* @returns The response of the mutation (typed by ApiResponseType)
*/
export async function mutation<ApiParams, ApiResponseType,>(metadata: MutationMetadataParams, params?: ApiParams): Promise<ApiResponseType> {
return await client.post('mutation', [metadata, params]);
export async function mutation<ApiParams, ApiResponseType>(metadata: MutationMetadataParams, params?: ApiParams, opt?: { headers: any }): Promise<ApiResponseType> {
return await client.post('mutation', [metadata, params], opt);
}
11 changes: 6 additions & 5 deletions packages/sdk/src/methods/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { QueryMetadataParams, Endpoints } from '@erpgap/odoo-sdk-api-client';
import { client } from '../../client';

/**
* Make the query
*
* @example
* Query the Odoo API
* @param metadata The metadata of the query - Example: { queryName: QueryName.GetWebsiteHomepage }
* @param params The parameters of the query (typed by ApiParams ) - Example: { id: countryId }
* @returns The response of the query (typed by ApiResponseType)
*/
export async function query<ApiParams, ApiResponseType>(metadata: QueryMetadataParams, params?: ApiParams): Promise<ApiResponseType> {
return await client.post('query', [metadata, params]);
export async function query<ApiParams, ApiResponseType>(metadata: QueryMetadataParams, params?: ApiParams, opt?: { headers: any }): Promise<ApiResponseType> {
return await client.post('query', [metadata, params], opt);
}

0 comments on commit cd4ef81

Please sign in to comment.