chore(medusa): Add transaction on mutation actions (2) (#1855)
**What** Wrap all actions that require the usage of an atomic phase into a transaction from the handler **Info** The following end points have been removed since that they rely on non existing stuff and can't be used and are not used admin - create-order admin - delete order metadata admin - set region metadata admin - remove region metadata Fixes CORE-358
This commit is contained in:
1 parent
d530ac23d6
commit
b603f7dc8f
64 files changed
+424
-297
No files matched your search
@@ -8,7 +8,6 @@ import {
|
|||||||
AdminPostRegionsRegionCountriesReq,
|
AdminPostRegionsRegionCountriesReq,
|
||||||
AdminPostRegionsRegionFulfillmentProvidersReq,
|
AdminPostRegionsRegionFulfillmentProvidersReq,
|
||||||
AdminPostRegionsRegionPaymentProvidersReq,
|
AdminPostRegionsRegionPaymentProvidersReq,
|
||||||
AdminPostRegionsRegionMetadata,
|
|
||||||
AdminGetRegionsRegionFulfillmentOptionsRes,
|
AdminGetRegionsRegionFulfillmentOptionsRes,
|
||||||
} from "@medusajs/medusa"
|
} from "@medusajs/medusa"
|
||||||
import qs from "qs"
|
import qs from "qs"
|
||||||
@@ -94,38 +93,6 @@ class AdminRegionsResource extends BaseResource {
|
|||||||
return this.client.request("GET", path, undefined, {}, customHeaders)
|
return this.client.request("GET", path, undefined, {}, customHeaders)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description adds metadata to a region
|
|
||||||
* @param id region id
|
|
||||||
* @param payload metadata
|
|
||||||
* @param customHeaders
|
|
||||||
* @returns updated region
|
|
||||||
*/
|
|
||||||
setMetadata(
|
|
||||||
id: string,
|
|
||||||
payload: AdminPostRegionsRegionMetadata,
|
|
||||||
customHeaders: Record<string, any> = {}
|
|
||||||
): ResponsePromise<AdminRegionsRes> {
|
|
||||||
const path = `/admin/regions/${id}/metadata`
|
|
||||||
return this.client.request("POST", path, payload, {}, customHeaders)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description delete a region's metadata key value pair
|
|
||||||
* @param id region id
|
|
||||||
* @param key metadata key
|
|
||||||
* @param customHeaders
|
|
||||||
* @returns updated region
|
|
||||||
*/
|
|
||||||
deleteMetadata(
|
|
||||||
id: string,
|
|
||||||
key: string,
|
|
||||||
customHeaders: Record<string, any> = {}
|
|
||||||
): ResponsePromise<AdminRegionsRes> {
|
|
||||||
const path = `/admin/regions/${id}/metadata/${key}`
|
|
||||||
return this.client.request("DELETE", path, undefined, {}, customHeaders)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description adds a country to the list of countries in a region
|
* @description adds a country to the list of countries in a region
|
||||||
* @param id region id
|
* @param id region id
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
AdminRegionsRes,
|
AdminRegionsRes,
|
||||||
AdminPostRegionsRegionReq,
|
AdminPostRegionsRegionReq,
|
||||||
AdminPostRegionsReq,
|
AdminPostRegionsReq,
|
||||||
AdminPostRegionsRegionMetadata,
|
|
||||||
AdminPostRegionsRegionCountriesReq,
|
AdminPostRegionsRegionCountriesReq,
|
||||||
AdminPostRegionsRegionFulfillmentProvidersReq,
|
AdminPostRegionsRegionFulfillmentProvidersReq,
|
||||||
AdminPostRegionsRegionPaymentProvidersReq,
|
AdminPostRegionsRegionPaymentProvidersReq,
|
||||||
@@ -69,37 +68,6 @@ export const useAdminDeleteRegion = (
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useAdminSetRegionMetadata = (
|
|
||||||
id: string,
|
|
||||||
options?: UseMutationOptions<
|
|
||||||
Response<AdminRegionsRes>,
|
|
||||||
Error,
|
|
||||||
AdminPostRegionsRegionMetadata
|
|
||||||
>
|
|
||||||
) => {
|
|
||||||
const { client } = useMedusa()
|
|
||||||
const queryClient = useQueryClient()
|
|
||||||
|
|
||||||
return useMutation(
|
|
||||||
(metadata: AdminPostRegionsRegionMetadata) =>
|
|
||||||
client.admin.regions.setMetadata(id, metadata),
|
|
||||||
buildOptions(queryClient, adminRegionKeys.detail(id), options)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useAdminDeleteRegionMetadata = (
|
|
||||||
id: string,
|
|
||||||
options?: UseMutationOptions<Response<AdminRegionsRes>, Error, string>
|
|
||||||
) => {
|
|
||||||
const { client } = useMedusa()
|
|
||||||
const queryClient = useQueryClient()
|
|
||||||
|
|
||||||
return useMutation(
|
|
||||||
(key: string) => client.admin.regions.deleteMetadata(id, key),
|
|
||||||
buildOptions(queryClient, adminRegionKeys.detail(id), options)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useAdminRegionAddCountry = (
|
export const useAdminRegionAddCountry = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ import {
|
|||||||
useAdminCreateRegion,
|
useAdminCreateRegion,
|
||||||
useAdminUpdateRegion,
|
useAdminUpdateRegion,
|
||||||
useAdminDeleteRegion,
|
useAdminDeleteRegion,
|
||||||
useAdminSetRegionMetadata,
|
|
||||||
useAdminDeleteRegionMetadata,
|
|
||||||
useAdminRegionAddFulfillmentProvider,
|
useAdminRegionAddFulfillmentProvider,
|
||||||
useAdminRegionDeleteFulfillmentProvider,
|
useAdminRegionDeleteFulfillmentProvider,
|
||||||
useAdminRegionAddPaymentProvider,
|
useAdminRegionAddPaymentProvider,
|
||||||
@@ -89,50 +87,6 @@ describe("useAdminDeleteRegion hook", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("useAdminSetRegionMetadata hook", () => {
|
|
||||||
test("updates a region's metadata", async () => {
|
|
||||||
const metadata = {
|
|
||||||
key: "some_key",
|
|
||||||
value: "some_value",
|
|
||||||
}
|
|
||||||
const id = fixtures.get("region").id
|
|
||||||
|
|
||||||
const { result, waitFor } = renderHook(
|
|
||||||
() => useAdminSetRegionMetadata(id),
|
|
||||||
{
|
|
||||||
wrapper: createWrapper(),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
result.current.mutate(metadata)
|
|
||||||
|
|
||||||
await waitFor(() => result.current.isSuccess)
|
|
||||||
|
|
||||||
expect(result.current.data.response.status).toEqual(200)
|
|
||||||
expect(result.current.data.region).toEqual(fixtures.get("region"))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("useAdminDeleteRegionMetadata hook", () => {
|
|
||||||
test("deletes a region's metadata", async () => {
|
|
||||||
const id = fixtures.get("region").id
|
|
||||||
|
|
||||||
const { result, waitFor } = renderHook(
|
|
||||||
() => useAdminDeleteRegionMetadata(id),
|
|
||||||
{
|
|
||||||
wrapper: createWrapper(),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
result.current.mutate("some_key")
|
|
||||||
|
|
||||||
await waitFor(() => result.current.isSuccess)
|
|
||||||
|
|
||||||
expect(result.current.data.response.status).toEqual(200)
|
|
||||||
expect(result.current.data.region).toEqual(fixtures.get("region"))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("useAdminRegionAddFulfillmentProvider hook", () => {
|
describe("useAdminRegionAddFulfillmentProvider hook", () => {
|
||||||
test("adds a fulfillment provider to a region", async () => {
|
test("adds a fulfillment provider to a region", async () => {
|
||||||
const payload = {
|
const payload = {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { PriceList } from "../../../.."
|
|||||||
import PriceListService from "../../../../services/price-list"
|
import PriceListService from "../../../../services/price-list"
|
||||||
import { AdminPriceListPricesUpdateReq } from "../../../../types/price-list"
|
import { AdminPriceListPricesUpdateReq } from "../../../../types/price-list"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /price-lists/{id}/prices/batch
|
* @oas [post] /price-lists/{id}/prices/batch
|
||||||
@@ -77,7 +78,12 @@ export default async (req, res) => {
|
|||||||
const priceListService: PriceListService =
|
const priceListService: PriceListService =
|
||||||
req.scope.resolve("priceListService")
|
req.scope.resolve("priceListService")
|
||||||
|
|
||||||
await priceListService.addPrices(id, validated.prices, validated.override)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await priceListService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.addPrices(id, validated.prices, validated.override)
|
||||||
|
})
|
||||||
|
|
||||||
const priceList = await priceListService.retrieve(id, {
|
const priceList = await priceListService.retrieve(id, {
|
||||||
select: defaultAdminPriceListFields as (keyof PriceList)[],
|
select: defaultAdminPriceListFields as (keyof PriceList)[],
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
PriceListType,
|
PriceListType,
|
||||||
} from "../../../../types/price-list"
|
} from "../../../../types/price-list"
|
||||||
import { Request } from "express"
|
import { Request } from "express"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /price_lists
|
* @oas [post] /price_lists
|
||||||
@@ -90,9 +91,12 @@ export default async (req: Request, res) => {
|
|||||||
const priceListService: PriceListService =
|
const priceListService: PriceListService =
|
||||||
req.scope.resolve("priceListService")
|
req.scope.resolve("priceListService")
|
||||||
|
|
||||||
const priceList = await priceListService.create(
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
req.validatedBody as CreatePriceListInput
|
const priceList = await manager.transaction(async (transactionManager) => {
|
||||||
)
|
return await priceListService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.create(req.validatedBody as CreatePriceListInput)
|
||||||
|
})
|
||||||
|
|
||||||
res.json({ price_list: priceList })
|
res.json({ price_list: priceList })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import PriceListService from "../../../../services/price-list"
|
import PriceListService from "../../../../services/price-list"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /price-lists/{id}
|
* @oas [delete] /price-lists/{id}
|
||||||
@@ -31,7 +32,10 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const priceListService: PriceListService =
|
const priceListService: PriceListService =
|
||||||
req.scope.resolve("priceListService")
|
req.scope.resolve("priceListService")
|
||||||
await priceListService.delete(id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await priceListService.withTransaction(transactionManager).delete(id)
|
||||||
|
})
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
id,
|
id,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ArrayNotEmpty, IsString } from "class-validator"
|
import { ArrayNotEmpty, IsString } from "class-validator"
|
||||||
import PriceListService from "../../../../services/price-list"
|
import PriceListService from "../../../../services/price-list"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /price-lists/{id}/prices/batch
|
* @oas [delete] /price-lists/{id}/prices/batch
|
||||||
@@ -51,7 +52,12 @@ export default async (req, res) => {
|
|||||||
const priceListService: PriceListService =
|
const priceListService: PriceListService =
|
||||||
req.scope.resolve("priceListService")
|
req.scope.resolve("priceListService")
|
||||||
|
|
||||||
await priceListService.deletePrices(id, validated.price_ids)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await priceListService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.deletePrices(id, validated.price_ids)
|
||||||
|
})
|
||||||
|
|
||||||
res.json({ ids: validated.price_ids, object: "money-amount", deleted: true })
|
res.json({ ids: validated.price_ids, object: "money-amount", deleted: true })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import PriceListService from "../../../../services/price-list"
|
import PriceListService from "../../../../services/price-list"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /price-lists/{id}/products/{product_id}/prices
|
* @oas [delete] /price-lists/{id}/products/{product_id}/prices
|
||||||
@@ -36,9 +37,14 @@ export default async (req, res) => {
|
|||||||
const priceListService: PriceListService =
|
const priceListService: PriceListService =
|
||||||
req.scope.resolve("priceListService")
|
req.scope.resolve("priceListService")
|
||||||
|
|
||||||
const [deletedPriceIds] = await priceListService.deleteProductPrices(id, [
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
product_id,
|
const [deletedPriceIds] = await manager.transaction(
|
||||||
])
|
async (transactionManager) => {
|
||||||
|
return await priceListService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.deleteProductPrices(id, [product_id])
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return res.json({
|
return res.json({
|
||||||
ids: deletedPriceIds,
|
ids: deletedPriceIds,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import PriceListService from "../../../../services/price-list"
|
import PriceListService from "../../../../services/price-list"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /price-lists/{id}/variants/{variant_id}/prices
|
* @oas [delete] /price-lists/{id}/variants/{variant_id}/prices
|
||||||
@@ -36,9 +37,14 @@ export default async (req, res) => {
|
|||||||
const priceListService: PriceListService =
|
const priceListService: PriceListService =
|
||||||
req.scope.resolve("priceListService")
|
req.scope.resolve("priceListService")
|
||||||
|
|
||||||
const [deletedPriceIds] = await priceListService.deleteVariantPrices(id, [
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
variant_id,
|
const [deletedPriceIds] = await manager.transaction(
|
||||||
])
|
async (transactionManager) => {
|
||||||
|
return await priceListService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.deleteVariantPrices(id, [variant_id])
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return res.json({
|
return res.json({
|
||||||
ids: deletedPriceIds,
|
ids: deletedPriceIds,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
PriceListType,
|
PriceListType,
|
||||||
} from "../../../../types/price-list"
|
} from "../../../../types/price-list"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /price_lists/{id}
|
* @oas [post] /price_lists/{id}
|
||||||
@@ -103,7 +104,12 @@ export default async (req, res) => {
|
|||||||
const priceListService: PriceListService =
|
const priceListService: PriceListService =
|
||||||
req.scope.resolve("priceListService")
|
req.scope.resolve("priceListService")
|
||||||
|
|
||||||
await priceListService.update(id, validated)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await priceListService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.update(id, validated)
|
||||||
|
})
|
||||||
|
|
||||||
const priceList = await priceListService.retrieve(id, {
|
const priceList = await priceListService.retrieve(id, {
|
||||||
select: defaultAdminPriceListFields as (keyof PriceList)[],
|
select: defaultAdminPriceListFields as (keyof PriceList)[],
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { IsString } from "class-validator"
|
|||||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||||
import { ProductService, PricingService } from "../../../../services"
|
import { ProductService, PricingService } from "../../../../services"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /products/{id}/options
|
* @oas [post] /products/{id}/options
|
||||||
@@ -44,7 +45,13 @@ export default async (req, res) => {
|
|||||||
const productService: ProductService = req.scope.resolve("productService")
|
const productService: ProductService = req.scope.resolve("productService")
|
||||||
const pricingService: PricingService = req.scope.resolve("pricingService")
|
const pricingService: PricingService = req.scope.resolve("pricingService")
|
||||||
|
|
||||||
await productService.addOption(id, validated.title)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await productService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.addOption(id, validated.title)
|
||||||
|
})
|
||||||
|
|
||||||
const rawProduct = await productService.retrieve(id, {
|
const rawProduct = await productService.retrieve(id, {
|
||||||
select: defaultAdminProductFields,
|
select: defaultAdminProductFields,
|
||||||
relations: defaultAdminProductRelations,
|
relations: defaultAdminProductRelations,
|
||||||
|
|||||||
@@ -24,8 +24,11 @@ import {
|
|||||||
ProductTagReq,
|
ProductTagReq,
|
||||||
ProductTypeReq,
|
ProductTypeReq,
|
||||||
} from "../../../../types/product"
|
} from "../../../../types/product"
|
||||||
import { ProductVariantPricesCreateReq } from "../../../../types/product-variant"
|
|
||||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||||
|
import {
|
||||||
|
CreateProductVariantInput,
|
||||||
|
ProductVariantPricesCreateReq,
|
||||||
|
} from "../../../../types/product-variant"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -237,8 +240,7 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const entityManager: EntityManager = req.scope.resolve("manager")
|
const entityManager: EntityManager = req.scope.resolve("manager")
|
||||||
|
|
||||||
let newProduct
|
const newProduct = await entityManager.transaction(async (manager) => {
|
||||||
await entityManager.transaction(async (manager) => {
|
|
||||||
const { variants } = validated
|
const { variants } = validated
|
||||||
delete validated.variants
|
delete validated.variants
|
||||||
|
|
||||||
@@ -249,12 +251,16 @@ export default async (req, res) => {
|
|||||||
let shippingProfile
|
let shippingProfile
|
||||||
// Get default shipping profile
|
// Get default shipping profile
|
||||||
if (validated.is_giftcard) {
|
if (validated.is_giftcard) {
|
||||||
shippingProfile = await shippingProfileService.retrieveGiftCardDefault()
|
shippingProfile = await shippingProfileService
|
||||||
|
.withTransaction(manager)
|
||||||
|
.retrieveGiftCardDefault()
|
||||||
} else {
|
} else {
|
||||||
shippingProfile = await shippingProfileService.retrieveDefault()
|
shippingProfile = await shippingProfileService
|
||||||
|
.withTransaction(manager)
|
||||||
|
.retrieveDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
newProduct = await productService
|
const newProduct = await productService
|
||||||
.withTransaction(manager)
|
.withTransaction(manager)
|
||||||
.create({ ...validated, profile_id: shippingProfile.id })
|
.create({ ...validated, profile_id: shippingProfile.id })
|
||||||
|
|
||||||
@@ -265,7 +271,7 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const optionIds =
|
const optionIds =
|
||||||
validated?.options?.map(
|
validated?.options?.map(
|
||||||
(o) => newProduct.options.find((newO) => newO.title === o.title).id
|
(o) => newProduct.options.find((newO) => newO.title === o.title)?.id
|
||||||
) || []
|
) || []
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
@@ -281,10 +287,12 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
await productVariantService
|
await productVariantService
|
||||||
.withTransaction(manager)
|
.withTransaction(manager)
|
||||||
.create(newProduct.id, variant)
|
.create(newProduct.id, variant as CreateProductVariantInput)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return newProduct
|
||||||
})
|
})
|
||||||
|
|
||||||
const rawProduct = await productService.retrieve(newProduct.id, {
|
const rawProduct = await productService.retrieve(newProduct.id, {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
|||||||
import { ProductService, ProductVariantService } from "../../../../services"
|
import { ProductService, ProductVariantService } from "../../../../services"
|
||||||
import { ProductVariantPricesCreateReq } from "../../../../types/product-variant"
|
import { ProductVariantPricesCreateReq } from "../../../../types/product-variant"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /products/{id}/variants
|
* @oas [post] /products/{id}/variants
|
||||||
@@ -135,7 +136,12 @@ export default async (req, res) => {
|
|||||||
)
|
)
|
||||||
const productService: ProductService = req.scope.resolve("productService")
|
const productService: ProductService = req.scope.resolve("productService")
|
||||||
|
|
||||||
await productVariantService.create(id, validated)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await productVariantService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.create(id, validated)
|
||||||
|
})
|
||||||
|
|
||||||
const product = await productService.retrieve(id, {
|
const product = await productService.retrieve(id, {
|
||||||
select: defaultAdminProductFields,
|
select: defaultAdminProductFields,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||||
import { ProductService } from "../../../../services"
|
import { ProductService } from "../../../../services"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /products/{id}/options/{option_id}
|
* @oas [delete] /products/{id}/options/{option_id}
|
||||||
@@ -35,7 +36,12 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const productService: ProductService = req.scope.resolve("productService")
|
const productService: ProductService = req.scope.resolve("productService")
|
||||||
|
|
||||||
await productService.deleteOption(id, option_id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await productService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.deleteOption(id, option_id)
|
||||||
|
})
|
||||||
|
|
||||||
const data = await productService.retrieve(id, {
|
const data = await productService.retrieve(id, {
|
||||||
select: defaultAdminProductFields,
|
select: defaultAdminProductFields,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { ProductService } from "../../../../services"
|
import { ProductService } from "../../../../services"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /products/{id}
|
* @oas [delete] /products/{id}
|
||||||
@@ -30,7 +31,11 @@ export default async (req, res) => {
|
|||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
const productService: ProductService = req.scope.resolve("productService")
|
const productService: ProductService = req.scope.resolve("productService")
|
||||||
await productService.delete(id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await productService.withTransaction(transactionManager).delete(id)
|
||||||
|
})
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
id,
|
id,
|
||||||
object: "product",
|
object: "product",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
PricingService,
|
PricingService,
|
||||||
ProductVariantService,
|
ProductVariantService,
|
||||||
} from "../../../../services"
|
} from "../../../../services"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /products/{id}/variants/{variant_id}
|
* @oas [delete] /products/{id}/variants/{variant_id}
|
||||||
@@ -41,12 +42,18 @@ export default async (req, res) => {
|
|||||||
const productService: ProductService = req.scope.resolve("productService")
|
const productService: ProductService = req.scope.resolve("productService")
|
||||||
const pricingService: PricingService = req.scope.resolve("pricingService")
|
const pricingService: PricingService = req.scope.resolve("pricingService")
|
||||||
|
|
||||||
await productVariantService.delete(variant_id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
await productVariantService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.delete(variant_id)
|
||||||
|
})
|
||||||
|
|
||||||
const data = await productService.retrieve(id, {
|
const data = await productService.retrieve(id, {
|
||||||
select: defaultAdminProductFields,
|
select: defaultAdminProductFields,
|
||||||
relations: defaultAdminProductRelations,
|
relations: defaultAdminProductRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
const [product] = await pricingService.setProductPrices([data])
|
const [product] = await pricingService.setProductPrices([data])
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { IsString } from "class-validator"
|
import { IsString } from "class-validator"
|
||||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /products/{id}/metadata
|
* @oas [post] /products/{id}/metadata
|
||||||
@@ -45,9 +46,12 @@ export default async (req, res) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const productService = req.scope.resolve("productService")
|
const productService = req.scope.resolve("productService")
|
||||||
await productService.update(id, {
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await productService.withTransaction(transactionManager).update(id, {
|
||||||
metadata: { [validated.key]: validated.value },
|
metadata: { [validated.key]: validated.value },
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const product = await productService.retrieve(id, {
|
const product = await productService.retrieve(id, {
|
||||||
select: defaultAdminProductFields,
|
select: defaultAdminProductFields,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { IsString } from "class-validator"
|
|||||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||||
import { ProductService } from "../../../../services"
|
import { ProductService } from "../../../../services"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /products/{id}/options/{option_id}
|
* @oas [post] /products/{id}/options/{option_id}
|
||||||
@@ -44,7 +45,12 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const productService: ProductService = req.scope.resolve("productService")
|
const productService: ProductService = req.scope.resolve("productService")
|
||||||
|
|
||||||
await productService.updateOption(id, option_id, validated)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await productService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.updateOption(id, option_id, validated)
|
||||||
|
})
|
||||||
|
|
||||||
const product = await productService.retrieve(id, {
|
const product = await productService.retrieve(id, {
|
||||||
select: defaultAdminProductFields,
|
select: defaultAdminProductFields,
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import {
|
|||||||
import { ProductVariantPricesUpdateReq } from "../../../../types/product-variant"
|
import { ProductVariantPricesUpdateReq } from "../../../../types/product-variant"
|
||||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /products/{id}
|
* @oas [post] /products/{id}
|
||||||
@@ -224,12 +225,18 @@ export default async (req, res) => {
|
|||||||
const productService: ProductService = req.scope.resolve("productService")
|
const productService: ProductService = req.scope.resolve("productService")
|
||||||
const pricingService: PricingService = req.scope.resolve("pricingService")
|
const pricingService: PricingService = req.scope.resolve("pricingService")
|
||||||
|
|
||||||
await productService.update(id, validated)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
await productService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.update(id, validated)
|
||||||
|
})
|
||||||
|
|
||||||
const rawProduct = await productService.retrieve(id, {
|
const rawProduct = await productService.retrieve(id, {
|
||||||
select: defaultAdminProductFields,
|
select: defaultAdminProductFields,
|
||||||
relations: defaultAdminProductRelations,
|
relations: defaultAdminProductRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
const [product] = await pricingService.setProductPrices([rawProduct])
|
const [product] = await pricingService.setProductPrices([rawProduct])
|
||||||
|
|
||||||
res.json({ product })
|
res.json({ product })
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
import { PriceSelectionParams } from "../../../../types/price-selection"
|
import { PriceSelectionParams } from "../../../../types/price-selection"
|
||||||
import { ProductVariantPricesUpdateReq } from "../../../../types/product-variant"
|
import { ProductVariantPricesUpdateReq } from "../../../../types/product-variant"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /products/{id}/variants/{variant_id}
|
* @oas [post] /products/{id}/variants/{variant_id}
|
||||||
@@ -143,10 +144,15 @@ export default async (req, res) => {
|
|||||||
"productVariantService"
|
"productVariantService"
|
||||||
)
|
)
|
||||||
|
|
||||||
await productVariantService.update(variant_id, {
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
await productVariantService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.update(variant_id, {
|
||||||
product_id: id,
|
product_id: id,
|
||||||
...validated,
|
...validated,
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const rawProduct = await productService.retrieve(id, {
|
const rawProduct = await productService.retrieve(id, {
|
||||||
select: defaultAdminProductFields,
|
select: defaultAdminProductFields,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { defaultAdminRegionRelations, defaultAdminRegionFields } from "."
|
|||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
import { Region } from "../../../.."
|
import { Region } from "../../../.."
|
||||||
import RegionService from "../../../../services/region"
|
import RegionService from "../../../../services/region"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
/**
|
/**
|
||||||
* @oas [post] /regions/{id}/countries
|
* @oas [post] /regions/{id}/countries
|
||||||
* operationId: "PostRegionsRegionCountries"
|
* operationId: "PostRegionsRegionCountries"
|
||||||
@@ -41,7 +42,12 @@ export default async (req, res) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const regionService: RegionService = req.scope.resolve("regionService")
|
const regionService: RegionService = req.scope.resolve("regionService")
|
||||||
await regionService.addCountry(region_id, validated.country_code)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await regionService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.addCountry(region_id, validated.country_code)
|
||||||
|
})
|
||||||
|
|
||||||
const region: Region = await regionService.retrieve(region_id, {
|
const region: Region = await regionService.retrieve(region_id, {
|
||||||
select: defaultAdminRegionFields,
|
select: defaultAdminRegionFields,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { defaultAdminRegionRelations, defaultAdminRegionFields } from "."
|
|||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
import { Region } from "../../../.."
|
import { Region } from "../../../.."
|
||||||
import RegionService from "../../../../services/region"
|
import RegionService from "../../../../services/region"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
/**
|
/**
|
||||||
* @oas [post] /regions/{id}/fulfillment-providers
|
* @oas [post] /regions/{id}/fulfillment-providers
|
||||||
* operationId: "PostRegionsRegionFulfillmentProviders"
|
* operationId: "PostRegionsRegionFulfillmentProviders"
|
||||||
@@ -41,7 +42,12 @@ export default async (req, res) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const regionService: RegionService = req.scope.resolve("regionService")
|
const regionService: RegionService = req.scope.resolve("regionService")
|
||||||
await regionService.addFulfillmentProvider(region_id, validated.provider_id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await regionService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.addFulfillmentProvider(region_id, validated.provider_id)
|
||||||
|
})
|
||||||
|
|
||||||
const region: Region = await regionService.retrieve(region_id, {
|
const region: Region = await regionService.retrieve(region_id, {
|
||||||
select: defaultAdminRegionFields,
|
select: defaultAdminRegionFields,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { defaultAdminRegionRelations, defaultAdminRegionFields } from "."
|
|||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
import { Region } from "../../../.."
|
import { Region } from "../../../.."
|
||||||
import RegionService from "../../../../services/region"
|
import RegionService from "../../../../services/region"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /regions/{id}/payment-providers
|
* @oas [post] /regions/{id}/payment-providers
|
||||||
@@ -42,7 +43,12 @@ export default async (req, res) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const regionService: RegionService = req.scope.resolve("regionService")
|
const regionService: RegionService = req.scope.resolve("regionService")
|
||||||
await regionService.addPaymentProvider(region_id, validated.provider_id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await regionService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.addPaymentProvider(region_id, validated.provider_id)
|
||||||
|
})
|
||||||
|
|
||||||
const region: Region = await regionService.retrieve(region_id, {
|
const region: Region = await regionService.retrieve(region_id, {
|
||||||
select: defaultAdminRegionFields,
|
select: defaultAdminRegionFields,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { defaultAdminRegionRelations, defaultAdminRegionFields } from "."
|
|||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
import { Region } from "../../../.."
|
import { Region } from "../../../.."
|
||||||
import RegionService from "../../../../services/region"
|
import RegionService from "../../../../services/region"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
/**
|
/**
|
||||||
* @oas [post] /regions
|
* @oas [post] /regions
|
||||||
* operationId: "PostRegions"
|
* operationId: "PostRegions"
|
||||||
@@ -61,7 +62,14 @@ export default async (req, res) => {
|
|||||||
const validated = await validator(AdminPostRegionsReq, req.body)
|
const validated = await validator(AdminPostRegionsReq, req.body)
|
||||||
|
|
||||||
const regionService: RegionService = req.scope.resolve("regionService")
|
const regionService: RegionService = req.scope.resolve("regionService")
|
||||||
const result: Region = await regionService.create(validated)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
const result: Region = await manager.transaction(
|
||||||
|
async (transactionManager) => {
|
||||||
|
return await regionService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.create(validated)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const region: Region = await regionService.retrieve(result.id, {
|
const region: Region = await regionService.retrieve(result.id, {
|
||||||
select: defaultAdminRegionFields,
|
select: defaultAdminRegionFields,
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
import { defaultAdminRegionRelations, defaultAdminRegionFields } from "."
|
|
||||||
import { Region } from "../../../.."
|
|
||||||
import RegionService from "../../../../services/region"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @oas [delete] /regions/{id}/metadata/{key}
|
|
||||||
* operationId: "DeleteRegionsRegionMetadataKey"
|
|
||||||
* summary: "Delete Metadata"
|
|
||||||
* description: "Deletes a metadata key."
|
|
||||||
* x-authenticated: true
|
|
||||||
* parameters:
|
|
||||||
* - (path) id=* {string} The id of the Region.
|
|
||||||
* - (path) key=* {string} The metadata key.
|
|
||||||
* tags:
|
|
||||||
* - Region
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: OK
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* properties:
|
|
||||||
* region:
|
|
||||||
* $ref: "#/components/schemas/region"
|
|
||||||
*/
|
|
||||||
export default async (req, res) => {
|
|
||||||
const { id, key } = req.params
|
|
||||||
|
|
||||||
const regionService: RegionService = req.scope.resolve("regionService")
|
|
||||||
await regionService.deleteMetadata(id, key)
|
|
||||||
|
|
||||||
const region: Region = await regionService.retrieve(id, {
|
|
||||||
select: defaultAdminRegionFields,
|
|
||||||
relations: defaultAdminRegionRelations,
|
|
||||||
})
|
|
||||||
|
|
||||||
res.status(200).json({ region })
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import RegionService from "../../../../services/region"
|
import RegionService from "../../../../services/region"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /regions/{id}
|
* @oas [delete] /regions/{id}
|
||||||
@@ -31,7 +32,12 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const regionService: RegionService = req.scope.resolve("regionService")
|
const regionService: RegionService = req.scope.resolve("regionService")
|
||||||
|
|
||||||
await regionService.delete(region_id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await regionService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.delete(region_id)
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
id: region_id,
|
id: region_id,
|
||||||
|
|||||||
@@ -55,22 +55,6 @@ export default (app) => {
|
|||||||
middlewares.wrap(require("./remove-fulfillment-provider").default)
|
middlewares.wrap(require("./remove-fulfillment-provider").default)
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
|
||||||
* Set metadata key / value pair.
|
|
||||||
*/
|
|
||||||
route.post(
|
|
||||||
"/:id/metadata",
|
|
||||||
middlewares.wrap(require("./set-metadata").default)
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete metadata key / value pair.
|
|
||||||
*/
|
|
||||||
route.delete(
|
|
||||||
"/:id/metadata/:key",
|
|
||||||
middlewares.wrap(require("./delete-metadata").default)
|
|
||||||
)
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,4 +104,3 @@ export * from "./create-region"
|
|||||||
export * from "./add-country"
|
export * from "./add-country"
|
||||||
export * from "./add-payment-provider"
|
export * from "./add-payment-provider"
|
||||||
export * from "./add-fulfillment-provider"
|
export * from "./add-fulfillment-provider"
|
||||||
export * from "./set-metadata"
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import RegionService from "../../../../services/region"
|
import RegionService from "../../../../services/region"
|
||||||
import { defaultAdminRegionRelations, defaultAdminRegionFields } from "."
|
import { defaultAdminRegionRelations, defaultAdminRegionFields } from "."
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /regions/{id}/countries/{country_code}
|
* @oas [delete] /regions/{id}/countries/{country_code}
|
||||||
@@ -26,7 +27,12 @@ export default async (req, res) => {
|
|||||||
const { region_id, country_code } = req.params
|
const { region_id, country_code } = req.params
|
||||||
|
|
||||||
const regionService: RegionService = req.scope.resolve("regionService")
|
const regionService: RegionService = req.scope.resolve("regionService")
|
||||||
await regionService.removeCountry(region_id, country_code)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await regionService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.removeCountry(region_id, country_code)
|
||||||
|
})
|
||||||
|
|
||||||
const region = await regionService.retrieve(region_id, {
|
const region = await regionService.retrieve(region_id, {
|
||||||
select: defaultAdminRegionFields,
|
select: defaultAdminRegionFields,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import RegionService from "../../../../services/region"
|
import RegionService from "../../../../services/region"
|
||||||
import { defaultAdminRegionRelations, defaultAdminRegionFields } from "."
|
import { defaultAdminRegionRelations, defaultAdminRegionFields } from "."
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /regions/{id}/fulfillment-providers/{provider_id}
|
* @oas [delete] /regions/{id}/fulfillment-providers/{provider_id}
|
||||||
@@ -26,7 +27,12 @@ export default async (req, res) => {
|
|||||||
const { region_id, provider_id } = req.params
|
const { region_id, provider_id } = req.params
|
||||||
const regionService: RegionService = req.scope.resolve("regionService")
|
const regionService: RegionService = req.scope.resolve("regionService")
|
||||||
|
|
||||||
await regionService.removeFulfillmentProvider(region_id, provider_id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await regionService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.removeFulfillmentProvider(region_id, provider_id)
|
||||||
|
})
|
||||||
|
|
||||||
const region = await regionService.retrieve(region_id, {
|
const region = await regionService.retrieve(region_id, {
|
||||||
select: defaultAdminRegionFields,
|
select: defaultAdminRegionFields,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import RegionService from "../../../../services/region"
|
import RegionService from "../../../../services/region"
|
||||||
import { defaultAdminRegionRelations, defaultAdminRegionFields } from "."
|
import { defaultAdminRegionRelations, defaultAdminRegionFields } from "."
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /regions/{id}/payment-providers/{provider_id}
|
* @oas [delete] /regions/{id}/payment-providers/{provider_id}
|
||||||
@@ -26,7 +27,12 @@ export default async (req, res) => {
|
|||||||
const { region_id, provider_id } = req.params
|
const { region_id, provider_id } = req.params
|
||||||
|
|
||||||
const regionService: RegionService = req.scope.resolve("regionService")
|
const regionService: RegionService = req.scope.resolve("regionService")
|
||||||
await regionService.removePaymentProvider(region_id, provider_id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await regionService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.removePaymentProvider(region_id, provider_id)
|
||||||
|
})
|
||||||
|
|
||||||
const region = await regionService.retrieve(region_id, {
|
const region = await regionService.retrieve(region_id, {
|
||||||
select: defaultAdminRegionFields,
|
select: defaultAdminRegionFields,
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
import { IsString } from "class-validator"
|
|
||||||
import { validator } from "../../../../utils/validator"
|
|
||||||
import RegionService from "../../../../services/region"
|
|
||||||
import { defaultAdminRegionFields, defaultAdminRegionRelations } from "."
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @oas [post] /regions/{id}/metadata
|
|
||||||
* operationId: "PostRegionsRegionMetadata"
|
|
||||||
* summary: "Set the metadata of a Region"
|
|
||||||
* description: "Sets the metadata of a Region"
|
|
||||||
* x-authenticated: true
|
|
||||||
* parameters:
|
|
||||||
* - (path) id=* {string} The id of the Region.
|
|
||||||
* - (body) key=* {string} Key for the metadata value.
|
|
||||||
* - (body) value=* {string} The value that the key relates to.
|
|
||||||
* tags:
|
|
||||||
* - Region
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: OK
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* properties:
|
|
||||||
* region:
|
|
||||||
* $ref: "#/components/schemas/region"
|
|
||||||
*/
|
|
||||||
export default async (req, res) => {
|
|
||||||
const { id } = req.params
|
|
||||||
|
|
||||||
const validated = await validator(AdminPostRegionsRegionMetadata, req.body)
|
|
||||||
|
|
||||||
const regionService: RegionService = req.scope.resolve("regionService")
|
|
||||||
await regionService.setMetadata(id, validated.key, validated.value)
|
|
||||||
|
|
||||||
const region = await regionService.retrieve(id, {
|
|
||||||
select: defaultAdminRegionFields,
|
|
||||||
relations: defaultAdminRegionRelations,
|
|
||||||
})
|
|
||||||
|
|
||||||
res.status(200).json({ region })
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AdminPostRegionsRegionMetadata {
|
|
||||||
@IsString()
|
|
||||||
key: string
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
value: string
|
|
||||||
}
|
|
||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
import { defaultAdminRegionRelations, defaultAdminRegionFields } from "."
|
import { defaultAdminRegionRelations, defaultAdminRegionFields } from "."
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
import RegionService from "../../../../services/region"
|
import RegionService from "../../../../services/region"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /regions/{id}
|
* @oas [post] /regions/{id}
|
||||||
@@ -75,7 +76,13 @@ export default async (req, res) => {
|
|||||||
const validated = await validator(AdminPostRegionsRegionReq, req.body)
|
const validated = await validator(AdminPostRegionsRegionReq, req.body)
|
||||||
|
|
||||||
const regionService: RegionService = req.scope.resolve("regionService")
|
const regionService: RegionService = req.scope.resolve("regionService")
|
||||||
await regionService.update(region_id, validated)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await regionService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.update(region_id, validated)
|
||||||
|
})
|
||||||
|
|
||||||
const region = await regionService.retrieve(region_id, {
|
const region = await regionService.retrieve(region_id, {
|
||||||
select: defaultAdminRegionFields,
|
select: defaultAdminRegionFields,
|
||||||
relations: defaultAdminRegionRelations,
|
relations: defaultAdminRegionRelations,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
} from "."
|
} from "."
|
||||||
import { ReturnReasonService } from "../../../../services"
|
import { ReturnReasonService } from "../../../../services"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /return-reasons
|
* @oas [post] /return-reasons
|
||||||
@@ -53,7 +54,12 @@ export default async (req, res) => {
|
|||||||
const returnReasonService: ReturnReasonService = req.scope.resolve(
|
const returnReasonService: ReturnReasonService = req.scope.resolve(
|
||||||
"returnReasonService"
|
"returnReasonService"
|
||||||
)
|
)
|
||||||
const result = await returnReasonService.create(validated)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
const result = await manager.transaction(async (transactionManager) => {
|
||||||
|
return await returnReasonService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.create(validated)
|
||||||
|
})
|
||||||
|
|
||||||
const reason = await returnReasonService.retrieve(result.id, {
|
const reason = await returnReasonService.retrieve(result.id, {
|
||||||
select: defaultAdminReturnReasonsFields,
|
select: defaultAdminReturnReasonsFields,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { ReturnReasonService } from "../../../../services"
|
import { ReturnReasonService } from "../../../../services"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /return-reasons/{id}
|
* @oas [delete] /return-reasons/{id}
|
||||||
@@ -32,7 +33,12 @@ export default async (req, res) => {
|
|||||||
const returnReasonService: ReturnReasonService = req.scope.resolve(
|
const returnReasonService: ReturnReasonService = req.scope.resolve(
|
||||||
"returnReasonService"
|
"returnReasonService"
|
||||||
)
|
)
|
||||||
await returnReasonService.delete(id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await returnReasonService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.delete(id)
|
||||||
|
})
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
id: id,
|
id: id,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
} from "."
|
} from "."
|
||||||
import { ReturnReasonService } from "../../../../services"
|
import { ReturnReasonService } from "../../../../services"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /return-reasons/{id}
|
* @oas [post] /return-reasons/{id}
|
||||||
@@ -49,7 +50,12 @@ export default async (req, res) => {
|
|||||||
"returnReasonService"
|
"returnReasonService"
|
||||||
)
|
)
|
||||||
|
|
||||||
await returnReasonService.update(id, validated)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await returnReasonService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.update(id, validated)
|
||||||
|
})
|
||||||
|
|
||||||
const reason = await returnReasonService.retrieve(id, {
|
const reason = await returnReasonService.retrieve(id, {
|
||||||
select: defaultAdminReturnReasonsFields,
|
select: defaultAdminReturnReasonsFields,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
defaultAdminOrdersFields,
|
defaultAdminOrdersFields,
|
||||||
defaultAdminOrdersRelations,
|
defaultAdminOrdersRelations,
|
||||||
} from "../orders"
|
} from "../orders"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /returns/{id}/cancel
|
* @oas [post] /returns/{id}/cancel
|
||||||
@@ -29,7 +30,10 @@ export default async (req, res) => {
|
|||||||
const returnService: ReturnService = req.scope.resolve("returnService")
|
const returnService: ReturnService = req.scope.resolve("returnService")
|
||||||
const orderService: OrderService = req.scope.resolve("orderService")
|
const orderService: OrderService = req.scope.resolve("orderService")
|
||||||
|
|
||||||
let result = await returnService.cancel(id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
let result = await manager.transaction(async (transactionManager) => {
|
||||||
|
return await returnService.withTransaction(transactionManager).cancel(id)
|
||||||
|
})
|
||||||
|
|
||||||
if (result.swap_id) {
|
if (result.swap_id) {
|
||||||
const swapService = req.scope.resolve("swapService")
|
const swapService = req.scope.resolve("swapService")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { SalesChannelService } from "../../../../services"
|
|||||||
import { IsArray, ValidateNested } from "class-validator"
|
import { IsArray, ValidateNested } from "class-validator"
|
||||||
import { Type } from "class-transformer"
|
import { Type } from "class-transformer"
|
||||||
import { ProductBatchSalesChannel } from "../../../../types/sales-channels"
|
import { ProductBatchSalesChannel } from "../../../../types/sales-channels"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /sales-channels/{id}/products/batch
|
* @oas [post] /sales-channels/{id}/products/batch
|
||||||
@@ -26,18 +27,25 @@ import { ProductBatchSalesChannel } from "../../../../types/sales-channels"
|
|||||||
* $ref: "#/components/schemas/sales_channel"
|
* $ref: "#/components/schemas/sales_channel"
|
||||||
*/
|
*/
|
||||||
export default async (req: Request, res: Response): Promise<void> => {
|
export default async (req: Request, res: Response): Promise<void> => {
|
||||||
|
const validatedBody =
|
||||||
|
req.validatedBody as AdminPostSalesChannelsChannelProductsBatchReq
|
||||||
|
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
const salesChannelService: SalesChannelService = req.scope.resolve(
|
const salesChannelService: SalesChannelService = req.scope.resolve(
|
||||||
"salesChannelService"
|
"salesChannelService"
|
||||||
)
|
)
|
||||||
|
|
||||||
const validatedBody =
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
req.validatedBody as AdminPostSalesChannelsChannelProductsBatchReq
|
const salesChannel = await manager.transaction(async (transactionManager) => {
|
||||||
const salesChannel = await salesChannelService.addProducts(
|
return await salesChannelService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.addProducts(
|
||||||
id,
|
id,
|
||||||
validatedBody.product_ids.map((p) => p.id)
|
validatedBody.product_ids.map((p) => p.id)
|
||||||
)
|
)
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({ sales_channel: salesChannel })
|
res.status(200).json({ sales_channel: salesChannel })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { IsBoolean, IsOptional, IsString } from "class-validator"
|
|||||||
|
|
||||||
import SalesChannelService from "../../../../services/sales-channel"
|
import SalesChannelService from "../../../../services/sales-channel"
|
||||||
import { CreateSalesChannelInput } from "../../../../types/sales-channels"
|
import { CreateSalesChannelInput } from "../../../../types/sales-channels"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /sales-channels
|
* @oas [post] /sales-channels
|
||||||
@@ -27,13 +28,18 @@ import { CreateSalesChannelInput } from "../../../../types/sales-channels"
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export default async (req: Request, res: Response) => {
|
export default async (req: Request, res: Response) => {
|
||||||
|
const validatedBody = req.validatedBody as CreateSalesChannelInput
|
||||||
const salesChannelService: SalesChannelService = req.scope.resolve(
|
const salesChannelService: SalesChannelService = req.scope.resolve(
|
||||||
"salesChannelService"
|
"salesChannelService"
|
||||||
)
|
)
|
||||||
|
|
||||||
const salesChannel = await salesChannelService.create(
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
req.validatedBody as CreateSalesChannelInput
|
const salesChannel = await manager.transaction(async (transactionManager) => {
|
||||||
)
|
return await salesChannelService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.create(validatedBody)
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({ sales_channel: salesChannel })
|
res.status(200).json({ sales_channel: salesChannel })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { IsArray, ValidateNested } from "class-validator"
|
|||||||
import { SalesChannelService } from "../../../../services"
|
import { SalesChannelService } from "../../../../services"
|
||||||
import { Request, Response } from "express"
|
import { Request, Response } from "express"
|
||||||
import { ProductBatchSalesChannel } from "../../../../types/sales-channels"
|
import { ProductBatchSalesChannel } from "../../../../types/sales-channels"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /sales-channels/{id}/products/batch
|
* @oas [delete] /sales-channels/{id}/products/batch
|
||||||
@@ -27,18 +28,24 @@ import { ProductBatchSalesChannel } from "../../../../types/sales-channels"
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export default async (req: Request, res: Response) => {
|
export default async (req: Request, res: Response) => {
|
||||||
|
const validatedBody =
|
||||||
|
req.validatedBody as AdminDeleteSalesChannelsChannelProductsBatchReq
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
const salesChannelService: SalesChannelService = req.scope.resolve(
|
const salesChannelService: SalesChannelService = req.scope.resolve(
|
||||||
"salesChannelService"
|
"salesChannelService"
|
||||||
)
|
)
|
||||||
|
|
||||||
const validatedBody =
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
req.validatedBody as AdminDeleteSalesChannelsChannelProductsBatchReq
|
const salesChannel = await manager.transaction(async (transactionManager) => {
|
||||||
const salesChannel = await salesChannelService.removeProducts(
|
return await salesChannelService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.removeProducts(
|
||||||
id,
|
id,
|
||||||
validatedBody.product_ids.map((p) => p.id)
|
validatedBody.product_ids.map((p) => p.id)
|
||||||
)
|
)
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({ sales_channel: salesChannel })
|
res.status(200).json({ sales_channel: salesChannel })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Request, Response } from "express"
|
import { Request, Response } from "express"
|
||||||
import { SalesChannelService } from "../../../../services/"
|
import { SalesChannelService } from "../../../../services/"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /sales-channels/{id}
|
* @oas [delete] /sales-channels/{id}
|
||||||
@@ -33,7 +34,13 @@ export default async (req: Request, res: Response): Promise<void> => {
|
|||||||
const salesChannelService: SalesChannelService = req.scope.resolve(
|
const salesChannelService: SalesChannelService = req.scope.resolve(
|
||||||
"salesChannelService"
|
"salesChannelService"
|
||||||
)
|
)
|
||||||
await salesChannelService.delete(id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await salesChannelService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.delete(id)
|
||||||
|
})
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
id,
|
id,
|
||||||
object: "sales-channel",
|
object: "sales-channel",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { IsBoolean, IsOptional, IsString } from "class-validator"
|
import { IsBoolean, IsOptional, IsString } from "class-validator"
|
||||||
import { Request, Response } from "express"
|
import { Request, Response } from "express"
|
||||||
import { SalesChannelService } from "../../../../services"
|
import { SalesChannelService } from "../../../../services"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /sales-channels/{id}
|
* @oas [post] /sales-channels/{id}
|
||||||
@@ -45,7 +46,15 @@ export default async (req: Request, res: Response) => {
|
|||||||
const salesChannelService: SalesChannelService = req.scope.resolve(
|
const salesChannelService: SalesChannelService = req.scope.resolve(
|
||||||
"salesChannelService"
|
"salesChannelService"
|
||||||
)
|
)
|
||||||
const sales_channel = await salesChannelService.update(id, validatedBody)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
const sales_channel = await manager.transaction(
|
||||||
|
async (transactionManager) => {
|
||||||
|
return await salesChannelService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.update(id, validatedBody)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
res.status(200).json({ sales_channel })
|
res.status(200).json({ sales_channel })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
} from "class-validator"
|
} from "class-validator"
|
||||||
import { defaultFields, defaultRelations } from "."
|
import { defaultFields, defaultRelations } from "."
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /shipping-options
|
* @oas [post] /shipping-options
|
||||||
@@ -92,7 +93,13 @@ export default async (req, res) => {
|
|||||||
validated.profile_id = id
|
validated.profile_id = id
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await optionService.create(validated)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
const result = await manager.transaction(async (transactionManager) => {
|
||||||
|
return await optionService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.create(validated)
|
||||||
|
})
|
||||||
|
|
||||||
const data = await optionService.retrieve(result.id, {
|
const data = await optionService.retrieve(result.id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /shipping-options/{id}
|
* @oas [delete] /shipping-options/{id}
|
||||||
* operationId: "DeleteShippingOptionsOption"
|
* operationId: "DeleteShippingOptionsOption"
|
||||||
@@ -28,7 +30,12 @@ export default async (req, res) => {
|
|||||||
const { option_id } = req.params
|
const { option_id } = req.params
|
||||||
const optionService = req.scope.resolve("shippingOptionService")
|
const optionService = req.scope.resolve("shippingOptionService")
|
||||||
|
|
||||||
await optionService.delete(option_id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await optionService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.delete(option_id)
|
||||||
|
})
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
id: option_id,
|
id: option_id,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
} from "class-validator"
|
} from "class-validator"
|
||||||
import { defaultFields, defaultRelations } from "."
|
import { defaultFields, defaultRelations } from "."
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /shipping-options/{id}
|
* @oas [post] /shipping-options/{id}
|
||||||
@@ -69,7 +70,12 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const optionService = req.scope.resolve("shippingOptionService")
|
const optionService = req.scope.resolve("shippingOptionService")
|
||||||
|
|
||||||
await optionService.update(option_id, validated)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await optionService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.update(option_id, validated)
|
||||||
|
})
|
||||||
|
|
||||||
const data = await optionService.retrieve(option_id, {
|
const data = await optionService.retrieve(option_id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { IsString } from "class-validator"
|
import { IsString } from "class-validator"
|
||||||
import { ShippingProfileService } from "../../../../services"
|
import { ShippingProfileService } from "../../../../services"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /shipping-profiles
|
* @oas [post] /shipping-profiles
|
||||||
@@ -36,7 +37,12 @@ export default async (req, res) => {
|
|||||||
const profileService: ShippingProfileService = req.scope.resolve(
|
const profileService: ShippingProfileService = req.scope.resolve(
|
||||||
"shippingProfileService"
|
"shippingProfileService"
|
||||||
)
|
)
|
||||||
const data = await profileService.create(validated)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
const data = await manager.transaction(async (transactionManager) => {
|
||||||
|
return await profileService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.create(validated)
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({ shipping_profile: data })
|
res.status(200).json({ shipping_profile: data })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { ShippingProfileService } from "../../../../services"
|
import { ShippingProfileService } from "../../../../services"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /shipping-profiles/{id}
|
* @oas [delete] /shipping-profiles/{id}
|
||||||
@@ -32,7 +33,12 @@ export default async (req, res) => {
|
|||||||
"shippingProfileService"
|
"shippingProfileService"
|
||||||
)
|
)
|
||||||
|
|
||||||
await profileService.delete(profile_id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await profileService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.delete(profile_id)
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
id: profile_id,
|
id: profile_id,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { IsOptional, IsString } from "class-validator"
|
import { IsOptional, IsString } from "class-validator"
|
||||||
import { ShippingProfileService } from "../../../../services"
|
import { ShippingProfileService } from "../../../../services"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /shipping-profiles/{id}
|
* @oas [post] /shipping-profiles/{id}
|
||||||
@@ -41,7 +42,12 @@ export default async (req, res) => {
|
|||||||
"shippingProfileService"
|
"shippingProfileService"
|
||||||
)
|
)
|
||||||
|
|
||||||
await profileService.update(profile_id, validated)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await profileService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.update(profile_id, validated)
|
||||||
|
})
|
||||||
|
|
||||||
const data = await profileService.retrieve(profile_id)
|
const data = await profileService.retrieve(profile_id)
|
||||||
res.status(200).json({ shipping_profile: data })
|
res.status(200).json({ shipping_profile: data })
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { StoreService } from "../../../../services"
|
import { StoreService } from "../../../../services"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
/**
|
/**
|
||||||
* @oas [post] /store/currencies/{code}
|
* @oas [post] /store/currencies/{code}
|
||||||
* operationId: "PostStoreCurrenciesCode"
|
* operationId: "PostStoreCurrenciesCode"
|
||||||
@@ -23,6 +24,12 @@ export default async (req, res) => {
|
|||||||
const { currency_code } = req.params
|
const { currency_code } = req.params
|
||||||
|
|
||||||
const storeService: StoreService = req.scope.resolve("storeService")
|
const storeService: StoreService = req.scope.resolve("storeService")
|
||||||
const data = await storeService.addCurrency(currency_code)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
const data = await manager.transaction(async (transactionManager) => {
|
||||||
|
return await storeService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.addCurrency(currency_code)
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({ store: data })
|
res.status(200).json({ store: data })
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { StoreService } from "../../../../services"
|
import { StoreService } from "../../../../services"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /store/currencies/{code}
|
* @oas [delete] /store/currencies/{code}
|
||||||
@@ -24,6 +25,12 @@ export default async (req, res) => {
|
|||||||
const { currency_code } = req.params
|
const { currency_code } = req.params
|
||||||
|
|
||||||
const storeService: StoreService = req.scope.resolve("storeService")
|
const storeService: StoreService = req.scope.resolve("storeService")
|
||||||
const data = await storeService.removeCurrency(currency_code)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
const data = await manager.transaction(async (transactionManager) => {
|
||||||
|
return await storeService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.removeCurrency(currency_code)
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({ store: data })
|
res.status(200).json({ store: data })
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { IsArray, IsOptional, IsString, IsObject } from "class-validator"
|
import { IsArray, IsOptional, IsString, IsObject } from "class-validator"
|
||||||
import { StoreService } from "../../../../services"
|
import { StoreService } from "../../../../services"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /store
|
* @oas [post] /store
|
||||||
@@ -45,7 +46,12 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const storeService: StoreService = req.scope.resolve("storeService")
|
const storeService: StoreService = req.scope.resolve("storeService")
|
||||||
|
|
||||||
const store = await storeService.update(validatedBody)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
const store = await manager.transaction(async (transactionManager) => {
|
||||||
|
return await storeService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.update(validatedBody)
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({ store })
|
res.status(200).json({ store })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { IsArray, IsOptional } from "class-validator"
|
|||||||
import { TaxRate } from "../../../.."
|
import { TaxRate } from "../../../.."
|
||||||
import { TaxRateService } from "../../../../services"
|
import { TaxRateService } from "../../../../services"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /tax-rates/:id/product-types/batch
|
* @oas [post] /tax-rates/:id/product-types/batch
|
||||||
@@ -38,7 +39,12 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const rateService: TaxRateService = req.scope.resolve("taxRateService")
|
const rateService: TaxRateService = req.scope.resolve("taxRateService")
|
||||||
|
|
||||||
await rateService.addToProductType(req.params.id, value.product_types)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await rateService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.addToProductType(req.params.id, value.product_types)
|
||||||
|
})
|
||||||
|
|
||||||
const config = getRetrieveConfig(
|
const config = getRetrieveConfig(
|
||||||
query.fields as (keyof TaxRate)[],
|
query.fields as (keyof TaxRate)[],
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { IsArray, IsOptional } from "class-validator"
|
|||||||
import { TaxRate } from "../../../.."
|
import { TaxRate } from "../../../.."
|
||||||
import { TaxRateService } from "../../../../services"
|
import { TaxRateService } from "../../../../services"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /tax-rates/:id/products/batch
|
* @oas [post] /tax-rates/:id/products/batch
|
||||||
@@ -35,7 +36,12 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const rateService: TaxRateService = req.scope.resolve("taxRateService")
|
const rateService: TaxRateService = req.scope.resolve("taxRateService")
|
||||||
|
|
||||||
await rateService.addToProduct(req.params.id, value.products)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await rateService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.addToProduct(req.params.id, value.products)
|
||||||
|
})
|
||||||
|
|
||||||
const config = getRetrieveConfig(
|
const config = getRetrieveConfig(
|
||||||
query.fields as (keyof TaxRate)[],
|
query.fields as (keyof TaxRate)[],
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { IsArray, IsOptional } from "class-validator"
|
|||||||
import { TaxRate } from "../../../.."
|
import { TaxRate } from "../../../.."
|
||||||
import { TaxRateService } from "../../../../services"
|
import { TaxRateService } from "../../../../services"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /tax-rates/:id/shipping-options/batch
|
* @oas [post] /tax-rates/:id/shipping-options/batch
|
||||||
@@ -37,7 +38,12 @@ export default async (req, res) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const rateService: TaxRateService = req.scope.resolve("taxRateService")
|
const rateService: TaxRateService = req.scope.resolve("taxRateService")
|
||||||
await rateService.addToShippingOption(req.params.id, value.shipping_options)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await rateService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.addToShippingOption(req.params.id, value.shipping_options)
|
||||||
|
})
|
||||||
|
|
||||||
const config = getRetrieveConfig(
|
const config = getRetrieveConfig(
|
||||||
query.fields as (keyof TaxRate)[],
|
query.fields as (keyof TaxRate)[],
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { TaxRateService } from "../../../../services"
|
import { TaxRateService } from "../../../../services"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /tax-rates/{id}
|
* @oas [delete] /tax-rates/{id}
|
||||||
@@ -30,7 +31,10 @@ export default async (req, res) => {
|
|||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
const taxRateService: TaxRateService = req.scope.resolve("taxRateService")
|
const taxRateService: TaxRateService = req.scope.resolve("taxRateService")
|
||||||
|
|
||||||
await taxRateService.delete(id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await taxRateService.withTransaction(transactionManager).delete(id)
|
||||||
|
})
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
id: id,
|
id: id,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { IsArray, IsOptional } from "class-validator"
|
|||||||
import { TaxRate } from "../../../.."
|
import { TaxRate } from "../../../.."
|
||||||
import { TaxRateService } from "../../../../services"
|
import { TaxRateService } from "../../../../services"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /tax-rates/:id/product-types/batch
|
* @oas [delete] /tax-rates/:id/product-types/batch
|
||||||
@@ -38,7 +39,12 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const rateService: TaxRateService = req.scope.resolve("taxRateService")
|
const rateService: TaxRateService = req.scope.resolve("taxRateService")
|
||||||
|
|
||||||
await rateService.removeFromProductType(req.params.id, value.product_types)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await rateService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.removeFromProductType(req.params.id, value.product_types)
|
||||||
|
})
|
||||||
|
|
||||||
const config = getRetrieveConfig(
|
const config = getRetrieveConfig(
|
||||||
query.fields as (keyof TaxRate)[],
|
query.fields as (keyof TaxRate)[],
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { IsArray, IsOptional } from "class-validator"
|
|||||||
import { TaxRate } from "../../../.."
|
import { TaxRate } from "../../../.."
|
||||||
import { TaxRateService } from "../../../../services"
|
import { TaxRateService } from "../../../../services"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /tax-rates/:id/products/batch
|
* @oas [delete] /tax-rates/:id/products/batch
|
||||||
@@ -35,7 +36,12 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const rateService: TaxRateService = req.scope.resolve("taxRateService")
|
const rateService: TaxRateService = req.scope.resolve("taxRateService")
|
||||||
|
|
||||||
await rateService.removeFromProduct(req.params.id, value.products)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await rateService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.removeFromProduct(req.params.id, value.products)
|
||||||
|
})
|
||||||
|
|
||||||
const config = getRetrieveConfig(
|
const config = getRetrieveConfig(
|
||||||
query.fields as (keyof TaxRate)[],
|
query.fields as (keyof TaxRate)[],
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { IsArray, IsOptional } from "class-validator"
|
|||||||
import { TaxRate } from "../../../.."
|
import { TaxRate } from "../../../.."
|
||||||
import { TaxRateService } from "../../../../services"
|
import { TaxRateService } from "../../../../services"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /tax-rates/:id/shipping-options/batch
|
* @oas [delete] /tax-rates/:id/shipping-options/batch
|
||||||
@@ -38,10 +39,12 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const rateService: TaxRateService = req.scope.resolve("taxRateService")
|
const rateService: TaxRateService = req.scope.resolve("taxRateService")
|
||||||
|
|
||||||
await rateService.removeFromShippingOption(
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
req.params.id,
|
await manager.transaction(async (transactionManager) => {
|
||||||
value.shipping_options
|
return await rateService
|
||||||
)
|
.withTransaction(transactionManager)
|
||||||
|
.removeFromShippingOption(req.params.id, value.shipping_options)
|
||||||
|
})
|
||||||
|
|
||||||
const config = getRetrieveConfig(
|
const config = getRetrieveConfig(
|
||||||
query.fields as (keyof TaxRate)[],
|
query.fields as (keyof TaxRate)[],
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import _ from "lodash"
|
|||||||
import { UserRoles } from "../../../../models/user"
|
import { UserRoles } from "../../../../models/user"
|
||||||
import UserService from "../../../../services/user"
|
import UserService from "../../../../services/user"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /users
|
* @oas [post] /users
|
||||||
@@ -51,7 +52,12 @@ export default async (req, res) => {
|
|||||||
const userService: UserService = req.scope.resolve("userService")
|
const userService: UserService = req.scope.resolve("userService")
|
||||||
const data = _.omit(validated, ["password"])
|
const data = _.omit(validated, ["password"])
|
||||||
|
|
||||||
const user = await userService.create(data, validated.password)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
const user = await manager.transaction(async (transactionManager) => {
|
||||||
|
return await userService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.create(data, validated.password)
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({ user: _.omit(user, ["password_hash"]) })
|
res.status(200).json({ user: _.omit(user, ["password_hash"]) })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import UserService from "../../../../services/user"
|
import UserService from "../../../../services/user"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /users/{user_id}
|
* @oas [delete] /users/{user_id}
|
||||||
@@ -30,7 +31,10 @@ export default async (req, res) => {
|
|||||||
const { user_id } = req.params
|
const { user_id } = req.params
|
||||||
|
|
||||||
const userService: UserService = req.scope.resolve("userService")
|
const userService: UserService = req.scope.resolve("userService")
|
||||||
await userService.delete(user_id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await userService.withTransaction(transactionManager).delete(user_id)
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).send({
|
res.status(200).send({
|
||||||
id: user_id,
|
id: user_id,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { IsEmail } from "class-validator"
|
import { IsEmail } from "class-validator"
|
||||||
import UserService from "../../../../services/user"
|
import UserService from "../../../../services/user"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /users/password-token
|
* @oas [post] /users/password-token
|
||||||
@@ -31,7 +32,12 @@ export default async (req, res) => {
|
|||||||
const user = await userService.retrieveByEmail(validated.email)
|
const user = await userService.retrieveByEmail(validated.email)
|
||||||
|
|
||||||
// Should call a email service provider that sends the token to the user
|
// Should call a email service provider that sends the token to the user
|
||||||
await userService.generateResetPasswordToken(user.id)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
await manager.transaction(async (transactionManager) => {
|
||||||
|
return await userService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.generateResetPasswordToken(user.id)
|
||||||
|
})
|
||||||
|
|
||||||
res.sendStatus(204)
|
res.sendStatus(204)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { MedusaError } from "medusa-core-utils"
|
|||||||
import { User } from "../../../.."
|
import { User } from "../../../.."
|
||||||
import UserService from "../../../../services/user"
|
import UserService from "../../../../services/user"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /users/password-token
|
* @oas [post] /users/password-token
|
||||||
@@ -71,10 +72,12 @@ export default async (req, res) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const userResult = await userService.setPassword_(
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
user.id,
|
const userResult = await manager.transaction(async (transactionManager) => {
|
||||||
validated.password
|
return await userService
|
||||||
)
|
.withTransaction(transactionManager)
|
||||||
|
.setPassword_(user.id, validated.password)
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({ user: _.omit(userResult, ["password_hash"]) })
|
res.status(200).json({ user: _.omit(userResult, ["password_hash"]) })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { IsEnum, IsObject, IsOptional, IsString } from "class-validator"
|
|||||||
import { UserRoles } from "../../../../models/user"
|
import { UserRoles } from "../../../../models/user"
|
||||||
import UserService from "../../../../services/user"
|
import UserService from "../../../../services/user"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /users/{user_id}
|
* @oas [post] /users/{user_id}
|
||||||
@@ -33,7 +34,13 @@ export default async (req, res) => {
|
|||||||
const validated = await validator(AdminUpdateUserRequest, req.body)
|
const validated = await validator(AdminUpdateUserRequest, req.body)
|
||||||
|
|
||||||
const userService: UserService = req.scope.resolve("userService")
|
const userService: UserService = req.scope.resolve("userService")
|
||||||
const data = await userService.update(user_id, validated)
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
const data = await manager.transaction(async (transactionManager) => {
|
||||||
|
return await userService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.update(user_id, validated)
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({ user: data })
|
res.status(200).json({ user: data })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ export const regions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const RegionServiceMock = {
|
export const RegionServiceMock = {
|
||||||
|
withTransaction: function () {
|
||||||
|
return this
|
||||||
|
},
|
||||||
retrieve: jest.fn().mockImplementation(regionId => {
|
retrieve: jest.fn().mockImplementation(regionId => {
|
||||||
if (regionId === IdMap.getId("testRegion")) {
|
if (regionId === IdMap.getId("testRegion")) {
|
||||||
return Promise.resolve(regions.testRegion)
|
return Promise.resolve(regions.testRegion)
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ export const shippingOptions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ShippingOptionServiceMock = {
|
export const ShippingOptionServiceMock = {
|
||||||
|
withTransaction: function () {
|
||||||
|
return this
|
||||||
|
},
|
||||||
retrieve: jest.fn().mockImplementation((optionId) => {
|
retrieve: jest.fn().mockImplementation((optionId) => {
|
||||||
if (optionId === IdMap.getId("return-shipping")) {
|
if (optionId === IdMap.getId("return-shipping")) {
|
||||||
return Promise.resolve(shippingOptions.returnShipping)
|
return Promise.resolve(shippingOptions.returnShipping)
|
||||||
|
|||||||
Reference in new issue
Block a user