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 authored and GitHub committed 2023-04-05 12:39:46 +02:00
1 parent eab2d22f7d
commit 60abb91b7c
3 files changed
+25 -21

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
chore(medusa): Migrate payment repository api
@@ -1,27 +1,26 @@
import { MedusaError } from "medusa-core-utils" import { MedusaError } from "medusa-core-utils"
import { PaymentCollection } from "./../models/payment-collection" import { PaymentCollection } from "../models"
import { FindConfig } from "../types/common"
import { dataSource } from "../loaders/database" import { dataSource } from "../loaders/database"
import { FindManyOptions } from "typeorm"
export const PaymentCollectionRepository = dataSource export const PaymentCollectionRepository = dataSource
.getRepository(PaymentCollection) .getRepository(PaymentCollection)
.extend({ .extend({
async getPaymentCollectionIdBySessionId( async getPaymentCollectionIdBySessionId(
sessionId: string, sessionId: string,
config: FindConfig<PaymentCollection> = {} config: FindManyOptions<PaymentCollection> = {}
): Promise<PaymentCollection> { ): Promise<PaymentCollection> {
const paymentCollection = await this.find({ const paymentCollection = await this.find({
join: {
alias: "payment_col",
innerJoin: { payment_sessions: "payment_col.payment_sessions" },
},
where: { where: {
payment_sessions: { payment_sessions: {
id: sessionId, id: sessionId,
}, },
}, },
relations: config.relations, relations: {
select: config.select, ...(config.relations ?? {}),
payment_sessions: true,
},
select: config.select ?? {},
}) })
if (!paymentCollection.length) { if (!paymentCollection.length) {
@@ -36,20 +35,19 @@ export const PaymentCollectionRepository = dataSource
async getPaymentCollectionIdByPaymentId( async getPaymentCollectionIdByPaymentId(
paymentId: string, paymentId: string,
config: FindConfig<PaymentCollection> = {} config: FindManyOptions<PaymentCollection> = {}
): Promise<PaymentCollection> { ): Promise<PaymentCollection> {
const paymentCollection = await this.find({ const paymentCollection = await this.find({
join: {
alias: "payment_col",
innerJoin: { payments: "payment_col.payments" },
},
where: { where: {
payments: { payments: {
id: paymentId, id: paymentId,
}, },
}, },
relations: config.relations, relations: {
select: config.select, ...(config.relations ?? {}),
payment_sessions: true,
},
select: config.select ?? {},
}) })
if (!paymentCollection.length) { if (!paymentCollection.length) {
@@ -417,11 +417,12 @@ export default class PaymentCollectionService extends TransactionBaseService {
await paymentCollectionRepository.getPaymentCollectionIdBySessionId( await paymentCollectionRepository.getPaymentCollectionIdBySessionId(
sessionId, sessionId,
{ {
relations: [ relations: {
"region", region: {
"region.payment_providers", payment_providers: true,
"payment_sessions", },
], payment_sessions: true,
},
} }
) )