feat(medusa): Validate LineItems in SalesChannel (#1871)

* wip: validate line item SC

* fix: repository type, remove relation, use sc id, check if cart has associated sc

* feat: setup tests and seeder, change entity retrieval in cart service method

* feat: remove repo usage and method, use Adrien's method from product service to check sc association, add test cases, add seeder entities, accept flag for validating sc on the endpoint

* feat: add a unit test to ensure validation method is called if flag is passed

* feat: allow `validate_sales_channels` flag in other relevant endpoints

* fix: typo

* fix: flag rename

* fix: correct FF in test suites

* fix: address PR feedback

* fix: change error message

* feat: remove query params, guard with FF, refactor

* feat: guard validation in the service

* refactor: rename validation method

* refactor: reorganise tests

* wip: cleanup test file

* wip: revert cart seeder changes use factories

* fix: remove seeder, update mocks

* fix: method name

* fix: units, validate by default

* git: resolve merge conflicts

* refactor: separate line item sales chanel units

Co-authored-by: fPolic <frane@medusajs.com>
This commit is contained in:
Frane Polić
2022-07-27 21:39:06 +02:00
committed by GitHub
co-authored by fPolic
parent 204dd23a39
commit 3fbe8d7d08
9 changed files with 387 additions and 28 deletions
@@ -1,4 +1,10 @@
import { IsInt, IsObject, IsOptional, IsString } from "class-validator"
import {
IsBoolean,
IsInt,
IsObject,
IsOptional,
IsString,
} from "class-validator"
import { MedusaError } from "medusa-core-utils"
import { EntityManager } from "typeorm"
import {
@@ -12,6 +18,7 @@ import {
LineItemService,
} from "../../../../services"
import { validator } from "../../../../utils/validator"
import { FlagRouter } from "../../../../utils/flag-router"
/**
* @oas [post] /draft-orders/{id}/line-items
* operationId: "PostDraftOrdersDraftOrderLineItems"
@@ -92,7 +99,7 @@ export default async (req, res) => {
await cartService
.withTransaction(manager)
.addLineItem(draftOrder.cart_id, line)
.addLineItem(draftOrder.cart_id, line, { validateSalesChannels: false })
} else {
// custom line items can be added to a draft order
await lineItemService.withTransaction(manager).create({