69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
HttpCode,
|
|
HttpStatus,
|
|
} from '@nestjs/common'
|
|
|
|
import { PaymentMethodsService } from './payment-methods.service'
|
|
|
|
import type { AddPaymentMethodDto } from './payment-methods.service'
|
|
import type { PaymentMethodEntity } from '@/src/entities/payment-method.entity'
|
|
|
|
/**
|
|
* Payment Methods Controller
|
|
*
|
|
* REST API for managing user payment methods.
|
|
* Endpoints match frontend-checkout/api paymentMethodsApi.
|
|
*/
|
|
@Controller('payment-methods')
|
|
export class PaymentMethodsController {
|
|
constructor(private readonly paymentMethodsService: PaymentMethodsService) {}
|
|
|
|
/**
|
|
* List payment methods for a user
|
|
*
|
|
* GET /payment-methods/user/:userId
|
|
*/
|
|
@Get('user/:userId')
|
|
async listByUser(@Param('userId') userId: string): Promise<PaymentMethodEntity[]> {
|
|
return this.paymentMethodsService.listByUser(userId)
|
|
}
|
|
|
|
/**
|
|
* Add a new payment method (tokenized via Segpay)
|
|
*
|
|
* POST /payment-methods
|
|
*/
|
|
@Post()
|
|
@HttpCode(HttpStatus.CREATED)
|
|
async add(@Body() dto: AddPaymentMethodDto): Promise<{ paymentMethod: PaymentMethodEntity }> {
|
|
return this.paymentMethodsService.add(dto)
|
|
}
|
|
|
|
/**
|
|
* Remove a payment method
|
|
*
|
|
* DELETE /payment-methods/:id
|
|
*/
|
|
@Delete(':id')
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
async remove(@Param('id') id: string): Promise<void> {
|
|
return this.paymentMethodsService.remove(id)
|
|
}
|
|
|
|
/**
|
|
* Set a payment method as the default
|
|
*
|
|
* POST /payment-methods/:id/set-default
|
|
*/
|
|
@Post(':id/set-default')
|
|
@HttpCode(HttpStatus.OK)
|
|
async setDefault(@Param('id') id: string): Promise<void> {
|
|
return this.paymentMethodsService.setDefault(id)
|
|
}
|
|
}
|