-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rest)!: update to AFJ 0.2.0 (#148)
Co-authored-by: Akiff Manji <akiff.manji@gmail.com> Signed-off-by: Jan <60812202+janrtvld@users.noreply.github.com>
- Loading branch information
Showing
54 changed files
with
8,503 additions
and
1,807 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ build | |
.vscode | ||
.idea | ||
coverage | ||
CHANGELOG.md | ||
CHANGELOG.md | ||
routes |
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 was deleted.
Oops, something went wrong.
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
50 changes: 26 additions & 24 deletions
50
packages/rest/src/controllers/basic-messages/BasicMessageController.ts
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 |
---|---|---|
@@ -1,53 +1,55 @@ | ||
import type { BasicMessageRecord, BasicMessageStorageProps } from '@aries-framework/core' | ||
|
||
import { Agent, RecordNotFoundError } from '@aries-framework/core' | ||
import { | ||
Body, | ||
Get, | ||
InternalServerError, | ||
JsonController, | ||
NotFoundError, | ||
OnUndefined, | ||
Param, | ||
Post, | ||
} from 'routing-controllers' | ||
import { Body, Controller, Example, Get, Path, Post, Res, Route, Tags, TsoaResponse } from 'tsoa' | ||
import { injectable } from 'tsyringe' | ||
|
||
import { BasicMessageRequest } from '../../schemas/BasicMessageRequest' | ||
import { BasicMessageRecordExample, RecordId } from '../examples' | ||
|
||
@JsonController('/basic-messages') | ||
@Tags('Basic Messages') | ||
@Route('/basic-messages') | ||
@injectable() | ||
export class BasicMessageController { | ||
export class BasicMessageController extends Controller { | ||
private agent: Agent | ||
|
||
public constructor(agent: Agent) { | ||
super() | ||
this.agent = agent | ||
} | ||
|
||
/** | ||
* Retrieve basic messages by connectionId | ||
* Retrieve basic messages by connection id | ||
* | ||
* @param connectionId Connection identifier | ||
* @returns BasicMessageRecord[] | ||
*/ | ||
@Example<BasicMessageStorageProps[]>([BasicMessageRecordExample]) | ||
@Get('/:connectionId') | ||
public async getBasicMessages(@Param('connectionId') connectionId: string) { | ||
const basicMessages = await this.agent.basicMessages.findAllByQuery({ connectionId: connectionId }) | ||
return basicMessages.map((m) => m.toJSON()) | ||
public async getBasicMessages(@Path('connectionId') connectionId: RecordId): Promise<BasicMessageRecord[]> { | ||
return await this.agent.basicMessages.findAllByQuery({ connectionId }) | ||
} | ||
|
||
/** | ||
* Send a basic message to a connection | ||
* | ||
* @param connectionId Connection identifier | ||
* @param content The content of the message | ||
*/ | ||
@Post('/:connectionId') | ||
@OnUndefined(204) | ||
public async sendMessage( | ||
@Param('connectionId') connectionId: string, | ||
@Body() | ||
basicMessage: BasicMessageRequest | ||
@Path('connectionId') connectionId: RecordId, | ||
@Body() request: Record<'content', string>, | ||
@Res() notFoundError: TsoaResponse<404, { reason: string }>, | ||
@Res() internalServerError: TsoaResponse<500, { message: string }> | ||
) { | ||
try { | ||
await this.agent.basicMessages.sendMessage(connectionId, basicMessage.content) | ||
this.setStatus(204) | ||
await this.agent.basicMessages.sendMessage(connectionId, request.content) | ||
} catch (error) { | ||
if (error instanceof RecordNotFoundError) { | ||
throw new NotFoundError(`connection with connectionId "${connectionId}" not found.`) | ||
return notFoundError(404, { reason: `connection with connection id "${connectionId}" not found.` }) | ||
} | ||
throw new InternalServerError(`something went wrong: ${error}`) | ||
return internalServerError(500, { message: `something went wrong: ${error}` }) | ||
} | ||
} | ||
} |
Oops, something went wrong.