Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Bhutan-NDI/ngotag-agent-controller …
Browse files Browse the repository at this point in the history
…into pipeline-implementation
  • Loading branch information
Sheetal-ayanworks committed Jul 11, 2024
2 parents 5e94ecd + 9e84017 commit 9641fa3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/controllers/multi-tenancy/MultiTenancyController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,15 @@ export class MultiTenancyController extends Controller {
})
})

if (schemaResponse.schemaState?.state === 'failed') {
const reason = schemaResponse.schemaState?.reason?.toLowerCase()
if (reason && reason.includes('insufficient') && reason.includes('funds')) {
throw new Error('Insufficient funds to the address, Please add funds to perform this operation')
} else {
throw new Error(schemaResponse.schemaState?.reason)
}
}

const configFileData = fs.readFileSync('config.json', 'utf-8')
const config = JSON.parse(configFileData)
if (!config.schemaFileServerURL) {
Expand Down Expand Up @@ -2004,4 +2013,35 @@ export class MultiTenancyController extends Controller {

return questionAnswerRecord
}

/**
* Send a question to a connection
*
* @param tenantId Tenant identifier
* @param connectionId Connection identifier
* @param content The content of the message
*/
@Security('apiKey')
@Post('/basic-message/:connectionId/:tenantId')
public async sendBasicMessage(
@Path('connectionId') connectionId: RecordId,
@Path('tenantId') tenantId: string,
@Body() request: Record<'content', string>,
@Res() notFoundError: TsoaResponse<404, { reason: string }>,
@Res() internalServerError: TsoaResponse<500, { message: string }>
) {
try {
let basicMessageRecord
await this.agent.modules.tenants.withTenantAgent({ tenantId }, async (tenantAgent) => {
basicMessageRecord = await tenantAgent.basicMessages.sendMessage(connectionId, request.content)
basicMessageRecord = basicMessageRecord?.toJSON()
})
return basicMessageRecord
} catch (error) {
if (error instanceof RecordNotFoundError) {
return notFoundError(404, { reason: `connection with connection id "${connectionId}" not found.` })
}
return internalServerError(500, { message: `something went wrong: ${error}` })
}
}
}
9 changes: 9 additions & 0 deletions src/controllers/polygon/PolygonController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ export class Polygon extends Controller {
schema,
})

if (schemaResponse.schemaState?.state === 'failed') {
const reason = schemaResponse.schemaState?.reason?.toLowerCase()
if (reason && reason.includes('insufficient') && reason.includes('funds')) {
throw new Error('Insufficient funds to the address, Please add funds to perform this operation')
} else {
throw new Error(schemaResponse.schemaState?.reason)
}
}

const schemaServerConfig = fs.readFileSync('config.json', 'utf-8')
const configJson = JSON.parse(schemaServerConfig)
if (!configJson.schemaFileServerURL) {
Expand Down

0 comments on commit 9641fa3

Please sign in to comment.