Skip to content

Commit

Permalink
fix: improve types and Swagger definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Feb 12, 2025
1 parent dcc4b4a commit abe7bf9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
16 changes: 4 additions & 12 deletions src/routes/targeted-messaging/entities/targeted-safe.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@ import type { TargetedSafe as DomainTargetedSafe } from '@/domain/targeted-messa
export class TargetedSafe
implements Pick<DomainTargetedSafe, 'outreachId' | 'address'>
{
@ApiProperty()
outreachId: number;
@ApiProperty({ type: Number })
outreachId!: DomainTargetedSafe['outreachId'];

@ApiProperty()
address: `0x${string}`;

constructor({
outreachId,
address,
}: Pick<DomainTargetedSafe, 'outreachId' | 'address'>) {
this.outreachId = outreachId;
this.address = address;
}
@ApiProperty({ type: String })
address!: DomainTargetedSafe['address'];
}
15 changes: 12 additions & 3 deletions src/routes/targeted-messaging/targeted-messaging.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { TargetedSafeSchema } from '@/domain/targeted-messaging/entities/targeted-safe.entity';
import {
TargetedSafe as DomainTargetedSafe,
TargetedSafeSchema,
} from '@/domain/targeted-messaging/entities/targeted-safe.entity';
import { TargetedSafeNotFoundError } from '@/domain/targeted-messaging/errors/targeted-safe-not-found.error';
import {
CreateSubmissionDto,
Expand All @@ -21,7 +24,12 @@ import {
Post,
Res,
} from '@nestjs/common';
import { ApiCreatedResponse, ApiOkResponse, ApiTags } from '@nestjs/swagger';
import {
ApiCreatedResponse,
ApiNotFoundResponse,
ApiOkResponse,
ApiTags,
} from '@nestjs/swagger';
import { Response } from 'express';

@ApiTags('targeted-messaging')
Expand All @@ -33,14 +41,15 @@ export class TargetedMessagingController {
constructor(private readonly service: TargetedMessagingService) {}

@ApiOkResponse({ type: TargetedSafe })
@ApiNotFoundResponse({ description: 'Safe not targeted.' })
@Get(':outreachId/chains/:chainId/safes/:safeAddress')
async getTargetedSafe(
@Param(
'outreachId',
ParseIntPipe,
new ValidationPipe(TargetedSafeSchema.shape.outreachId),
)
outreachId: number,
outreachId: DomainTargetedSafe['outreachId'],
@Param('chainId', new ValidationPipe(NumericStringSchema)) chainId: string,
@Param('safeAddress', new ValidationPipe(AddressSchema))
safeAddress: `0x${string}`,
Expand Down
6 changes: 3 additions & 3 deletions src/routes/targeted-messaging/targeted-messaging.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export class TargetedMessagingService {
) {}

async getTargetedSafe(args: {
outreachId: number;
outreachId: TargetedSafe['outreachId'];
chainId: string;
safeAddress: `0x${string}`;
}): Promise<RouteTargetedSafe> {
const targetedSafe = await this.repository.getTargetedSafe(args);
return new RouteTargetedSafe({
return {
outreachId: targetedSafe.outreachId,
address: targetedSafe.address,
});
};
}

async getSubmission(args: {
Expand Down

0 comments on commit abe7bf9

Please sign in to comment.