Skip to content

Commit

Permalink
feat: added remaining queries/mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth9890 committed Jan 11, 2024
1 parent d3e9647 commit b0b5e7c
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 46 deletions.
19 changes: 18 additions & 1 deletion __mocks__/dataRequestTemplate.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,26 @@ export const DataRequestTemplateMockService = (
getDataRequestTemplatesMock: jest
.spyOn(dataRequestTemplate.sdk, 'dataRequestTemplates_query')
.mockResolvedValue({ dataRequestTemplates: [dataRequestTemplateStub()] }),
getDataRequestsTemplateCount: jest
getDataRequestsTemplateCountMock: jest
.spyOn(dataRequestTemplate.sdk, 'dataRequestTemplatesCount_query')
.mockResolvedValue({
dataRequestTemplatesCount: 10,
}),
getDataRequestsTemplatesMetadataMock: jest
.spyOn(dataRequestTemplate.sdk, 'dataRequestTemplatesMetadata_query')
.mockResolvedValue({
dataRequestTemplatesMetadata: {
tags: [dataRequestTemplateStub().tags[0]],
},
}),
getVerifiersByDataRequestTemplateMock: jest
.spyOn(dataRequestTemplate.sdk, 'verifiersByDataRequestTemplate_query')
.mockResolvedValue({
verifiersByDataRequestTemplate: [],
}),
getVerifiersByDataRequestTemplateCountMock: jest
.spyOn(dataRequestTemplate.sdk, 'verifiersByDataRequestTemplateCount_query')
.mockResolvedValue({
verifiersByDataRequestTemplateCount: 10,
}),
});
17 changes: 14 additions & 3 deletions __mocks__/user.mock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Organization } from '../src/organization/organization';
import { User } from '../src/user/user';
import { organizationStub } from '../test/stubs/organization.stub';
import { userStub } from '../test/stubs/user.stub';
import { userStub, walletStub } from '../test/stubs/user.stub';

export const UserMockService = (user: User) => ({
meMock: jest.spyOn(user.sdk, 'me_query').mockResolvedValue({
Expand Down Expand Up @@ -39,4 +37,17 @@ export const UserMockService = (user: User) => ({
'https://www.tryodyssey.xyz/images/campaigns/lifi/odyssey_lifi.png',
}).profilePicture,
}),
myFinancialTransactionsCountMock: jest
.spyOn(user.sdk, 'myFinancialTransactionsCount_query')
.mockResolvedValue({
myFinancialTransactionsCount: 10,
}),
mywalletMock: jest.spyOn(user.sdk, 'myWallet_query').mockResolvedValue({
myWallet: walletStub(),
}),
// myFinancialTransactionsMock: jest
// .spyOn(user.sdk, 'myFinancialTransactions_query')
// .mockResolvedValue({
// myFinancialTransactions: userStub().
// }),
});
2 changes: 2 additions & 0 deletions src/Gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ export class Gateway {
this.user = new User(this.sdk);
}
}
// calculateProofCost
// findValidPDAsForRequest
2 changes: 0 additions & 2 deletions src/data-model/data-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
import { errorHandler } from '../utils/errorHandler';
import { isUUIDValid, validateObjectProperties } from '../utils/validators';

/* The `DataModel` class is a TypeScript class that provides methods for creating and retrieving data
models. */

export class DataModel {
public sdk: Sdk;
Expand Down
50 changes: 47 additions & 3 deletions src/dataRequestsTemplate/dataRequestsTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class DataRequestTemplate {
async createDataRequestTemplate(templateInput: TemplateSchemaInput) {
try {
validateObjectProperties(templateInput);
return this.sdk.createDataRequestTemplate_mutation({
return await this.sdk.createDataRequestTemplate_mutation({
input: templateInput,
});
} catch (error) {
Expand All @@ -43,7 +43,7 @@ export class DataRequestTemplate {
async getDataRequestTemplate(id: string) {
try {
isUUIDValid(id);
return this.sdk.dataRequestTemplate_query({ id });
return await this.sdk.dataRequestTemplate_query({ id });
} catch (error) {
throw new Error(errorHandler(error));
}
Expand All @@ -61,7 +61,7 @@ export class DataRequestTemplate {
variables?: dataRequestTemplates_queryQueryVariables,
) {
try {
return this.sdk.dataRequestTemplates_query(variables);
return await this.sdk.dataRequestTemplates_query(variables);
} catch (error) {
throw new Error(errorHandler(error));
}
Expand All @@ -83,4 +83,48 @@ export class DataRequestTemplate {
throw new Error(errorHandler(error));
}
}

/**
* The function `getDataRequestsTemplatesMetadata` gets metadat of template
* to the SDK and returns the result, or throws an error if something goes wrong.
* @returns the result of the `dataRequestTemplatesMetadata_queryQuery` method call.
*/
async getDataRequestsTemplatesMetadata() {
try {
return await this.sdk.dataRequestTemplatesMetadata_query();
} catch (error) {
throw new Error(errorHandler(error));
}
}

/**
* The function `getVerifiersByDataRequestTemplate` gets verifier for a data request template
* to the SDK and returns the result, or throws an error if something goes wrong.
* @param {string} id - The variables is a id of the template
* @returns the result of the `verifiersByDataRequestTemplate_queryQuery` method call.
*/
async getVerifiersByDataRequestTemplate(id: string) {
try {
isUUIDValid(id);
return await this.sdk.verifiersByDataRequestTemplate_query({ id });
} catch (error) {
throw new Error(errorHandler(error));
}
}

/**
* The function `getVerifiersByDataRequestTemplateCount` gets count of recently made transactions
* to the SDK and returns the result, or throws an error if something goes wrong.
* @param {string} id - The variables is a id of the template
* @returns the result of the `verifiersByDataRequestTemplateCount_queryQuery` method call.
*/
async getVerifiersByDataRequestTemplateCount(id: string) {
try {
isUUIDValid(id);
return (await this.sdk.verifiersByDataRequestTemplateCount_query({ id }))
.verifiersByDataRequestTemplateCount;
} catch (error) {
throw new Error(errorHandler(error));
}
}
}
10 changes: 5 additions & 5 deletions src/organization/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Organization {
async createOrganization(organizationInput: CreateOrganizationInput) {
try {
validateObjectProperties(organizationInput);
return this.sdk.createOrganization_mutation({
return await this.sdk.createOrganization_mutation({
input: organizationInput,
});
} catch (error) {
Expand All @@ -48,7 +48,7 @@ export class Organization {
*/
async addMemberToOrganization(memberInput: MemberInput) {
try {
return this.sdk.addMemberToOrganization_mutation({
return await this.sdk.addMemberToOrganization_mutation({
input: memberInput,
});
} catch (error) {
Expand All @@ -66,7 +66,7 @@ export class Organization {
*/
async changeMemberRole(memberInput: MemberInput) {
try {
return this.sdk.changeMemberRole_mutation({ input: memberInput });
return await this.sdk.changeMemberRole_mutation({ input: memberInput });
} catch (error) {
throw new Error(errorHandler(error));
}
Expand Down Expand Up @@ -101,7 +101,7 @@ export class Organization {
async updateOrganization(updatedOrganization: UpdateOrganizationInput) {
try {
validateObjectProperties(updatedOrganization);
return this.sdk.updateOrganization_mutation({
return await this.sdk.updateOrganization_mutation({
input: updatedOrganization,
});
} catch (error) {
Expand All @@ -123,7 +123,7 @@ export class Organization {
async getOrganization(type: OrganizationIdentifierType, value: string) {
try {
isStringValid(value);
return this.sdk.organization_query({ input: { type, value } });
return await this.sdk.organization_query({ input: { type, value } });
} catch (error) {
throw new Error(errorHandler(error));
}
Expand Down
21 changes: 3 additions & 18 deletions src/pda/pda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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) {
Expand All @@ -52,7 +52,7 @@ export class PDA {
/**
* The function `getPDAs` retrieves PDAs based on the provided filter, order, skip, and take
* parameters.
* @param {PDAFilter} - - `filter`: An object that contains filter criteria for the query.
* @param {PDAs_queryQueryVariables} - - `filter`: An object that contains filter criteria for the query.
* @returns a Promise that resolves to a value of type PDAs_queryQuery.
*/
async getPDAs(variables?: PDAs_queryQueryVariables) {
Expand All @@ -66,7 +66,7 @@ export class PDA {
/**
* The function `getIssuedPDAs` retrieves issued PDAs based on the provided filter, order, skip, and
* take parameters.
* @param {PDAFilter} - - `filter`: An object that contains filter criteria for the query. It is
* @param {issuedPDAs_queryQueryVariables} - - `filter`: An object that contains filter criteria for the query. It is
* used to specify conditions that the returned PDAs must meet.
* @returns a Promise that resolves to an object of type `issuedPDAs_queryQuery`.
*/
Expand All @@ -93,21 +93,6 @@ export class PDA {
}
}

/**
* The function `myPDACount` is an asynchronous function that returns the count of myPDAs based on an
* optional filter.
* @param {FilterPDAInput} [filter] - The `filter` parameter is an optional input that can be used to
* filter the results of the query. It is of type `FilterPDAInput`.
* @returns a Promise that resolves to a number.
*/
async myPDACount(filter?: FilterPDAInput) {
try {
return (await this.sdk.myPDACount_query({ filter })).myPDACount;
} catch (error) {
throw new Error(errorHandler(error));
}
}

/**
* The function `changePDAStatus` is an asynchronous function that takes an `id` and a `status` as
* parameters and returns a Promise that resolves to a `changePDAStatus_mutationMutation` object.
Expand Down
8 changes: 0 additions & 8 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FilterPDAInput } from '../.mesh';

export enum UserIdentifierType {
EMAIL = 'EMAIL',
Expand All @@ -15,13 +14,6 @@ export enum PDAStatus {
'Valid' = 'Valid',
}

export type PDAFilter = {
filter?: FilterPDAInput;
order?: JSON;
skip?: number;
take?: number;
};

export enum OrganizationIdentifierType {
GATEWAY_ID = 'GATEWAY_ID',
ORG_ID = 'ORG_ID',
Expand Down
72 changes: 70 additions & 2 deletions src/user/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import {
FilterPDAInput,
Sdk,
UpdateUserInput,
myFinancialTransactionsCount_queryQueryVariables,
myFinancialTransactions_queryQueryVariables,
myPDAs_queryQueryVariables,
myTransactions_queryQueryVariables,
} from '../../.mesh';
import { UserIdentifierType } from '../types';
import { errorHandler } from '../utils/errorHandler';
import {
isEmailValid,
isStringValid,
isUUIDValid,
validateObjectProperties,
} from '../utils/validators';

Expand Down Expand Up @@ -73,9 +77,9 @@ export class User {
}

/**
* The function `myPDAs` is an asynchronous function that takes in a `PDAFilter` object and returns a
* The function `myPDAs` is an asynchronous function that takes in a `myPDAs_queryQueryVariables` object and returns a
* promise that resolves to a `myPDAs_queryQuery` object.
* @param {PDAFilter} - - `filter`: An object that contains filter criteria for the query.
* @param {myPDAs_queryQueryVariables} - - `filter`: An object that contains filter criteria for the query.
* @returns a Promise that resolves to a value of type `myPDAs_queryQuery`.
*/
async myPDAs(variables?: myPDAs_queryQueryVariables) {
Expand Down Expand Up @@ -121,6 +125,70 @@ export class User {
}
}

/**
* The function `myFinancialTransactions` gets recently made financial transactions
* to the SDK and returns the result, or throws an error if something goes wrong.
* @param {myFinancialTransactionsCount_queryQueryVariables} variables - The variables is a complex filter type
* @returns the result of the `myFinancialTransactions_queryQuery` method call.
*/
async myFinancialTransactions(
variables?: myFinancialTransactions_queryQueryVariables,
) {
try {
if (variables?.organizationId) isUUIDValid(variables.organizationId);
return await this.sdk.myFinancialTransactions_query(variables);
} catch (error) {
throw new Error(errorHandler(error));
}
}

/**
* The function `myFinancialTransactionsCount` gets count of recently made transactions
* to the SDK and returns the result, or throws an error if something goes wrong.
* @param {myFinancialTransactionsCount_queryQueryVariables} variables - The variables is a complex filter type
* @returns the result of the `myFinancialTransactionsCount_queryQuery` method call.
*/
async myFinancialTransactionsCount(
variables?: myFinancialTransactionsCount_queryQueryVariables,
) {
try {
if (variables?.organizationId) isUUIDValid(variables.organizationId);
return (await this.sdk.myFinancialTransactionsCount_query(variables))
.myFinancialTransactionsCount;
} catch (error) {
throw new Error(errorHandler(error));
}
}

/**
* The function `myTransactions_query` gets recently made transactions
* to the SDK and returns the result, or throws an error if something goes wrong.
* @param {myTransactions_queryQueryVariables} variables - The variables is a complex filter type
* @returns the result of the `myTransactions_queryQuery` method call.
*/
async myTransactions(variables?: myTransactions_queryQueryVariables) {
try {
return await this.sdk.myTransactions_query(variables);
} catch (error) {
throw new Error(errorHandler(error));
}
}

/**
* The function `myWallet` gets wallet summary by making a query request
* to the SDK and returns the result, or throws an error if something goes wrong.
* @param {string} organizationId - The organizationId parameter is a string that represents the org id
* @returns the result of the `myWallet_queryQuery` method call.
*/
async myWallet(organizationId?: string) {
try {
if (organizationId) isUUIDValid(organizationId);
return await this.sdk.myWallet_query({ organizationId });
} catch (error) {
throw new Error(errorHandler(error));
}
}

/**
* The function `updateUser` updates a user's information and returns the updated user.
* @param {UpdateUserInput} updatedUser - The `updatedUser` parameter is an object of type
Expand Down
Loading

0 comments on commit b0b5e7c

Please sign in to comment.