mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 14:08:11 +00:00
Project Initialization
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Passenger } from '@edr/types';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
|
||||
@Entity({ name: 'payments' })
|
||||
export class Payment extends BaseEntity {
|
||||
@Column({ name: 'ticket_id', type: 'uuid' })
|
||||
ticketId!: string;
|
||||
|
||||
@Column({ name: 'amount', type: 'numeric', precision: 10, scale: 2 })
|
||||
amount!: number;
|
||||
|
||||
@Column({ name: 'currency', type: 'varchar', length: 8, default: 'ETB' })
|
||||
currency!: string;
|
||||
|
||||
@Column({
|
||||
name: 'status',
|
||||
type: 'enum',
|
||||
enum: Passenger.PaymentStatus,
|
||||
default: Passenger.PaymentStatus.Pending,
|
||||
})
|
||||
status!: Passenger.PaymentStatus;
|
||||
|
||||
@Column({ name: 'provider', type: 'varchar', length: 64 })
|
||||
provider!: string;
|
||||
|
||||
@Column({ name: 'provider_transaction_id', type: 'varchar', length: 256, nullable: true })
|
||||
providerTransactionId?: string | null;
|
||||
|
||||
@Column({ name: 'paid_at', type: 'timestamptz', nullable: true })
|
||||
paidAt?: Date | null;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Controller, Get, Param, ParseUUIDPipe } from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
|
||||
import { PaymentsService } from './payments.service';
|
||||
|
||||
@ApiTags('payments')
|
||||
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
|
||||
@Controller('payments')
|
||||
export class PaymentsController {
|
||||
constructor(private readonly paymentsService: PaymentsService) {}
|
||||
|
||||
@Get('ticket/:ticketId')
|
||||
@ApiOperation({ summary: 'List payments for a ticket' })
|
||||
findByTicket(@Param('ticketId', ParseUUIDPipe) ticketId: string) {
|
||||
return this.paymentsService.findByTicket(ticketId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { Payment } from './entities/payment.entity';
|
||||
import { PaymentsController } from './payments.controller';
|
||||
import { PaymentsService } from './payments.service';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Payment])],
|
||||
controllers: [PaymentsController],
|
||||
providers: [PaymentsService],
|
||||
exports: [PaymentsService],
|
||||
})
|
||||
export class PaymentsModule {}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { Payment } from './entities/payment.entity';
|
||||
|
||||
@Injectable()
|
||||
export class PaymentsService {
|
||||
constructor(
|
||||
@InjectRepository(Payment)
|
||||
private readonly paymentsRepository: Repository<Payment>,
|
||||
) {}
|
||||
|
||||
/** List payments associated with a ticket. */
|
||||
findByTicket(ticketId: string): Promise<Payment[]> {
|
||||
return this.paymentsRepository.find({
|
||||
where: { ticketId },
|
||||
order: { createdAt: 'DESC' },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user