51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
import { Body, Controller, Get, Param, Patch, Post, Query } from "@nestjs/common";
|
|
import { CurrentUser } from "../common/decorators/current-user.decorator";
|
|
import { ok } from "../common/response";
|
|
import { BillPayService } from "./bill-pay.service";
|
|
import { CreateBillDto, CreateBillPayeeDto, InitiateBillPaymentDto, MarkBillPaidDto, UpdateBillDto } from "./dto";
|
|
|
|
@Controller("bill-pay")
|
|
export class BillPayController {
|
|
constructor(private readonly billPayService: BillPayService) {}
|
|
|
|
@Get("summary")
|
|
async summary(@CurrentUser() userId: string) {
|
|
return ok(await this.billPayService.summary(userId));
|
|
}
|
|
|
|
@Get("payees")
|
|
async payees(@CurrentUser() userId: string) {
|
|
return ok(await this.billPayService.listPayees(userId));
|
|
}
|
|
|
|
@Post("payees")
|
|
async createPayee(@CurrentUser() userId: string, @Body() body: CreateBillPayeeDto) {
|
|
return ok(await this.billPayService.createPayee(userId, body));
|
|
}
|
|
|
|
@Get("bills")
|
|
async bills(@CurrentUser() userId: string, @Query("status") status?: string) {
|
|
return ok(await this.billPayService.listBills(userId, status));
|
|
}
|
|
|
|
@Post("bills")
|
|
async createBill(@CurrentUser() userId: string, @Body() body: CreateBillDto) {
|
|
return ok(await this.billPayService.createBill(userId, body));
|
|
}
|
|
|
|
@Patch("bills/:id")
|
|
async updateBill(@CurrentUser() userId: string, @Param("id") id: string, @Body() body: UpdateBillDto) {
|
|
return ok(await this.billPayService.updateBill(userId, id, body));
|
|
}
|
|
|
|
@Post("bills/:id/pay")
|
|
async markPaid(@CurrentUser() userId: string, @Param("id") id: string, @Body() body: MarkBillPaidDto) {
|
|
return ok(await this.billPayService.markPaid(userId, id, body));
|
|
}
|
|
|
|
@Post("bills/:id/initiate-payment")
|
|
async initiatePayment(@CurrentUser() userId: string, @Param("id") id: string, @Body() body: InitiateBillPaymentDto) {
|
|
return ok(await this.billPayService.initiatePayment(userId, id, body));
|
|
}
|
|
}
|