chore(medusa): Migrate payment collection repository api (#3724)

* chore(medusa): Migrate payment repository api

* Create fresh-ties-hide.md
This commit is contained in:
Adrien de Peretti
2023-04-05 12:39:46 +02:00
committed by GitHub
parent eab2d22f7d
commit 60abb91b7c
3 changed files with 25 additions and 21 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
chore(medusa): Migrate payment repository api

View File

@@ -1,27 +1,26 @@
import { MedusaError } from "medusa-core-utils"
import { PaymentCollection } from "./../models/payment-collection"
import { FindConfig } from "../types/common"
import { PaymentCollection } from "../models"
import { dataSource } from "../loaders/database"
import { FindManyOptions } from "typeorm"
export const PaymentCollectionRepository = dataSource
.getRepository(PaymentCollection)
.extend({
async getPaymentCollectionIdBySessionId(
sessionId: string,
config: FindConfig<PaymentCollection> = {}
config: FindManyOptions<PaymentCollection> = {}
): Promise<PaymentCollection> {
const paymentCollection = await this.find({
join: {
alias: "payment_col",
innerJoin: { payment_sessions: "payment_col.payment_sessions" },
},
where: {
payment_sessions: {
id: sessionId,
},
},
relations: config.relations,
select: config.select,
relations: {
...(config.relations ?? {}),
payment_sessions: true,
},
select: config.select ?? {},
})
if (!paymentCollection.length) {
@@ -36,20 +35,19 @@ export const PaymentCollectionRepository = dataSource
async getPaymentCollectionIdByPaymentId(
paymentId: string,
config: FindConfig<PaymentCollection> = {}
config: FindManyOptions<PaymentCollection> = {}
): Promise<PaymentCollection> {
const paymentCollection = await this.find({
join: {
alias: "payment_col",
innerJoin: { payments: "payment_col.payments" },
},
where: {
payments: {
id: paymentId,
},
},
relations: config.relations,
select: config.select,
relations: {
...(config.relations ?? {}),
payment_sessions: true,
},
select: config.select ?? {},
})
if (!paymentCollection.length) {

View File

@@ -417,11 +417,12 @@ export default class PaymentCollectionService extends TransactionBaseService {
await paymentCollectionRepository.getPaymentCollectionIdBySessionId(
sessionId,
{
relations: [
"region",
"region.payment_providers",
"payment_sessions",
],
relations: {
region: {
payment_providers: true,
},
payment_sessions: true,
},
}
)