generated from algoan/nestjs-connector-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #431 from meriamBenSassi/feat/service-account-v2
[FEAT] use v2 to fetch service-accounts
- Loading branch information
Showing
19 changed files
with
323 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './paginated-data'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Paginated Algoan data | ||
*/ | ||
export interface PaginatedData<T> { | ||
resources: T[]; | ||
totalResources: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { IServiceAccount, RequestBuilder, ServiceAccount } from '@algoan/rest'; | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { Config } from 'node-config-ts'; | ||
|
||
import { CONFIG } from '../../config/config.module'; | ||
import { PaginatedData } from '../interfaces'; | ||
/** | ||
* Service to manage analysis | ||
*/ | ||
@Injectable() | ||
export class AlgoanServiceAcountService { | ||
private readonly apiVersion: string = 'v2'; | ||
// Note: here we have to instantiate a request builder instead of using the algoanhttp module | ||
// because algoanhttp's scope is REQUEST and we can't use a REQUEST scopped module in a onModuleInit | ||
// and we have to get the service account on initing the module | ||
private readonly requestBuilder = new RequestBuilder( | ||
this.config.algoan.baseUrl, | ||
{ | ||
clientId: this.config.algoan.clientId, | ||
clientSecret: this.config.algoan.clientSecret, | ||
}, | ||
{ | ||
version: this.config.algoan.version, | ||
}, | ||
); | ||
|
||
constructor(@Inject(CONFIG) private readonly config: Config) {} | ||
|
||
/** | ||
* Find all service accounts linekd to the connector | ||
*/ | ||
public async findAll(): Promise<ServiceAccount[]> { | ||
const path: string = `/${this.apiVersion}/service-accounts?limit=1000`; | ||
const paginatedServiceAccounts: PaginatedData<IServiceAccount> = await this.requestBuilder.request({ | ||
url: path, | ||
method: 'GET', | ||
}); | ||
|
||
return paginatedServiceAccounts.resources.map( | ||
(sa: IServiceAccount) => | ||
new ServiceAccount(this.config.algoan.baseUrl, sa, { | ||
apiVersion: this.config.algoan.version, | ||
}), | ||
); | ||
} | ||
|
||
/** | ||
* Find a service account by id | ||
*/ | ||
public async findById(id: string): Promise<ServiceAccount | undefined> { | ||
/* eslint-disable-next-line @typescript-eslint/naming-convention,camelcase */ | ||
const path: string = `/${this.apiVersion}/service-accounts?filter=${JSON.stringify({ _id: id })}`; | ||
const paginatedServiceAccounts: PaginatedData<IServiceAccount> = await this.requestBuilder.request({ | ||
url: path, | ||
method: 'GET', | ||
}); | ||
if (paginatedServiceAccounts.resources.length > 0) { | ||
return new ServiceAccount(this.config.algoan.baseUrl, paginatedServiceAccounts.resources?.[0], { | ||
apiVersion: this.config.algoan.version, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IsNotEmpty, IsString } from 'class-validator'; | ||
|
||
/** | ||
* ServiceAccountUpdated DTO | ||
*/ | ||
export class ServiceAccountUpdatedDTO { | ||
/** | ||
* Unique service account DTO | ||
*/ | ||
@IsNotEmpty() | ||
@IsString() | ||
public readonly serviceAccountId: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention,camelcase */ | ||
/** | ||
* Received events names | ||
*/ | ||
export enum EventName { | ||
SERVICE_ACCOUNT_CREATED = 'service_account_created', | ||
SERVICE_ACCOUNT_UPDATED = 'service_account_updated', | ||
SERVICE_ACCOUNT_DELETED = 'service_account_deleted', | ||
AGGREGATOR_LINK_REQUIRED = 'aggregator_link_required', | ||
BANK_DETAILS_REQUIRED = 'bank_details_required', | ||
} |
Oops, something went wrong.