forked from MergeFi/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathescrow.controller.ts
More file actions
49 lines (43 loc) · 1.51 KB
/
Copy pathescrow.controller.ts
File metadata and controls
49 lines (43 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { EscrowService } from './escrow.service';
import { FundEscrowDto } from './dto/fund-escrow.dto';
import { ReleaseEscrowDto } from './dto/release-escrow.dto';
import { SplitReleaseDto } from './dto/split-release.dto';
import { toPublicEscrow } from './escrow-response.mapper';
import { Idempotent } from '../common/idempotency/idempotent.decorator';
@ApiTags('escrow')
@Controller('escrow')
export class EscrowController {
constructor(private readonly escrowService: EscrowService) {}
@Idempotent('escrow.fund')
@Post('fund')
async fund(@Body() dto: FundEscrowDto) {
return toPublicEscrow(await this.escrowService.fund(dto));
}
@Get(':id')
async findOne(@Param('id') id: string) {
return toPublicEscrow(await this.escrowService.findOne(id));
}
@Idempotent('escrow.release')
@Post(':id/release')
async release(@Param('id') id: string, @Body() dto: ReleaseEscrowDto) {
return toPublicEscrow(
await this.escrowService.release(
id,
dto.recipientAddress,
dto.recipientId,
),
);
}
@Idempotent('escrow.splitRelease')
@Post(':id/split-release')
splitRelease(@Param('id') id: string, @Body() dto: SplitReleaseDto) {
return this.escrowService.splitRelease(id, dto.recipients);
}
@Idempotent('escrow.refund')
@Post(':id/refund')
async refund(@Param('id') id: string) {
return toPublicEscrow(await this.escrowService.refund(id));
}
}