mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 10:52:53 +00:00
39 lines
1.6 KiB
TypeScript
39 lines
1.6 KiB
TypeScript
import { Injectable } from "@nestjs/common";
|
|
import { DataSource, FindOptionsWhere, QueryDeepPartialEntity, QueryRunner, Repository } from "typeorm";
|
|
import { PaymentEntity } from "./entities/payment.entity";
|
|
|
|
@Injectable()
|
|
export class PaymentRepository {
|
|
private readonly paymentRepo: Repository<PaymentEntity>;
|
|
constructor(private readonly dataSource: DataSource) {
|
|
this.paymentRepo = this.dataSource.getRepository(PaymentEntity)
|
|
}
|
|
|
|
async createTr(qr: QueryRunner, data: Pick<PaymentEntity, "amount" | "method" | "currency" | "type" | "refId" | "merchantOrderId" | "rawInitiation" | "clientAction" | "expiresAt">): Promise<PaymentEntity> {
|
|
const payment = qr.manager.create(PaymentEntity, data)
|
|
return qr.manager.save(payment)
|
|
}
|
|
|
|
findOneBy(options: FindOptionsWhere<PaymentEntity> | FindOptionsWhere<PaymentEntity>[]): Promise<PaymentEntity | null> {
|
|
return this.paymentRepo.findOneBy(options);
|
|
}
|
|
|
|
update(where: FindOptionsWhere<PaymentEntity>, data: QueryDeepPartialEntity<PaymentEntity>) {
|
|
return this.paymentRepo.update(where, data)
|
|
}
|
|
|
|
getActivePaymentByRefIdAndMethod(refId: string, method: PaymentEntity["method"]) {
|
|
return this.paymentRepo
|
|
.createQueryBuilder('payment')
|
|
.where('payment.method = :method', { method })
|
|
.andWhere('payment.refId = :refId', { refId })
|
|
.andWhere('payment.status IN (:...statuses)', {
|
|
statuses: ['action-required'],
|
|
})
|
|
.andWhere('payment.expiresAt > :now', { now: new Date() })
|
|
.getOne();
|
|
}
|
|
|
|
|
|
|
|
} |