Skip to content
Ignacio Larrañaga edited this page Dec 24, 2022 · 17 revisions

Contracts Example - Sample Use Case

This use case gets over the flow using the different GraphQL queries implemented. Briefly, we will:

  1. Create Sample Profiles (used to design the scenarios)
  2. Create Jobs (using 2 sample client profiles)
  3. Create Contracts (using the previously created jobs and some of the contractor profiles)
  4. Make Deposits (to pay for the jobs in the contracts)
  5. Pay Jobs
  6. Check Jobs and Contracts
  7. Get the Best Profession
  8. Get the Best Clients

1. Create Sample Profiles

Let's start by creating a few users using the GraphQL API:

mutation CreateSampleProfiles {
  client1: createProfile(input: {firstName: "John", lastName: "Doe", profession: "Business Manager", type: CLIENT, id: "john", password: "-TestUser1"}) {
    id, firstName,  lastName, profession, type, balance, amountDue
  }

  client2: createProfile(input: {firstName: "Joe", lastName: "Doe", profession: "Operations Manager", type: CLIENT, id: "joe", password: "-TestUser1"}) {
    id, firstName,  lastName, profession, type, balance, amountDue
  }

  contractor1: createProfile(input: {firstName: "Jane", lastName: "Doe", profession: "Software Engineer", type: CONTRACTOR, id: "jane", password: "-TestUser1"}) {
    id, firstName,  lastName, profession, type, balance, amountDue
  }

  contractor2: createProfile(input: {firstName: "Jess", lastName: "Doe", profession: "Tester", type: CONTRACTOR, id: "jess", password: "-TestUser1"}) {
    id, firstName,  lastName, profession, type, balance, amountDue
  }

  contractor3: createProfile(input: {firstName: "Jennifer", lastName: "Doe", profession: "Project Manager", type: CONTRACTOR, id: "jennifer", password: "-TestUser1"}) {
    id, firstName,  lastName, profession, type, balance, amountDue
  }
}
Sample Profiles Creation

You can also get those profiles with a query like this:

query GetProfile {
  getProfile(id: "john") {
    id, firstName, lastName, profession, type, balance, amountDue, maxDeposit, createdBy, createdAt, lastModifiedBy, lastModifiedAt
  }
}

2. Create Jobs

Let's first login as John and create some jobs from him:

Login as John
mutation CreateSampleJobsForJohn {
  job1: createJob(input: {description: "Develop the PoC", price: 8000}) {
    id, description, clientId, contractorId, contractId, price, paid, paymentDate, createdBy, createdAt, lastModifiedBy, lastModifiedAt
  }

  job2: createJob(input: {description: "Add Integration Tests", price: 2000}) {
    id, description, clientId, contractorId, contractId, price, paid, paymentDate, createdBy, createdAt, lastModifiedBy, lastModifiedAt
  }
}
John Jobs

Later same as Joe:

mutation CreateSampleJobsForJoe {
  job3: createJob(input: {description: "Manage the Project", price: 5000}) {
    id, description, clientId, contractorId, contractId, price, paid, paymentDate, createdBy, createdAt, lastModifiedBy, lastModifiedAt
  }
}

You can also get a list of the unpaid jobs with a query like this one:

query ListUnpaidJobs {
  listJobs(filter: {paid: false}) {
    items {
      id, description, clientId, price, paid, paymentDate, createdBy, createdAt, lastModifiedBy, lastModifiedAt
    }
  }
}

3. Create Contracts

Now we are ready to create some contracts between the clients and contractors. Let's start with John:

mutation CreateAContract {
  createContract(input: {contractorId: "jane", jobIds: ["d5dc8b86-6cef-4ff5-84f6-5e7cb7f1db2d", "1e62cc68-ffa0-4492-b433-2fa8d2903d11"], terms: "None"}) {
    id, clientId, contractorId, jobIds, terms, status, createdBy, createdAt, lastModifiedBy, lastModifiedAt
  }
}
John Contracts

And later create another for Joe:

mutation CreateAContract {
  createContract(input: {contractorId: "jennifer", jobIds: ["f4eb77fe-9864-47dd-b941-d591fb5a4e12"], terms: "None"}) {
    id, clientId, contractorId, jobIds, terms, status, createdBy, createdAt, lastModifiedBy, lastModifiedAt
  }
}

You can also list or directly get the contracts for either of the users with the following queries:

query ListContracts {
  listContracts(filter: { unterminated: true }) {
    items {
      id, clientId, contractorId, terms, status, jobIds, createdAt, createdBy, lastModifiedAt, lastModifiedBy
    }
  }
}
query GetAContract {
  getContract(id: "20608d63-74b5-430f-92b3-3e695b0079f9") {
  	id, clientId, contractorId, terms, status, jobIds, createdAt, createdBy, lastModifiedAt, lastModifiedBy
  }
}

4. Make Deposits

We will make several deposits on both client profiles to have enough balance to pay for the jobs in the following step. Let's start with John:

mutation MakeADeposit {
  makeProfileDeposit(input: {amount: 2500}) {
    id, firstName, lastName, profession, type, balance
  }
}
John Deposit

Let's go up to 10k so we have enough money to pay all its jobs. Let's do the same for Joe (i.e. execute the query logged as Joe) up to 5k because of the same.

5. Pay Jobs

We will now pay for all the jobs in all the contracts of all the clients with queries like the following:

mutation PayJob {
  payJob(id: "1e62cc68-ffa0-4492-b433-2fa8d2903d11") {
    id, description, clientId, contractorId, price, paid, paymentDate, createdBy, createdAt. lastModifiedBy, lastModifiedAt
  }
}
John  Payment

6. Check Jobs and Contracts

We can now check the status of the contracts with queries like the following:

query GetAContract {
  getContract(id: "20608d63-74b5-430f-92b3-3e695b0079f9") {
    id, clientId, contractorId, jobIds, status, terms, createdBy, createdAt, lastModifiedAt, lastModifiedBy
  }
}
John Contract Status

And the jobs with:

query ListPaidJobs {
  listJobs(filter: {paid: true}) {
    items {
      id, description, clientId, price, paid, paymentDate, createdBy, createdAt, lastModifiedBy, lastModifiedAt
    }
  }
}
John Jobs Status

7. Get the Best Profession

Now that all the jobs are paid we can check the best profession with a query like this:

query GetBestProfession {
  bestProfession
}
Best Profession

8. Get the Best Clients

Also we can check the best clients with a query like the following:

query GetBestClients {
  bestClients {
    items {
      id, fullName, paid
    }
  }
}
Best Clients