Merge branch 'integration/dummy-project' of github.com:medusajs/medusa into integration/dummy-project

This commit is contained in:
Sebastian Rindom
2020-07-04 12:16:37 +02:00
67 changed files with 13988 additions and 178 deletions
@@ -43,6 +43,8 @@ export default async (req, res) => {
delete value.variants
const productService = req.scope.resolve("productService")
const shippingProfileService = req.scope.resolve("shippingProfileService")
let newProduct = await productService.createDraft(value)
if (variants) {
@@ -64,6 +66,10 @@ export default async (req, res) => {
)
}
// Add to default shipping profile
const { _id } = await shippingProfileService.retrieveDefault()
await shippingProfileService.addProduct(_id, newProduct._id)
newProduct = await productService.decorate(newProduct, [
"title",
"description",
@@ -12,6 +12,8 @@ describe("POST /admin/shipping-options", () => {
name: "Test option",
region_id: "testregion",
provider_id: "test_provider",
data: { id: "test" },
profile_id: "test",
price: {
type: "flat_rate",
amount: 100,
@@ -32,6 +34,7 @@ describe("POST /admin/shipping-options", () => {
})
it("returns 200", () => {
console.log(subject)
expect(subject.status).toEqual(200)
})
@@ -41,6 +44,8 @@ describe("POST /admin/shipping-options", () => {
name: "Test option",
region_id: "testregion",
provider_id: "test_provider",
data: { id: "test" },
profile_id: "test",
price: {
type: "flat_rate",
amount: 100,
@@ -5,11 +5,14 @@ export default async (req, res) => {
name: Validator.string().required(),
region_id: Validator.string().required(),
provider_id: Validator.string().required(),
data: Validator.object(),
price: Validator.object().keys({
type: Validator.string().required(),
amount: Validator.number().optional(),
}),
profile_id: Validator.string().required(),
data: Validator.object().required(),
price: Validator.object()
.keys({
type: Validator.string().required(),
amount: Validator.number().optional(),
})
.required(),
requirements: Validator.array()
.items(
Validator.object({
@@ -27,10 +30,17 @@ export default async (req, res) => {
try {
const optionService = req.scope.resolve("shippingOptionService")
const shippingProfileService = req.scope.resolve("shippingProfileService")
const data = await optionService.create(value)
// Add to default shipping profile
const { _id } = await shippingProfileService.retrieveDefault()
await shippingProfileService.addShippingOption(_id, data._id)
res.status(200).json({ shipping_option: data })
} catch (err) {
console.log(err)
throw err
}
}
@@ -12,6 +12,7 @@ export default async (req, res) => {
discounts: Validator.array().items({
code: Validator.string(),
}),
customer_id: Validator.string(),
})
const { value, error } = schema.validate(req.body)
@@ -27,6 +28,10 @@ export default async (req, res) => {
}
try {
if (value.customer_id) {
await cartService.updateCustomerId(id, value.customer_id)
}
if (value.region_id) {
await cartService.setRegion(id, value.region_id)
}
@@ -17,7 +17,7 @@ export default async (req, res) => {
try {
const customerService = req.scope.resolve("customerService")
const customer = await customerService.create(value)
const data = await customerService.decorate(customer)
const data = await customerService.decorate(customer, ["_id", "email"])
res.status(201).json({ customer: data })
} catch (err) {
throw err