Skip to content

Commit

Permalink
Merge pull request #1 from keisyd/feat/subaccounts
Browse files Browse the repository at this point in the history
feat/subaccounts
  • Loading branch information
lncitador authored Aug 8, 2024
2 parents 9b0b0f6 + 0ae32ca commit 31d1dc3
Show file tree
Hide file tree
Showing 5 changed files with 486 additions and 18 deletions.
207 changes: 189 additions & 18 deletions packages/core/src/contract/companies/subaccounts.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,191 @@
import { initContract } from '@ts-rest/core'
import { initContract } from '@ts-rest/core';
import { z } from 'zod';
import { listMandatoryDocumentsResponseSchema, sendMandatoryDocumentsResponseSchema, sendMandatoryDocumentsCpfRequestSchema, listSubAccountsResponseSchema, listSubAccountsParamsSchema, createSubAccounResponseSchema, createSubAccountCpfBodySchema, createSubAccountCnpjBodySchema, updateSubAccountResponseSchema, updateSubAccountsBodySchema } from '../../schemas/companies/subaccounts.js';

const c = initContract()
const c = initContract();

export const subaccounts = c.router(
{
// Todo: Listar Subcontas
// Todo: Obter Documentos Necessários
// Todo: Criar Subconta CPF
// Todo: Criar Subconta CNPJ
// Todo: Enviar Documentos Necessários CPF
// Todo: Enviar Documentos Necessários CNPJ
// Todo: Editar Subconta
// Todo: Reativar Subconta
// Todo: Desativar Subconta
},
{
pathPrefix: '/subaccounts',
},
)
/**
* Defines the subaccounts router object.
*
* @example
* ```ts
* import { initClient } from '@ts-rest/core'
* import { subaccounts } from '@cel_cash/core/contract'
*
* const client = initClient(subaccounts, {
* baseUrl: 'https://api.celcoin.com.br'
* })
*
* const subaccountsList = await client.list({ ... })
* const createdSubaccount = await client.createWithCnpj({ ... })
* const updatedSubaccount = await client.update({ ... })
* const deletedSubaccount = await client.delete({ ... })
* ```
*/
export const subaccounts = c.router({
/**
* Retrieves a list of mandatory documents.
* Require access_token to have company.read scope.
*
* @method GET
* @path /company/mandatory-documents
* @responses 200 - The list of mandatory documents.
*/
listMandatoryDocuments: {
method: 'GET',
path: '/mandatory-documents',
responses: {
200: listMandatoryDocumentsResponseSchema,
},
},
/**
* Sends mandatory documents with CPF.
* Require access_token to have company.write scope.
*
* @method POST
* @path /company/mandatory-documents
* @responses 200 - If succeeded or not.
* @body - The request body for sending mandatory documents.
*/
sendMandatoryDocumentsCpf: {
method: 'POST',
path: '/mandatory-documents',
responses: {
200: sendMandatoryDocumentsResponseSchema,
},
body: sendMandatoryDocumentsCpfRequestSchema,
},
/**
* Creates a new mandatory documents with CNPJ.
* Require access_token to have company.write scope.
*
* @method POST
* @path /company/mandatory-documents
* @responses 200 - If succeeded or not.
* @body - The request body for sending mandatory documents.
*/
sendMandatoryDocumentsCnpj: {
method: 'POST',
path: '/mandatory-documents',
responses: {
200: sendMandatoryDocumentsResponseSchema,
},
body: sendMandatoryDocumentsCpfRequestSchema,
},
/**
* Retrieves a list of subAccounts.
* Require access_token to have company.read scope.
*
* @method GET
* @path /company/subaccount
* @responses 200 - The list of subAccounts.
* @query - The query parameters for listing subAccounts.
*/
list: {
method: 'GET',
path: '/subaccounts',
responses: {
200: listSubAccountsResponseSchema,
},
query: listSubAccountsParamsSchema,
},
/**
* Creates a new subAccount with CPF.
* Require access_token to have company.write scope.
*
* @method POST
* @path /company/subaccount
* @responses 200 - The created company subAccount.
* @body - The request body for creating a subAccount.
*/
createWithCpf: {
method: 'POST',
path: '/subaccount',
responses: {
200: createSubAccounResponseSchema,
},
body: createSubAccountCpfBodySchema,
},
/**
* Creates a new subAccount with CNPJ.
* Require access_token to have company.write scope.
*
* @method POST
* @path /company/subaccount
* @responses 200 - The created company subAccount.
* @body - The request body for creating a subAccount.
*/
createWithCnpj: {
method: 'POST',
path: '/subaccount',
responses: {
200: createSubAccounResponseSchema,
},
body: createSubAccountCnpjBodySchema,
},
/**
* Updates a subAccount.
* Require access_token to have company.write scope.
*
* @method PUT
* @path /company/subaccount/:subAccountId/:typeId
* @pathParams - The path parameters for updating a subAccount.
* @responses 200 - The updated subAccount.
* @body - The request body for updating a subAccount.
*/
update: {
method: 'PUT',
path: '/subaccount/:subAccountId',
pathParams: z.object({
subAccountId: z.union([z.coerce.number().positive(), z.coerce.string()]),
}),
responses: {
200: updateSubAccountResponseSchema,
},
body: updateSubAccountsBodySchema,
},
/**
* Reactivate a subAccount.
* Require access_token to have company.write scope.
*
* @method PUT
* @path /company/subaccount/active/:subAccountId
* @pathParams - The path parameters for updating a subAccount.
* @responses 200 - The updated subAccount.
* @body - The request body for updating a subAccount.
*/
active: {
method: 'PUT',
path: '/subaccount/active/:subAccountId',
pathParams: z.object({
subAccountId: z.union([z.coerce.number().positive(), z.coerce.string()]),
}),
responses: {
200: updateSubAccountResponseSchema,
},
body: updateSubAccountsBodySchema,
},
/**
* Deletes a subAccount.
* Require access_token to have company.write scope.
*
* @method DELETE
* @path /company/subaccount/:subAccountId/:typeId
* @pathParams - The path parameters for deleting a subAccount.
* @responses 200 - The deletion status.
* @body - An empty object.
*/
delete: {
method: 'DELETE',
path: '/subaccount/:subAccountId',
pathParams: z.object({
subAccountId: z.union([z.coerce.number().positive(), z.coerce.string()]),
}),
responses: {
200: z.object({
type: z.boolean(),
}),
},
body: c.noBody(),
},
});
4 changes: 4 additions & 0 deletions packages/core/src/contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { plans } from './plans.js'
import { subscriptions } from './subscriptions.js'
import { transactions } from './transactions.js'
import { pix, transfer } from './transfer.js'
import { subaccounts } from './companies/subaccounts.js'

export type Antecipation = Client<typeof antecipation>
export type Auth = Client<typeof auth>
Expand All @@ -23,6 +24,7 @@ export type Subscriptions = Client<typeof subscriptions>
export type Transactions = Client<typeof transactions>
export type Pix = Client<typeof pix>
export type Transfer = Client<typeof transfer>
export type Subaccounts = Client<typeof subaccounts>

export type Contract = {
antecipation: Antecipation
Expand All @@ -36,6 +38,7 @@ export type Contract = {
transactions: Transactions
pix: Pix
transfer: Transfer
subaccounts: Subaccounts
}

export {
Expand All @@ -51,4 +54,5 @@ export {
transactions,
pix,
transfer,
subaccounts
}
32 changes: 32 additions & 0 deletions packages/core/src/schemas/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,38 @@ export const addressSchema = z.object({
state: z.string(),
})

export const professionalSchema = z.object({
internalName: z.enum([
'lawyer',
'doctor',
'accountant',
'realtor',
'broker',
'physicalEducator',
'physiotherapist',
'others',
]),
street: z.string(),
number: z.string(),
complement: z.string().optional(),
neighborhood: z.string(),
city: z.string(),
state: z.string(),
});

export const apiAuthSchema = z.object({
galaxId: z.string(),
galaxHash: z.string(),
publicToken: z.string(),
confirmHashWebhook: z.string(),
});

export const verificationSchema = z.object({
status: z.string(),
Reasons: z.array(z.string()),
});


export const extraFieldSchema = z.object({
tagName: z.string(),
value: z.string(),
Expand Down
68 changes: 68 additions & 0 deletions packages/core/src/schemas/companies/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { z } from 'zod';
import { addressSchema } from '../common.js';

export const professionalSchema = z.object({
internalName: z.enum([
'lawyer',
'doctor',
'accountant',
'realtor',
'broker',
'physicalEducator',
'physiotherapist',
'others',
]),
street: z.string(),
number: z.string(),
complement: z.string().optional(),
neighborhood: z.string(),
city: z.string(),
state: z.string(),
});

export const apiAuthSchema = z.object({
galaxId: z.string(),
galaxHash: z.string(),
publicToken: z.string(),
confirmHashWebhook: z.string(),
});

export const verificationSchema = z.object({
status: z.string(),
Reasons: z.array(z.string()),
});

export const configBaseSchema = z.object({
confirmHashWebhook: z.string(),
taxWithdraw: z.number(),
taxPixDone: z.number(),
taxPixBoleto: z.number(),
taxPixReceived: z.number(),
taxPixTransaction: z.number(),
});

export const userBaseSchema = z.object({
galaxPayId: z.number(),
master: z.boolean(),
email: z.string(),
name: z.string(),
document: z.string(),
phone: z.string(),
});

export const companyBaseSchema = z.object({
galaxPayId: z.number(),
name: z.string(),
document: z.string(),
nameDisplay: z.string(),
active: z.boolean(),
emailContact: z.string(),
urlLogo: z.string(),
createdAt: z.string(),
canAccessPlatform: z.boolean(),
updatedAt: z.string(),
Address: addressSchema,
Professional: professionalSchema,
ApiAuth: apiAuthSchema,
Verification: verificationSchema,
});
Loading

0 comments on commit 31d1dc3

Please sign in to comment.