Skip to content

Commit

Permalink
CRYP-47 Add api retrieve delivery attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
thongnguyen5 authored and thongnguyendev committed Apr 16, 2024
1 parent 78660be commit bc89f8e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
16 changes: 16 additions & 0 deletions app/apps/onebox/src/modules/delivery/delivery.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { User } from '../users/schemas/user.schema';
import { DeliveryService } from './delivery.service';
import {
DeliveryAttemptResponseDto,
GetMonitorDeliveryDto,
MonitorDeliveryResponseDto,
} from './dto/delivery.dto';
Expand All @@ -33,4 +34,19 @@ export class DeliveryController {
body,
);
}

@ApiOperation({ summary: 'Get Delivery Attempts' })
@ApiBearerAuth('JWT')
@UseGuards(JwtAuthGuard)
@Get('/attempts')
@ApiOkResponse({ type: [DeliveryAttemptResponseDto] })
async getDeliveryAttempts(
@Req() req: Request,
@Query('deliveryId') deliveryId: string,
): Promise<DeliveryAttemptResponseDto[]> {
return await this.deliveryService.getDeliveryAttempt(
req.user as User,
deliveryId,
);
}
}
14 changes: 14 additions & 0 deletions app/apps/onebox/src/modules/delivery/delivery.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common';
import { MonitorService } from '../monitor/monitor.service';
import { User } from '../users/schemas/user.schema';
import {
DeliveryAttemptResponseDto,
GetMonitorDeliveryDto,
MonitorDeliveryResponseDto,
} from './dto/delivery.dto';
Expand Down Expand Up @@ -36,4 +37,17 @@ export class DeliveryService {
);
});
}

async getDeliveryAttempt(
user: User,
deliveryId: string,
): Promise<DeliveryAttemptResponseDto[]> {
return this.webhookService
.getDeliveryAttempts(deliveryId)
.then((response) => {
return response.delivery_attempts.map((attempt) =>
DeliveryAttemptResponseDto.from(attempt),
);
});
}
}
48 changes: 47 additions & 1 deletion app/apps/onebox/src/modules/delivery/dto/delivery.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { DeliveryDto } from '@app/shared_modules/webhook/webhook.service';
import {
DeliveryAttemptDto,
DeliveryDto,
} from '@app/shared_modules/webhook/webhook.service';
import { ApiProperty, ApiResponseProperty } from '@nestjs/swagger';
import { Builder } from 'builder-pattern';
import { Transform } from 'class-transformer';
Expand Down Expand Up @@ -58,3 +61,46 @@ export class MonitorDeliveryResponseDto {
.build();
}
}

export class DeliveryAttemptResponseDto {
@ApiResponseProperty()
id: string;

@ApiResponseProperty()
deliveryId: string;

@ApiResponseProperty()
request: string;

@ApiResponseProperty()
response: string;

@ApiResponseProperty()
responseStatusCode: number;

@ApiResponseProperty()
executionDuration: number;

@ApiResponseProperty()
success: boolean;

@ApiResponseProperty()
error: string;

@ApiResponseProperty()
dateCreated: string;

static from(dto: DeliveryAttemptDto): DeliveryAttemptResponseDto {
return Builder<DeliveryAttemptResponseDto>()
.id(dto.id)
.deliveryId(dto.delivery_id)
.request(dto.raw_request)
.response(dto.raw_response)
.responseStatusCode(dto.response_status_code)
.executionDuration(dto.execution_duration)
.success(dto.success)
.error(dto.error)
.dateCreated(dto.created_at)
.build();
}
}
4 changes: 2 additions & 2 deletions app/libs/shared_modules/src/webhook/webhook.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class UpdateWebhookRequestDto {
active?: boolean;
}

interface DeliveryAttemptDto {
export class DeliveryAttemptDto {
id: string;
// webhook_id: string;
delivery_id: string;
Expand All @@ -364,7 +364,7 @@ interface DeliveryAttemptDto {
created_at: string;
}

interface DeliveryAttemptsResponseDto {
export class DeliveryAttemptsResponseDto {
delivery_attempts: DeliveryAttemptDto[];
limit: number;
offset: number;
Expand Down

0 comments on commit bc89f8e

Please sign in to comment.