# API reference

# GrahpQL

The backend of the platform is built using GraphQL. The list of queries and mutations can be found respectively:

  • ./backend/graphql/typeDefs/types/Query.graphql
  • ./backend/graphql/typeDefs/types/Mutation.graphql

It is also possible to explore the API using the GraphQL playground when the environment variable NODE_ENV is set to development. Simply visit http://localhost:$PORT/graphql.

# Crons

# CronDeleteUsers every month at 00:00

  • Selects users where disabled is true and deleteAt is passed.
  • Deletes them.
  • If user is borrower, will also delete his projects.
  • If user is organization owner, will also delete the organization members.
  • If user is organization member, will be removed from organization members.

# CronEarlyReimbursement every hour

  • Selects reimbursement plans where isEarlyReimbursement is true and paid is false.
  • If the wallet balance of the project owner is less than total amount to reimburse, then notifies admin every day.
  • Else transfers money from the project wallet to lender wallet, updates refund to true and notifies admin, lender and borrower.
  • Lenders will receive amortization + interest for the current(the year when admin executes early reimbursement) term and only amortization for upcoming terms.
  • Lenders will receive half of the interest for the current term if early reimbursement is executed before six months from reimbursement terms execution date.

# CronHandleDelayedReimbursements every day at 12:00

  • Selects reimbursements where paid is false and executionAt is passed.
  • Sets the property delayed to true.

# CronHandleNotSuccessfulProjects every hour

  • Selects projects where status is PUBLIC_SALE and collected < target and endSaleAt is passed.
  • Updates the status to NOT_SUCCESSFUL.
  • Notifies project owners and investors by email.

# CronHandleSuccessfulProjects every hour

  • Selects projects where status is PUBLIC_SALE and collected >= target or maximum and enSaleAt is passed.
  • Updates the status to SUCCESSFUL.
  • Populates reimbursement, reimbursement plan and reimbursement terms for each project based on defined respite period by admin.
  • Notifies project owners and investors by email.
  • Downloads, zip and uploads to s3 all investment contracts.

# CronHandleWalletStatusChange every minute MANGOPAY

  • Selects users / organizations where profileStatus is WALLET_CREATED or REJECTED_PSP.
  • If Mangopay user's kYCLevel is REGULAR, updates profileStatus to APPROVED, adds kycStatus and sends an email to the user.
  • Else if there are rejected documents, updates profileStatus to REJECTED_PSP.

# CronMoveProjectsToPublicSale every 5 hours

  • Selects projects where status is PRIVATE_SALE and startSaleAt is passed.
  • Updates the status to PUBLIC_SALE.
  • Notifies all lenders of a new project available by email.

# CronProfileNotCompleted every day at 12:00

  • Selects users where type is LENDER and profileStatus is NOT_SUBMITTED.
  • Notifies the user that the profile is still not submitted after 1 and 10 days by email.

# CronRefundProjectsNotSuccessful every hour

  • Selects investments where refund is false and status is COMPLETED (when a project becomes NOT_SUCCESSFUL, the refund property is added to each related investment marking them as investments to refund).
  • Transfers money from the project wallet to each lenders wallet.
  • Sets refund to true.

# CronReimbursement every hour

  • Selects reimbursement terms where paid is false and executionAt is passed.
  • If the wallet balance of the project owner is less than total amount to reimburse, then notifies admin every day.
  • Else transfers money from the project wallet to lender wallet, updates refund to true and notifies admin, lender and borrower.

# CronReimbursementPayTax every hour

  • Selects reimbursements where paid is true and taxPaid is false.
  • Calculates socialTax and incomeTax.
  • Transfers both taxes to the tax wallet.
  • Sets taxPaid to true.

# CronResetTaxExempt every 1st of april at 00:00

  • Selects every users where type is LENDER.
  • Sets taxExempt to false.

# CronSendEmailIncomeTaxExemption every 1st of november at 00:00

  • Selects every users where type is LENDER and hasOrganization is false.
  • Notifies lenders about tax exemption.

# CronSendEmailNotEnoughBalanceToCompleteReimbursement every day at 12:00

  • Sends an email to borrower and admin 15, 7 and 2 days before the reimbursement if the amount in the wallet is not enough.

# CronSendEmailProjectNewsNotPublished every day at 12:00

  • Selects projects where status is SUCCESSFUL.
  • Sends the borrower and admin a reminder email that project news have no been published for a long time every 5 days until a news is published.

NOTE: long time means 90 days after the last publication (or the end of the sale period if no news yet).

# CronSendEmailProjectPublishNews every day at 12:00

  • Selects projects where status is SUCCESSFUL.
  • Sends the borrower a reminder email to publish a news in his project 60 days after endSaleAt, then every 3 months until the project gets fully reimbursed.

# CronSendEmailToAdminsIfKycStatusNotUpdated every day at 12:00

  • Selects users where type is LENDER and profileStatus is not APPROVED.
  • If profileApprovedAt was 2 days ago, sends an email to admin as there might be an issue with the payment service provider.

# CronSendEmailToLenderApprovedButNotInvested every day at 12:00

  • Selects users where type is LENDER and their investments.
  • If user has profileApprovedAt and is 14 days or 84 days (3 months) ago, send an reminder email to the user.

# CronSendEmailToLenderIfRiskAssessmentNotSigned every day at 12:00

  • Selects users where type is LENDER and riskAssessment.isSigned is false.
  • Sends a reminder to the lender if he did not sign the risk assessment after 3 days we sent it.

# CronStatistics every day at 12:00

  • Calculates statistics for current year and updates the statistics table.

# CronUpdateKYCStatuses every hour LEMONWAY

  • Updates profileStatus and kycStatus with values from Lemonway.

# CronUploadDocument every five minutes

  • Selects users where type is LENDER and profileStatus is WALLET_CREATED.
  • Selects files uploaded by users (proofs) where uploadId is null.
  • Uploads the files to the payment service provider and update the uploadId.

# CronUploadUBODeclaration every minute MANGOPAY

  • Selects organizations where profileStatus is not NOT_SUBMITTED or REJECTED and uboStatus is not VALIDATED or SUBMITTED.
  • If organization.uboStatus is REFUSED or null, creates a new ubo declaration upload documents and submit ubo declaration.
  • If organization.uboStatus is INCOMPLETE update submitted ubo document and details.
  • Else create new ubo declaration upload documents and submit ubo declaration.

# Webhooks

# document MANGOPAY

  • triggerd on: Kyc Succeeded or Kyc Failed
  • If Mangopay user's kYCLevel is REGULAR, updates profileStatus to APPROVED, adds kycStatus and sends an email to the user.
  • Else if there are rejected documents, updates profileStatus to REJECTED_PSP.

# payment MANGOPAY

  • triggered on: Payin Succeeded or Payin Failed
  • If PAYIN_NORMAL_SUCCEEDED,send an email to the user and update walletCreditedAt
  • Increment logsCount on paynin succeeded or failed

# ubo MANGOPAY

  • triggerd on: Ubo Declaration Refused or Ubo Declaration Validated
  • If UBO_DECLARATION_VALIDATED, update uboStatus to VALIDATED
  • Else if refused, updates profileStatus to REJECTED_PSP and kycStatus to ACCOUNT_NOT_OPENED