From c6bf58dae863d7c0c6b2ceb4ff9f59eca17fb56e Mon Sep 17 00:00:00 2001 From: Siddharth9890 <siddharth.a9890@gmail.com> Date: Mon, 8 Jan 2024 18:31:18 +0530 Subject: [PATCH] feat: added default values for all getters very imp! --- src/data-model/data-model.ts | 15 ++++++---- .../dataRequestsTemplate.ts | 28 +++++++++++-------- src/organization/organization.ts | 21 ++++++++------ src/pda/pda.ts | 26 +++++++++++++---- src/user/user.ts | 18 +++++++++--- src/utils/constants.ts | 1 + src/utils/errorHandler.ts | 16 ++++++++--- 7 files changed, 85 insertions(+), 40 deletions(-) diff --git a/src/data-model/data-model.ts b/src/data-model/data-model.ts index ffc9b4d..e7feb93 100644 --- a/src/data-model/data-model.ts +++ b/src/data-model/data-model.ts @@ -4,6 +4,7 @@ import { dataModels_queryQueryVariables, FilterDataModelInput, } from '../../.mesh'; +import { DEFAULT_TAKE_LIMIT } from '../utils/constants'; import { errorHandler } from '../utils/errorHandler'; import { isUUIDValid, validateObjectProperties } from '../utils/validators'; @@ -61,12 +62,14 @@ export class DataModel { * call. */ - async getDataModels({ - filter, - order, - skip, - take, - }: dataModels_queryQueryVariables = {}) { + async getDataModels( + { filter, order, skip, take }: dataModels_queryQueryVariables = { + filter: {}, + order: {}, + skip: 0, + take: DEFAULT_TAKE_LIMIT, + }, + ) { try { const data = await this.sdk.dataModels_query({ filter, diff --git a/src/dataRequestsTemplate/dataRequestsTemplate.ts b/src/dataRequestsTemplate/dataRequestsTemplate.ts index 112d850..d4e9ce0 100644 --- a/src/dataRequestsTemplate/dataRequestsTemplate.ts +++ b/src/dataRequestsTemplate/dataRequestsTemplate.ts @@ -56,17 +56,19 @@ export class DataRequestTemplate { * @returns the result of the `dataRequestTemplates_query` method call, which is a Promise * that resolves to the data request templates. */ - async getDataRequestTemplates({ - filter, - order, - skip, - take, - }: { - filter?: FilterDataRequestTemplateInput; - order?: JSON; - skip?: number; - take?: number; - } = {}) { + async getDataRequestTemplates( + { + filter, + order, + skip, + take, + }: { + filter?: FilterDataRequestTemplateInput; + order?: JSON; + skip?: number; + take?: number; + } = { filter: {}, order: {} as JSON, skip: 0, take: 10 }, + ) { try { return await this.sdk.dataRequestTemplates_query({ filter, @@ -87,7 +89,9 @@ export class DataRequestTemplate { * `FilterDataRequestTemplateInput`. * @returns the count of data request templates. */ - async getDataRequestsTemplateCount(filter?: FilterDataRequestTemplateInput) { + async getDataRequestsTemplateCount( + filter: FilterDataRequestTemplateInput = {}, + ) { try { return (await this.sdk.dataRequestTemplatesCount_query({ filter })) .dataRequestTemplatesCount; diff --git a/src/organization/organization.ts b/src/organization/organization.ts index 27c4a95..48142aa 100644 --- a/src/organization/organization.ts +++ b/src/organization/organization.ts @@ -7,6 +7,7 @@ import { UpdateOrganizationInput, } from '../../.mesh'; import { OrganizationIdentifierType } from '../types'; +import { DEFAULT_TAKE_LIMIT } from '../utils/constants'; import { errorHandler } from '../utils/errorHandler'; import { isStringValid, validateObjectProperties } from '../utils/validators'; @@ -135,15 +136,17 @@ export class Organization { * to filter the organizations based on certain criteria. * @returns the result of the `organizations_query` method call from the `sdk` object. */ - async getOrganizations({ - filter, - skip, - take, - }: { - filter?: FilterOrganizationInput; - skip?: number; - take?: number; - } = {}) { + async getOrganizations( + { + filter, + skip, + take, + }: { + filter?: FilterOrganizationInput; + skip?: number; + take?: number; + } = { filter: {}, skip: 0, take: DEFAULT_TAKE_LIMIT }, + ) { try { return await this.sdk.organizations_query({ filter, skip, take }); } catch (error) { diff --git a/src/pda/pda.ts b/src/pda/pda.ts index d2670cb..e225721 100644 --- a/src/pda/pda.ts +++ b/src/pda/pda.ts @@ -5,6 +5,7 @@ import { UpdatePDAInput, } from '../../.mesh'; import { PDAFilter, PDAStatus } from '../types'; +import { DEFAULT_TAKE_LIMIT } from '../utils/constants'; import { errorHandler } from '../utils/errorHandler'; import { isUUIDValid, validateObjectProperties } from '../utils/validators'; @@ -39,7 +40,7 @@ export class PDA { * of type `FilterPDAInput`. * @returns a Promise that resolves to a number. */ - async getPDACount(filter?: FilterPDAInput) { + async getPDACount(filter: FilterPDAInput = {}) { try { return (await this.sdk.PDACount_query({ filter })).PDACount; } catch (error) { @@ -53,10 +54,18 @@ export class PDA { * @param {PDAFilter} - - `filter`: An object that contains filter criteria for the query. * @returns a Promise that resolves to a value of type PDAs_queryQuery. */ - async getPDAs({ filter, order, skip, take }: PDAFilter = {}) { + async getPDAs( + { filter, order, skip, take }: PDAFilter = { + filter: {}, + order: {} as JSON, + skip: 0, + take: DEFAULT_TAKE_LIMIT, + }, + ) { try { return await this.sdk.PDAs_query({ filter, order, skip, take }); } catch (error) { + console.log(error); throw new Error(errorHandler(error)); } } @@ -68,7 +77,14 @@ export class PDA { * used to specify conditions that the returned PDAs must meet. * @returns a Promise that resolves to an object of type `issuedPDAs_queryQuery`. */ - async getIssuedPDAs({ filter, order, skip, take }: PDAFilter = {}) { + async getIssuedPDAs( + { filter, order, skip, take }: PDAFilter = { + filter: {}, + order: {} as JSON, + skip: 0, + take: DEFAULT_TAKE_LIMIT, + }, + ) { try { return await this.sdk.issuedPDAs_query({ filter, order, skip, take }); } catch (error) { @@ -83,7 +99,7 @@ export class PDA { * specify criteria for filtering the issued PDAs. It is of type `FilterPDAInput`. * @returns a Promise that resolves to a number. */ - async getIssuedPDAsCount(filter?: FilterPDAInput) { + async getIssuedPDAsCount(filter: FilterPDAInput = {}) { try { return (await this.sdk.issuedPDAsCount_query({ filter })).issuedPDAsCount; } catch (error) { @@ -98,7 +114,7 @@ export class PDA { * filter the results of the query. It is of type `FilterPDAInput`. * @returns a Promise that resolves to a number. */ - async myPDACount(filter?: FilterPDAInput) { + async myPDACount(filter: FilterPDAInput = {}) { try { return (await this.sdk.myPDACount_query({ filter })).myPDACount; } catch (error) { diff --git a/src/user/user.ts b/src/user/user.ts index fb5d570..4cdc6e8 100644 --- a/src/user/user.ts +++ b/src/user/user.ts @@ -6,6 +6,7 @@ import { UpdateUserInput, } from '../../.mesh'; import { PDAFilter, UserIdentifierType } from '../types'; +import { DEFAULT_TAKE_LIMIT } from '../utils/constants'; import { errorHandler } from '../utils/errorHandler'; import { isEmailValid, @@ -63,7 +64,7 @@ export class User { * of type `FilterPDAInput`. * @returns a Promise that resolves to a number. */ - async myPDACount(filter?: FilterPDAInput) { + async myPDACount(filter: FilterPDAInput = {}) { try { return (await this.sdk.myPDACount_query({ filter })).myPDACount; } catch (error) { @@ -77,7 +78,14 @@ export class User { * @param {PDAFilter} - - `filter`: An object that contains filter criteria for the query. * @returns a Promise that resolves to a value of type `myPDAs_queryQuery`. */ - async myPDAs({ filter, order, skip, take }: PDAFilter = {}) { + async myPDAs( + { filter, order, skip, take }: PDAFilter = { + filter: {}, + order: {} as JSON, + skip: 0, + take: DEFAULT_TAKE_LIMIT, + }, + ) { try { return await this.sdk.myPDAs_query({ filter, order, skip, take }); } catch (error) { @@ -94,7 +102,7 @@ export class User { * logical operators like AND and OR to combine multiple conditions. * @returns the count of data models that match the provided filter. */ - async myDataModelsCount(filter?: FilterDataModelInput) { + async myDataModelsCount(filter: FilterDataModelInput = {}) { try { return (await this.sdk.dataModelsCount_query({ filter })).dataModelsCount; } catch (error) { @@ -111,7 +119,9 @@ export class User { * specific conditions such as template name, creator, or any other relevant attributes. * @returns the count of myDataRequestTemplates that match the provided filter. */ - async myDataRequestTemplatesCount(filter?: FilterDataRequestTemplateInput) { + async myDataRequestTemplatesCount( + filter: FilterDataRequestTemplateInput = {}, + ) { try { return (await this.sdk.myDataRequestTemplatesCount_query({ filter })) .myDataRequestTemplatesCount; diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 01ab5a4..a32446f 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1,2 +1,3 @@ export const STRING_VALIDATION_LENGTH = 3; export const TEST_DEFAULT_TIMEOUT = 10000; +export const DEFAULT_TAKE_LIMIT = 15; diff --git a/src/utils/errorHandler.ts b/src/utils/errorHandler.ts index 66a43dc..880394f 100644 --- a/src/utils/errorHandler.ts +++ b/src/utils/errorHandler.ts @@ -1,7 +1,15 @@ export const errorHandler = (error: any): string => { - if (typeof error === 'object' && error !== null && 'message' in error) { - return error.message; - } else { - return 'Something went wrong!'; + if (typeof error === 'object' && error !== null) { + if ( + Array.isArray(error.errors) && + error.errors.length > 0 && + 'message' in error.errors[0] + ) { + return error.errors[0].message; + } else if ('message' in error) { + return error.message; + } } + + return 'Something went wrong!'; };