-
Notifications
You must be signed in to change notification settings - Fork 1
[TRNF-7286] Feat(v2): Add entity onboardings and multipart uploads #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
447c8b7
c1442b3
a83c195
2c6eb58
f1c8558
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| import { Client } from '../../client'; | ||
| import { ManagerMixin } from '../../mixins'; | ||
| import { Entity } from '../../resources/v2/entity'; | ||
|
|
||
| import { OnboardingsManager } from './onboardingsManager'; | ||
|
|
||
| export class EntitiesManager extends ManagerMixin<Entity> { | ||
| static resource = 'entity'; | ||
| static methods = ['list', 'get']; | ||
| static methods = ['list', 'get', 'create']; | ||
|
|
||
| onboardings: OnboardingsManager; | ||
|
|
||
| constructor(path: string, client: Client) { | ||
| super(path, client); | ||
| this.onboardings = new OnboardingsManager('/v2/entities/{entity_id}/onboardings', client); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { ResourceArguments, UploadFile } from '../../../types'; | ||
| import { ManagerMixin } from '../../mixins'; | ||
| import { Onboarding } from '../../resources/v2/onboarding'; | ||
|
|
||
| export class OnboardingsManager extends ManagerMixin<Onboarding> { | ||
| static resource = 'onboarding'; | ||
| static methods = ['list', 'get']; | ||
|
|
||
| create(args?: ResourceArguments): Promise<Onboarding> { | ||
| const innerArgs = args || {}; | ||
| const path = this.buildPath(innerArgs); | ||
| return this._create({ path_: path, ...innerArgs }); | ||
| } | ||
|
|
||
| submit(id: string, args?: ResourceArguments): Promise<Onboarding> { | ||
| const innerArgs = args || {}; | ||
| const path = `${this.buildPath(innerArgs)}/${id}/submit`; | ||
| return this._create({ path_: path, ...innerArgs }); | ||
| } | ||
|
|
||
| uploadDocument( | ||
| id: string, | ||
| slotKey: string, | ||
| file: UploadFile, | ||
| args?: ResourceArguments, | ||
| ): Promise<Onboarding> { | ||
| const innerArgs = args || {}; | ||
| const path = `${this.buildPath(innerArgs)}/${id}/documents/${slotKey}`; | ||
| return this._upload(path, file); | ||
| } | ||
|
|
||
| uploadShareholderDocument( | ||
| id: string, | ||
| shareholderId: string, | ||
| file: UploadFile, | ||
| args?: ResourceArguments, | ||
| ): Promise<Onboarding> { | ||
| const innerArgs = args || {}; | ||
| const path = `${this.buildPath(innerArgs)}/${id}/shareholders/${shareholderId}/document`; | ||
| return this._upload(path, file); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import { GenericFunction } from '../types'; | ||
| import FormData from 'form-data'; | ||
|
|
||
| import { GenericFunction, UploadFile } from '../types'; | ||
|
|
||
| import { Client } from './client'; | ||
| import { objetize, objetizeGenerator } from './utils'; | ||
|
|
@@ -113,6 +115,41 @@ export async function resourceCreate<ResourceType>( | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Upload a file to a resource endpoint through a multipart/form-data request. | ||
| * | ||
| * @param client - The Client object passed to the retrieved object | ||
| * @param path - The path within the API server for the upload | ||
| * @param klass - Class that will wrap the instance of the resource | ||
| * @param file - The file descriptor to upload under the `file` form field | ||
| * @param handlers - The post-request handlers | ||
| * @param methods - An array of the methods that the object can execute | ||
| * @returns - An object of class `klass` | ||
| */ | ||
| export async function resourceUpload<ResourceType>( | ||
| client: Client, | ||
| path: string, | ||
| klass: any, | ||
| file: UploadFile, | ||
| handlers: Record<string, GenericFunction> = {}, | ||
| methods: string[] = [], | ||
| ): Promise<ResourceType> { | ||
| const form = new FormData(); | ||
| form.append('file', file.data, { | ||
| filename: file.filename, | ||
| contentType: file.contentType, | ||
| }); | ||
| const data = await client.request({ path, method: 'put', form }); | ||
| return objetize( | ||
| klass, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. que sea con
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seguí el patrón que estaba en las otras clases nomás jeje, según yo igual es común para evitar el clash con |
||
| client, | ||
| data, | ||
| handlers, | ||
| methods, | ||
| path, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Update a specific instance of a resource. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { ResourceMixin } from '../../mixins/resourceMixin'; | ||
|
|
||
| export class Onboarding extends ResourceMixin<Onboarding> { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { ResourceMixin } from '../../mixins/resourceMixin'; | ||
|
|
||
| export class OnboardingDocument extends ResourceMixin<OnboardingDocument> { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { ResourceMixin } from '../../mixins/resourceMixin'; | ||
|
|
||
| export class OnboardingShareholder extends ResourceMixin<OnboardingShareholder> { | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
necesitamos esta librería? creo que usar el soporte nativo de Javascript sería mejor opción
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pucha si, estamos con node-10 como min requirement del SDK