committed by
GitHub
parent
c661cc789b
commit
eb8034502b
@@ -29,4 +29,4 @@ export default (fn: handler): RequestHandler => {
|
||||
* message:
|
||||
* type: string
|
||||
* default: "Provided request body contains errors. Please check the data and retry the request"
|
||||
*/
|
||||
*/
|
||||
|
||||
@@ -82,4 +82,4 @@ export default () => {
|
||||
* type:
|
||||
* type: string
|
||||
* description: A slug indicating the type of the error.
|
||||
*/
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { IsEmail, IsNotEmpty, IsString } from "class-validator"
|
||||
|
||||
import AuthService from "../../../../services/auth"
|
||||
import { EntityManager } from "typeorm";
|
||||
import { EntityManager } from "typeorm"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import _ from "lodash"
|
||||
import jwt from "jsonwebtoken"
|
||||
@@ -78,7 +78,9 @@ import { validator } from "../../../../utils/validator"
|
||||
* $ref: "#/components/responses/500_error"
|
||||
*/
|
||||
export default async (req, res) => {
|
||||
const { projectConfig: { jwt_secret } } = req.scope.resolve('configModule')
|
||||
const {
|
||||
projectConfig: { jwt_secret },
|
||||
} = req.scope.resolve("configModule")
|
||||
if (!jwt_secret) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_FOUND,
|
||||
@@ -90,10 +92,9 @@ export default async (req, res) => {
|
||||
const authService: AuthService = req.scope.resolve("authService")
|
||||
const manager: EntityManager = req.scope.resolve("manager")
|
||||
const result = await manager.transaction(async (transactionManager) => {
|
||||
return await authService.withTransaction(transactionManager).authenticate(
|
||||
validated.email,
|
||||
validated.password
|
||||
)
|
||||
return await authService
|
||||
.withTransaction(transactionManager)
|
||||
.authenticate(validated.email, validated.password)
|
||||
})
|
||||
|
||||
if (result.success && result.user) {
|
||||
|
||||
@@ -320,27 +320,37 @@ export class AdminGetBatchParams extends AdminGetBatchPaginationParams {
|
||||
type?: string[]
|
||||
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => (value === "null" ? null : value))
|
||||
@Transform(({ value }) => {
|
||||
return value === "null" ? null : value
|
||||
})
|
||||
@Type(() => DateComparisonOperator)
|
||||
confirmed_at?: DateComparisonOperator | null
|
||||
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => (value === "null" ? null : value))
|
||||
@Transform(({ value }) => {
|
||||
return value === "null" ? null : value
|
||||
})
|
||||
@Type(() => DateComparisonOperator)
|
||||
pre_processed_at?: DateComparisonOperator | null
|
||||
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => (value === "null" ? null : value))
|
||||
@Transform(({ value }) => {
|
||||
return value === "null" ? null : value
|
||||
})
|
||||
@Type(() => DateComparisonOperator)
|
||||
completed_at?: DateComparisonOperator | null
|
||||
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => (value === "null" ? null : value))
|
||||
@Transform(({ value }) => {
|
||||
return value === "null" ? null : value
|
||||
})
|
||||
@Type(() => DateComparisonOperator)
|
||||
failed_at?: DateComparisonOperator | null
|
||||
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => (value === "null" ? null : value))
|
||||
@Transform(({ value }) => {
|
||||
return value === "null" ? null : value
|
||||
})
|
||||
@Type(() => DateComparisonOperator)
|
||||
canceled_at?: DateComparisonOperator | null
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Request, Response } from "express"
|
||||
|
||||
import { EntityManager } from "typeorm";
|
||||
import { EntityManager } from "typeorm"
|
||||
import ProductCollectionService from "../../../../services/product-collection"
|
||||
|
||||
/**
|
||||
@@ -72,10 +72,11 @@ export default async (req: Request, res: Response) => {
|
||||
|
||||
const manager: EntityManager = req.scope.resolve("manager")
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
return await productCollectionService.withTransaction(transactionManager).delete(id)
|
||||
return await productCollectionService
|
||||
.withTransaction(transactionManager)
|
||||
.delete(id)
|
||||
})
|
||||
|
||||
|
||||
res.json({
|
||||
id,
|
||||
object: "product-collection",
|
||||
|
||||
@@ -2,7 +2,10 @@ import { Router } from "express"
|
||||
import "reflect-metadata"
|
||||
import { ProductCollection } from "../../../.."
|
||||
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
||||
import middlewares, { transformBody, transformQuery } from "../../../middlewares"
|
||||
import middlewares, {
|
||||
transformBody,
|
||||
transformQuery,
|
||||
} from "../../../middlewares"
|
||||
import { AdminGetCollectionsParams } from "./list-collections"
|
||||
import { AdminPostCollectionsReq } from "./create-collection"
|
||||
import { AdminPostCollectionsCollectionReq } from "./update-collection"
|
||||
@@ -20,14 +23,11 @@ export default (app) => {
|
||||
)
|
||||
route.get(
|
||||
"/",
|
||||
transformQuery(
|
||||
AdminGetCollectionsParams,
|
||||
{
|
||||
defaultRelations: defaultAdminCollectionsRelations,
|
||||
defaultFields: defaultAdminCollectionsFields,
|
||||
isList: true,
|
||||
}
|
||||
),
|
||||
transformQuery(AdminGetCollectionsParams, {
|
||||
defaultRelations: defaultAdminCollectionsRelations,
|
||||
defaultFields: defaultAdminCollectionsFields,
|
||||
isList: true,
|
||||
}),
|
||||
middlewares.wrap(require("./list-collections").default)
|
||||
)
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ export default async (req: Request, res: Response) => {
|
||||
const {
|
||||
validatedQuery: { limit, offset },
|
||||
filterableFields,
|
||||
listConfig
|
||||
listConfig,
|
||||
} = req
|
||||
|
||||
const [collections, count] = await productCollectionService.listAndCount(
|
||||
@@ -174,6 +174,7 @@ export class AdminGetCollectionsPaginationParams {
|
||||
offset = 0
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
export class AdminGetCollectionsParams extends AdminGetCollectionsPaginationParams {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ArrayNotEmpty, IsString } from "class-validator"
|
||||
import { Request, Response } from "express"
|
||||
import { EntityManager } from "typeorm";
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
import ProductCollectionService from "../../../../services/product-collection"
|
||||
|
||||
@@ -77,7 +77,9 @@ import ProductCollectionService from "../../../../services/product-collection"
|
||||
*/
|
||||
export default async (req: Request, res: Response) => {
|
||||
const { id } = req.params
|
||||
const { validatedBody } = req as { validatedBody: AdminDeleteProductsFromCollectionReq }
|
||||
const { validatedBody } = req as {
|
||||
validatedBody: AdminDeleteProductsFromCollectionReq
|
||||
}
|
||||
|
||||
const productCollectionService: ProductCollectionService = req.scope.resolve(
|
||||
"productCollectionService"
|
||||
@@ -85,7 +87,9 @@ export default async (req: Request, res: Response) => {
|
||||
|
||||
const manager: EntityManager = req.scope.resolve("manager")
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
return await productCollectionService.withTransaction(transactionManager).removeProducts(id, validatedBody.product_ids)
|
||||
return await productCollectionService
|
||||
.withTransaction(transactionManager)
|
||||
.removeProducts(id, validatedBody.product_ids)
|
||||
})
|
||||
|
||||
res.json({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { IsObject, IsOptional, IsString } from "class-validator"
|
||||
import { Request, Response } from "express"
|
||||
import { EntityManager } from "typeorm";
|
||||
import { EntityManager } from "typeorm"
|
||||
import ProductCollectionService from "../../../../services/product-collection"
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,7 @@ import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/ta
|
||||
import { PaginatedResponse } from "../../../../types/common"
|
||||
import middlewares, {
|
||||
transformBody,
|
||||
transformQuery
|
||||
transformQuery,
|
||||
} from "../../../middlewares"
|
||||
import { isFeatureFlagEnabled } from "../../../middlewares/feature-flag-enabled"
|
||||
import { AdminGetCurrenciesParams } from "./list-currencies"
|
||||
@@ -12,10 +12,7 @@ import { AdminPostCurrenciesCurrencyReq } from "./update-currency"
|
||||
|
||||
export default (app) => {
|
||||
const route = Router()
|
||||
app.use(
|
||||
"/currencies",
|
||||
route
|
||||
)
|
||||
app.use("/currencies", route)
|
||||
|
||||
route.get(
|
||||
"/",
|
||||
@@ -45,4 +42,3 @@ export type AdminCurrenciesRes = {
|
||||
|
||||
export * from "./list-currencies"
|
||||
export * from "./update-currency"
|
||||
|
||||
|
||||
@@ -147,6 +147,7 @@ export default async (req, res) => {
|
||||
res.status(200).json({ discount })
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
export class AdminPostDiscountsDiscountConditions extends AdminUpsertConditionsReq {
|
||||
@IsString()
|
||||
operator: DiscountConditionOperator
|
||||
|
||||
@@ -152,6 +152,7 @@ export default async (req, res) => {
|
||||
res.status(200).json({ discount })
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
export class AdminPostDiscountsDiscountConditionsCondition extends AdminUpsertConditionsReq {}
|
||||
|
||||
export class AdminPostDiscountsDiscountConditionsConditionParams {
|
||||
|
||||
@@ -213,6 +213,7 @@ export default async (req: Request, res) => {
|
||||
})
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
export class AdminGetPriceListsPriceListProductsParams extends extendedFindParamsMixin(
|
||||
{ limit: 50 }
|
||||
) {
|
||||
|
||||
@@ -187,6 +187,7 @@ export default async (req: Request, res) => {
|
||||
})
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
export class AdminGetPriceListPaginationParams extends FilterablePriceListProps {
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
|
||||
@@ -201,6 +201,7 @@ export class AdminGetProductTagsPaginationParams {
|
||||
offset = 0
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
export class AdminGetProductTagsParams extends AdminGetProductTagsPaginationParams {
|
||||
@IsType([String, [String], StringComparisonOperator])
|
||||
@IsOptional()
|
||||
|
||||
@@ -202,6 +202,7 @@ export class AdminGetProductTypesPaginationParams {
|
||||
offset? = 0
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
export class AdminGetProductTypesParams extends AdminGetProductTypesPaginationParams {
|
||||
@IsType([String, [String], StringComparisonOperator])
|
||||
@IsOptional()
|
||||
|
||||
@@ -90,7 +90,7 @@ export default async (req, res) => {
|
||||
try {
|
||||
const userService: UserService = req.scope.resolve("userService")
|
||||
|
||||
const decoded = (await jwt.decode(validated.token)) as payload
|
||||
const decoded = jwt.decode(validated.token) as payload
|
||||
|
||||
let user: User
|
||||
try {
|
||||
@@ -104,10 +104,10 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, "invalid token")
|
||||
}
|
||||
|
||||
const verifiedToken = (await jwt.verify(
|
||||
const verifiedToken = jwt.verify(
|
||||
validated.token,
|
||||
user.password_hash
|
||||
)) as payload
|
||||
) as payload
|
||||
if (!verifiedToken || verifiedToken.user_id !== user.id) {
|
||||
res.status(401).send("Invalid or expired password reset token")
|
||||
return
|
||||
|
||||
@@ -55,12 +55,7 @@ export default async (req, res) => {
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
idempotencyKey = await idempotencyKeyService
|
||||
.withTransaction(transactionManager)
|
||||
.initializeRequest(
|
||||
headerKey,
|
||||
req.method,
|
||||
req.params,
|
||||
req.path
|
||||
)
|
||||
.initializeRequest(headerKey, req.method, req.params, req.path)
|
||||
})
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
@@ -85,21 +80,23 @@ export default async (req, res) => {
|
||||
.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async (manager: EntityManager) => {
|
||||
const cart = await cartService.withTransaction(manager).retrieve(
|
||||
id,
|
||||
{
|
||||
relations: ["items", "items.adjustments"],
|
||||
select: [
|
||||
"total",
|
||||
"subtotal",
|
||||
"tax_total",
|
||||
"discount_total",
|
||||
"shipping_total",
|
||||
"gift_card_total",
|
||||
],
|
||||
},
|
||||
{ force_taxes: true }
|
||||
)
|
||||
const cart = await cartService
|
||||
.withTransaction(manager)
|
||||
.retrieve(
|
||||
id,
|
||||
{
|
||||
relations: ["items", "items.adjustments"],
|
||||
select: [
|
||||
"total",
|
||||
"subtotal",
|
||||
"tax_total",
|
||||
"discount_total",
|
||||
"shipping_total",
|
||||
"gift_card_total",
|
||||
],
|
||||
},
|
||||
{ force_taxes: true }
|
||||
)
|
||||
|
||||
const data = await decorateLineItemsWithTotals(cart, req, {
|
||||
force_taxes: true,
|
||||
@@ -131,14 +128,11 @@ export default async (req, res) => {
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
idempotencyKey = await idempotencyKeyService
|
||||
.withTransaction(transactionManager)
|
||||
.update(
|
||||
idempotencyKey.idempotency_key,
|
||||
{
|
||||
recovery_point: "finished",
|
||||
response_code: 500,
|
||||
response_body: { message: "Unknown recovery point" },
|
||||
}
|
||||
)
|
||||
.update(idempotencyKey.idempotency_key, {
|
||||
recovery_point: "finished",
|
||||
response_code: 500,
|
||||
response_body: { message: "Unknown recovery point" },
|
||||
})
|
||||
})
|
||||
break
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { EntityManager } from "typeorm";
|
||||
import { EntityManager } from "typeorm"
|
||||
import { AbstractCartCompletionStrategy } from "../../../../interfaces"
|
||||
import { IdempotencyKey } from "../../../../models/idempotency-key"
|
||||
import { IdempotencyKeyService } from "../../../../services"
|
||||
@@ -88,12 +88,9 @@ export default async (req, res) => {
|
||||
let idempotencyKey: IdempotencyKey
|
||||
try {
|
||||
idempotencyKey = await manager.transaction(async (transactionManager) => {
|
||||
return await idempotencyKeyService.withTransaction(transactionManager).initializeRequest(
|
||||
headerKey,
|
||||
req.method,
|
||||
req.params,
|
||||
req.path
|
||||
)
|
||||
return await idempotencyKeyService
|
||||
.withTransaction(transactionManager)
|
||||
.initializeRequest(headerKey, req.method, req.params, req.path)
|
||||
})
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { defaultStoreCartFields, defaultStoreCartRelations } from "."
|
||||
import { CartService } from "../../../../services"
|
||||
import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals"
|
||||
import { EntityManager } from "typeorm";
|
||||
import IdempotencyKeyService from "../../../../services/idempotency-key";
|
||||
import { EntityManager } from "typeorm"
|
||||
import IdempotencyKeyService from "../../../../services/idempotency-key"
|
||||
|
||||
/**
|
||||
* @oas [post] /carts/{id}/payment-sessions
|
||||
@@ -61,12 +61,9 @@ export default async (req, res) => {
|
||||
let idempotencyKey
|
||||
try {
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
idempotencyKey = await idempotencyKeyService.withTransaction(transactionManager).initializeRequest(
|
||||
headerKey,
|
||||
req.method,
|
||||
req.params,
|
||||
req.path
|
||||
)
|
||||
idempotencyKey = await idempotencyKeyService
|
||||
.withTransaction(transactionManager)
|
||||
.initializeRequest(headerKey, req.method, req.params, req.path)
|
||||
})
|
||||
} catch (error) {
|
||||
res.status(409).send("Failed to create idempotency key")
|
||||
@@ -89,23 +86,28 @@ export default async (req, res) => {
|
||||
.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async (stageManager) => {
|
||||
await cartService.withTransaction(stageManager).setPaymentSessions(id)
|
||||
await cartService
|
||||
.withTransaction(stageManager)
|
||||
.setPaymentSessions(id)
|
||||
|
||||
const cart = await cartService.withTransaction(stageManager).retrieve(id, {
|
||||
select: defaultStoreCartFields,
|
||||
relations: defaultStoreCartRelations,
|
||||
})
|
||||
const cart = await cartService
|
||||
.withTransaction(stageManager)
|
||||
.retrieve(id, {
|
||||
select: defaultStoreCartFields,
|
||||
relations: defaultStoreCartRelations,
|
||||
})
|
||||
|
||||
const data = await decorateLineItemsWithTotals(cart, req, {
|
||||
force_taxes: false,
|
||||
transactionManager: stageManager
|
||||
transactionManager: stageManager,
|
||||
})
|
||||
|
||||
return {
|
||||
response_code: 200,
|
||||
response_body: { cart: data },
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
if (error) {
|
||||
inProgress = false
|
||||
@@ -126,14 +128,11 @@ export default async (req, res) => {
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
idempotencyKey = await idempotencyKeyService
|
||||
.withTransaction(transactionManager)
|
||||
.update(
|
||||
idempotencyKey.idempotency_key,
|
||||
{
|
||||
recovery_point: "finished",
|
||||
response_code: 500,
|
||||
response_body: { message: "Unknown recovery point" },
|
||||
}
|
||||
)
|
||||
.update(idempotencyKey.idempotency_key, {
|
||||
recovery_point: "finished",
|
||||
response_code: 500,
|
||||
response_body: { message: "Unknown recovery point" },
|
||||
})
|
||||
})
|
||||
break
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { Request } from "express"
|
||||
import { TotalsService } from "../../../../services"
|
||||
import { Cart, LineItem } from "../../../../models"
|
||||
import { EntityManager } from "typeorm";
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
export const decorateLineItemsWithTotals = async (
|
||||
cart: Cart,
|
||||
req: Request,
|
||||
options: { force_taxes: boolean, transactionManager?: EntityManager } = { force_taxes: false }
|
||||
options: { force_taxes: boolean; transactionManager?: EntityManager } = {
|
||||
force_taxes: false,
|
||||
}
|
||||
): Promise<Cart> => {
|
||||
const totalsService: TotalsService = req.scope.resolve("totalsService")
|
||||
|
||||
@@ -15,10 +17,13 @@ export const decorateLineItemsWithTotals = async (
|
||||
const totalsServiceTx = totalsService.withTransaction(manager)
|
||||
return await Promise.all(
|
||||
cart.items.map(async (item: LineItem) => {
|
||||
const itemTotals = await totalsServiceTx
|
||||
.getLineItemTotals(item, cart, {
|
||||
const itemTotals = await totalsServiceTx.getLineItemTotals(
|
||||
item,
|
||||
cart,
|
||||
{
|
||||
include_tax: options.force_taxes || cart.region.automatic_taxes,
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
return Object.assign(item, itemTotals)
|
||||
})
|
||||
@@ -29,7 +34,8 @@ export const decorateLineItemsWithTotals = async (
|
||||
if (options.transactionManager) {
|
||||
items = await getItems(options.transactionManager)
|
||||
} else {
|
||||
const manager: EntityManager = options.transactionManager ?? req.scope.resolve("manager")
|
||||
const manager: EntityManager =
|
||||
options.transactionManager ?? req.scope.resolve("manager")
|
||||
items = await manager.transaction(async (transactionManager) => {
|
||||
return await getItems(transactionManager)
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { defaultStoreCartFields, defaultStoreCartRelations } from "."
|
||||
import { CartService } from "../../../../services"
|
||||
import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals"
|
||||
import { EntityManager } from "typeorm";
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
/**
|
||||
* @oas [delete] /carts/{id}/payment-sessions/{provider_id}
|
||||
@@ -54,7 +54,9 @@ export default async (req, res) => {
|
||||
|
||||
const manager: EntityManager = req.scope.resolve("manager")
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
return await cartService.withTransaction(transactionManager).deletePaymentSession(id, provider_id)
|
||||
return await cartService
|
||||
.withTransaction(transactionManager)
|
||||
.deletePaymentSession(id, provider_id)
|
||||
})
|
||||
|
||||
const cart = await cartService.retrieve(id, {
|
||||
|
||||
@@ -2,9 +2,12 @@ import { Router } from "express"
|
||||
import "reflect-metadata"
|
||||
import { Cart, Order, Swap } from "../../../../"
|
||||
import { DeleteResponse, EmptyQueryParams } from "../../../../types/common"
|
||||
import middlewares, { transformBody, transformQuery } from "../../../middlewares"
|
||||
import { StorePostCartsCartReq } from "./update-cart";
|
||||
import { StorePostCartReq } from "./create-cart";
|
||||
import middlewares, {
|
||||
transformBody,
|
||||
transformQuery,
|
||||
} from "../../../middlewares"
|
||||
import { StorePostCartsCartReq } from "./update-cart"
|
||||
import { StorePostCartReq } from "./create-cart"
|
||||
const route = Router()
|
||||
|
||||
export default (app, container) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CartService } from "../../../../services"
|
||||
import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals"
|
||||
import { EntityManager } from "typeorm";
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
/**
|
||||
* @oas [post] /carts/{id}/payment-sessions/{provider_id}/refresh
|
||||
@@ -53,7 +53,9 @@ export default async (req, res) => {
|
||||
|
||||
const manager: EntityManager = req.scope.resolve("manager")
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
return await cartService.withTransaction(transactionManager).refreshPaymentSession(id, provider_id)
|
||||
return await cartService
|
||||
.withTransaction(transactionManager)
|
||||
.refreshPaymentSession(id, provider_id)
|
||||
})
|
||||
const cart = await cartService.retrieve(id, {
|
||||
select: [
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { defaultStoreCartFields, defaultStoreCartRelations } from "."
|
||||
|
||||
import { CartService } from "../../../../services"
|
||||
import { EntityManager } from "typeorm";
|
||||
import { EntityManager } from "typeorm"
|
||||
import { IsString } from "class-validator"
|
||||
import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
@@ -68,7 +68,9 @@ export default async (req, res) => {
|
||||
|
||||
const manager: EntityManager = req.scope.resolve("manager")
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
return await cartService.withTransaction(transactionManager).setPaymentSession(id, validated.provider_id)
|
||||
return await cartService
|
||||
.withTransaction(transactionManager)
|
||||
.setPaymentSession(id, validated.provider_id)
|
||||
})
|
||||
|
||||
const cart = await cartService.retrieve(id, {
|
||||
|
||||
@@ -9,10 +9,10 @@ import { defaultStoreCartFields, defaultStoreCartRelations } from "."
|
||||
|
||||
import { AddressPayload } from "../../../../types/common"
|
||||
import { CartService } from "../../../../services"
|
||||
import { EntityManager } from "typeorm";
|
||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators";
|
||||
import { EntityManager } from "typeorm"
|
||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||
import { IsType } from "../../../../utils/validators/is-type"
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels";
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
import { Type } from "class-transformer"
|
||||
import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals"
|
||||
|
||||
@@ -139,12 +139,16 @@ export default async (req, res) => {
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
await cartService.withTransaction(transactionManager).update(id, validated)
|
||||
|
||||
const updated = await cartService.withTransaction(transactionManager).retrieve(id, {
|
||||
relations: ["payment_sessions", "shipping_methods"],
|
||||
})
|
||||
const updated = await cartService
|
||||
.withTransaction(transactionManager)
|
||||
.retrieve(id, {
|
||||
relations: ["payment_sessions", "shipping_methods"],
|
||||
})
|
||||
|
||||
if (updated.payment_sessions?.length && !validated.region_id) {
|
||||
await cartService.withTransaction(transactionManager).setPaymentSessions(id)
|
||||
await cartService
|
||||
.withTransaction(transactionManager)
|
||||
.setPaymentSessions(id)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -73,7 +73,9 @@ export default async (req, res) => {
|
||||
if (validated.quantity === 0) {
|
||||
await cartService.withTransaction(m).removeLineItem(id, line_id)
|
||||
} else {
|
||||
const cart = await cartService.withTransaction(m).retrieve(id, { relations: ["items"] })
|
||||
const cart = await cartService
|
||||
.withTransaction(m)
|
||||
.retrieve(id, { relations: ["items"] })
|
||||
|
||||
const existing = cart.items.find((i) => i.id === line_id)
|
||||
if (!existing) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { defaultStoreCartFields, defaultStoreCartRelations } from "."
|
||||
import { CartService } from "../../../../services"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals"
|
||||
import { EntityManager } from "typeorm";
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
/**
|
||||
* @oas [post] /carts/{id}/payment-sessions/{provider_id}
|
||||
@@ -22,7 +22,7 @@ import { EntityManager } from "typeorm";
|
||||
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||
* medusa.carts.updatePaymentSession(cart_id, 'manual', {
|
||||
* data: {
|
||||
*
|
||||
*
|
||||
* }
|
||||
* })
|
||||
* .then(({ cart }) => {
|
||||
@@ -70,8 +70,12 @@ export default async (req, res) => {
|
||||
|
||||
const manager: EntityManager = req.scope.resolve("manager")
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
await cartService.withTransaction(transactionManager).setPaymentSession(id, provider_id)
|
||||
await cartService.withTransaction(transactionManager).updatePaymentSession(id, validated.data)
|
||||
await cartService
|
||||
.withTransaction(transactionManager)
|
||||
.setPaymentSession(id, provider_id)
|
||||
await cartService
|
||||
.withTransaction(transactionManager)
|
||||
.updatePaymentSession(id, validated.data)
|
||||
})
|
||||
|
||||
const cart = await cartService.retrieve(id, {
|
||||
|
||||
@@ -238,6 +238,7 @@ export class StoreGetCustomersCustomerOrdersPaginationParams {
|
||||
expand?: string
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
export class StoreGetCustomersCustomerOrdersParams extends StoreGetCustomersCustomerOrdersPaginationParams {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
|
||||
@@ -95,4 +95,5 @@ export default async (req, res) => {
|
||||
res.json({ customer })
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
export class StorePostCustomersCustomerAddressesAddressReq extends AddressPayload {}
|
||||
|
||||
Reference in New Issue
Block a user