Skip to content

Commit

Permalink
Merge pull request #86 from ainize-team/feature/yoojin/custom_request…
Browse files Browse the repository at this point in the history
…_key

Get req key from optional param
  • Loading branch information
yoojinko authored Dec 21, 2023
2 parents af1db3a + dfc8be0 commit edcd0d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/controllers/serviceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ export default class ServiceController {
return await this.ain.getValue(creditHistoryPath) as creditHistories;
}

async request(serviceName: string, requestData: any) : Promise<any> {
async request(serviceName: string, requestData: any, requestKey?: string) : Promise<any> {
this.checkRunning(serviceName);
const result = await new Promise(async (resolve, reject) => {
const requestKey = Date.now();
requestKey = requestKey || Date.now().toString();
const requesterAddress = this.ain.getAddress();
const responsePath = Path.app(serviceName).response(requesterAddress, requestKey.toString());
const responsePath = Path.app(serviceName).response(requesterAddress, requestKey);
await this.handler.subscribe(responsePath, resolve);
const requestPath = Path.app(serviceName).request(requesterAddress, requestKey);
const requestOp = buildSetOperation("SET_VALUE", requestPath, requestData);
Expand Down
4 changes: 2 additions & 2 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export default class Service {
* @param {string} requestData String data for request to service.
* @returns {string} Response data from service.
*/
async request(requestData: any) {
async request(requestData: any, requestKey?: string) {
this.isLoggedIn();
return await this.serviceController.request(this.serviceName, requestData);
return await this.serviceController.request(this.serviceName, requestData, requestKey);
}

/**
Expand Down

0 comments on commit edcd0d7

Please sign in to comment.