Merge branch 'medusajs:develop' into develop
This commit is contained in:
76 files changed
+882
-1120
No files matched your search
@@ -6,12 +6,10 @@
|
|||||||
/packages/medusa/src/services/middleware.js
|
/packages/medusa/src/services/middleware.js
|
||||||
/packages/medusa/src/services/payment-provider.js
|
/packages/medusa/src/services/payment-provider.js
|
||||||
/packages/medusa/src/services/product-variant.js
|
/packages/medusa/src/services/product-variant.js
|
||||||
/packages/medusa/src/services/product.js
|
|
||||||
/packages/medusa/src/services/shipping-profile.js
|
/packages/medusa/src/services/shipping-profile.js
|
||||||
/packages/medusa/src/subscribers/notification.js
|
/packages/medusa/src/subscribers/notification.js
|
||||||
/packages/medusa/src/subscribers/order.js
|
/packages/medusa/src/subscribers/order.js
|
||||||
/packages/medusa/src/subscribers/product.js
|
/packages/medusa/src/subscribers/product.js
|
||||||
|
|
||||||
/packages/medusa/src/loaders/api.js
|
/packages/medusa/src/loaders/api.js
|
||||||
/packages/medusa/src/loaders/database.js
|
/packages/medusa/src/loaders/database.js
|
||||||
/packages/medusa/src/loaders/defaults.js
|
/packages/medusa/src/loaders/defaults.js
|
||||||
@@ -25,37 +23,20 @@
|
|||||||
/packages/medusa/src/loaders/repositories.js
|
/packages/medusa/src/loaders/repositories.js
|
||||||
/packages/medusa/src/loaders/services.js
|
/packages/medusa/src/loaders/services.js
|
||||||
/packages/medusa/src/loaders/subscribers.js
|
/packages/medusa/src/loaders/subscribers.js
|
||||||
|
|
||||||
/packages/medusa/src/api/routes/admin/apps
|
/packages/medusa/src/api/routes/admin/apps
|
||||||
/packages/medusa/src/api/routes/admin/auth
|
/packages/medusa/src/api/routes/admin/auth
|
||||||
/packages/medusa/src/api/routes/admin/collections
|
/packages/medusa/src/api/routes/admin/collections
|
||||||
/packages/medusa/src/api/routes/admin/customers
|
/packages/medusa/src/api/routes/admin/customers
|
||||||
/packages/medusa/src/api/routes/admin/draft-orders
|
/packages/medusa/src/api/routes/admin/draft-orders
|
||||||
/packages/medusa/src/api/routes/admin/gift-cards
|
|
||||||
/packages/medusa/src/api/routes/admin/notes
|
/packages/medusa/src/api/routes/admin/notes
|
||||||
/packages/medusa/src/api/routes/admin/notifications
|
|
||||||
/packages/medusa/src/api/routes/admin/orders
|
/packages/medusa/src/api/routes/admin/orders
|
||||||
/packages/medusa/src/api/routes/admin/products
|
|
||||||
/packages/medusa/src/api/routes/admin/regions
|
|
||||||
/packages/medusa/src/api/routes/admin/return-reasons
|
/packages/medusa/src/api/routes/admin/return-reasons
|
||||||
/packages/medusa/src/api/routes/admin/returns
|
/packages/medusa/src/api/routes/admin/returns
|
||||||
/packages/medusa/src/api/routes/admin/shipping-options
|
|
||||||
/packages/medusa/src/api/routes/admin/shipping-profiles
|
/packages/medusa/src/api/routes/admin/shipping-profiles
|
||||||
/packages/medusa/src/api/routes/admin/store
|
/packages/medusa/src/api/routes/admin/store
|
||||||
/packages/medusa/src/api/routes/admin/swaps
|
|
||||||
/packages/medusa/src/api/routes/admin/users
|
|
||||||
|
|
||||||
|
|
||||||
/packages/medusa/src/api/routes/store/auth
|
|
||||||
/packages/medusa/src/api/routes/store/carts
|
/packages/medusa/src/api/routes/store/carts
|
||||||
/packages/medusa/src/api/routes/store/customers
|
|
||||||
/packages/medusa/src/api/routes/store/gift-cards
|
|
||||||
/packages/medusa/src/api/routes/store/orders
|
|
||||||
/packages/medusa/src/api/routes/store/products
|
|
||||||
/packages/medusa/src/api/routes/store/regions
|
|
||||||
/packages/medusa/src/api/routes/store/return-reasons
|
/packages/medusa/src/api/routes/store/return-reasons
|
||||||
/packages/medusa/src/api/routes/store/returns
|
/packages/medusa/src/api/routes/store/returns
|
||||||
/packages/medusa/src/api/routes/store/shipping-options
|
|
||||||
/packages/medusa/src/api/routes/store/swaps
|
/packages/medusa/src/api/routes/store/swaps
|
||||||
|
|
||||||
# END OF FILES TODO
|
# END OF FILES TODO
|
||||||
@@ -66,7 +47,6 @@
|
|||||||
/packages/medusa/src/helpers
|
/packages/medusa/src/helpers
|
||||||
/packages/medusa/src/migrations
|
/packages/medusa/src/migrations
|
||||||
/packages/medusa/src/utils
|
/packages/medusa/src/utils
|
||||||
|
|
||||||
/integration-tests
|
/integration-tests
|
||||||
/docs
|
/docs
|
||||||
/docs-util
|
/docs-util
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
name: cache-bootstrap
|
||||||
|
description: Creates a cache with the given extension for lerna packages
|
||||||
|
inputs:
|
||||||
|
extension:
|
||||||
|
description: Extension for cache name
|
||||||
|
partial:
|
||||||
|
description: Boolean flag to describe whether or not to run a partial bootstrap when finding cache
|
||||||
|
default: false
|
||||||
|
runs:
|
||||||
|
using: composite
|
||||||
|
steps:
|
||||||
|
# for always overriding cache, use: pat-s/always-upload-cache@v2.1.5
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
id: cache
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
node_modules
|
||||||
|
*/*/node_modules
|
||||||
|
key: ${{ runner.os }}-yarn-${{inputs.extension}}-v8-${{ hashFiles('**/yarn.lock') }}
|
||||||
|
# We want to only bootstrap and install if no cache is found.
|
||||||
|
# Futhermore, we might want to do a partial, hoisted, bootstrap towards
|
||||||
|
# the base branch if it exists, otherwise we choose develop for this.
|
||||||
|
|
||||||
|
# yarn install --frozen-lockfile
|
||||||
|
- run: |
|
||||||
|
if [[ "${{steps.cache.outputs.cache-hit}}" != "true" || "${{inputs.partial}}" != "true" ]]; then
|
||||||
|
yarn install --frozen-lockfile
|
||||||
|
yarn bootstrap --concurrency=2
|
||||||
|
elif [[ "${{inputs.partial}}" = "true" ]]; then
|
||||||
|
[[ ! -z "${GITHUB_BASE_REF}" ]] && ref="${GITHUB_BASE_REF#refs/heads/}" || ref="develop"
|
||||||
|
yarn bootstrap --npm-client=npm --hoist --since "origin/${ref}...HEAD" --concurrency=2
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
name: Medusa Pipeline
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
unit-tests:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2.3.5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js environment
|
||||||
|
uses: actions/setup-node@v2.4.1
|
||||||
|
with:
|
||||||
|
node-version: '14'
|
||||||
|
cache: 'yarn'
|
||||||
|
|
||||||
|
- name: Assert changed
|
||||||
|
run: ./scripts/assert-changed-files-actions.sh "packages"
|
||||||
|
|
||||||
|
- name: Bootstrap packages
|
||||||
|
uses: ./.github/actions/cache-bootstrap
|
||||||
|
with:
|
||||||
|
extension: unit-tests
|
||||||
|
|
||||||
|
- name: Run unit tests
|
||||||
|
run: node --max-old-space-size=2048 ./node_modules/.bin/jest -w 1
|
||||||
|
|
||||||
|
integration-tests:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres
|
||||||
|
env:
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
options: >-
|
||||||
|
--health-cmd pg_isready
|
||||||
|
--health-interval 10s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 5
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2.3.5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js environment
|
||||||
|
uses: actions/setup-node@v2.4.1
|
||||||
|
with:
|
||||||
|
node-version: '14'
|
||||||
|
cache: 'yarn'
|
||||||
|
|
||||||
|
- name: Bootstrap packages
|
||||||
|
uses: ./.github/actions/cache-bootstrap
|
||||||
|
with:
|
||||||
|
extension: integration-tests
|
||||||
|
|
||||||
|
- name: Install dev cli
|
||||||
|
run: sudo npm i -g medusa-dev-cli
|
||||||
|
|
||||||
|
- name: Set path to medusa repo
|
||||||
|
run: medusa-dev --set-path-to-repo `pwd`
|
||||||
|
|
||||||
|
- name: Force install
|
||||||
|
run: medusa-dev --force-install
|
||||||
|
working-directory: integration-tests/api
|
||||||
|
|
||||||
|
- name: Build integration tests
|
||||||
|
run: yarn build
|
||||||
|
working-directory: integration-tests/api
|
||||||
|
|
||||||
|
- name: Run integration tests
|
||||||
|
run: yarn test
|
||||||
|
working-directory: integration-tests/api
|
||||||
|
env:
|
||||||
|
DB_PASSWORD: postgres
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"endOfLine": "lf",
|
"endOfLine": "auto",
|
||||||
"semi": false,
|
"semi": false,
|
||||||
"singleQuote": false,
|
"singleQuote": false,
|
||||||
"tabWidth": 2,
|
"tabWidth": 2,
|
||||||
|
|||||||
@@ -43,9 +43,7 @@ import { defaultFields, defaultRelations } from "./"
|
|||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const schema = Validator.object().keys({
|
const schema = Validator.object().keys({
|
||||||
value: Validator.number()
|
value: Validator.number().integer().optional(),
|
||||||
.integer()
|
|
||||||
.optional(),
|
|
||||||
ends_at: Validator.date().optional(),
|
ends_at: Validator.date().optional(),
|
||||||
is_disabled: Validator.boolean().optional(),
|
is_disabled: Validator.boolean().optional(),
|
||||||
region_id: Validator.string().optional(),
|
region_id: Validator.string().optional(),
|
||||||
@@ -57,21 +55,17 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const giftCardService = req.scope.resolve("giftCardService")
|
||||||
const giftCardService = req.scope.resolve("giftCardService")
|
|
||||||
|
|
||||||
const newly = await giftCardService.create({
|
const newly = await giftCardService.create({
|
||||||
...value,
|
...value,
|
||||||
balance: value.value,
|
balance: value.value,
|
||||||
})
|
})
|
||||||
|
|
||||||
const giftCard = await giftCardService.retrieve(newly.id, {
|
const giftCard = await giftCardService.retrieve(newly.id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ gift_card: giftCard })
|
res.status(200).json({ gift_card: giftCard })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -26,16 +26,12 @@
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
try {
|
const giftCardService = req.scope.resolve("giftCardService")
|
||||||
const giftCardService = req.scope.resolve("giftCardService")
|
await giftCardService.delete(id)
|
||||||
await giftCardService.delete(id)
|
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
id,
|
id,
|
||||||
object: "gift-card",
|
object: "gift-card",
|
||||||
deleted: true,
|
deleted: true,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -22,15 +22,11 @@ import { defaultFields, defaultRelations } from "./"
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
try {
|
const giftCardService = req.scope.resolve("giftCardService")
|
||||||
const giftCardService = req.scope.resolve("giftCardService")
|
const giftCard = await giftCardService.retrieve(id, {
|
||||||
const giftCard = await giftCardService.retrieve(id, {
|
select: defaultFields,
|
||||||
select: defaultFields,
|
relations: defaultRelations,
|
||||||
relations: defaultRelations,
|
})
|
||||||
})
|
|
||||||
|
|
||||||
res.status(200).json({ gift_card: giftCard })
|
res.status(200).json({ gift_card: giftCard })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ import middlewares from "../../../middlewares"
|
|||||||
|
|
||||||
const route = Router()
|
const route = Router()
|
||||||
|
|
||||||
export default app => {
|
export default (app) => {
|
||||||
app.use("/gift-cards", route)
|
app.use("/gift-cards", route)
|
||||||
|
|
||||||
route.get("/", middlewares.wrap(require("./list-gift-cards").default))
|
route.get("/", middlewares.wrap(require("./list-gift-cards").default))
|
||||||
@@ -33,10 +33,7 @@ export const defaultFields = [
|
|||||||
"metadata",
|
"metadata",
|
||||||
]
|
]
|
||||||
|
|
||||||
export const defaultRelations = [
|
export const defaultRelations = ["region", "order"]
|
||||||
"region",
|
|
||||||
"order",
|
|
||||||
]
|
|
||||||
|
|
||||||
export const allowedFields = [
|
export const allowedFields = [
|
||||||
"id",
|
"id",
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { MedusaError, Validator } from "medusa-core-utils"
|
|
||||||
import { defaultFields, defaultRelations } from "./"
|
import { defaultFields, defaultRelations } from "./"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,28 +20,24 @@ import { defaultFields, defaultRelations } from "./"
|
|||||||
* $ref: "#/components/schemas/gift_card"
|
* $ref: "#/components/schemas/gift_card"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
try {
|
const limit = parseInt(req.query.limit) || 50
|
||||||
const limit = parseInt(req.query.limit) || 50
|
const offset = parseInt(req.query.offset) || 0
|
||||||
const offset = parseInt(req.query.offset) || 0
|
|
||||||
|
|
||||||
const selector = {}
|
const selector = {}
|
||||||
|
|
||||||
if ("q" in req.query) {
|
if ("q" in req.query) {
|
||||||
selector.q = req.query.q
|
selector.q = req.query.q
|
||||||
}
|
|
||||||
|
|
||||||
const giftCardService = req.scope.resolve("giftCardService")
|
|
||||||
|
|
||||||
const giftCards = await giftCardService.list(selector, {
|
|
||||||
select: defaultFields,
|
|
||||||
relations: defaultRelations,
|
|
||||||
order: { created_at: "DESC" },
|
|
||||||
limit: limit,
|
|
||||||
skip: offset,
|
|
||||||
})
|
|
||||||
|
|
||||||
res.status(200).json({ gift_cards: giftCards })
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const giftCardService = req.scope.resolve("giftCardService")
|
||||||
|
|
||||||
|
const giftCards = await giftCardService.list(selector, {
|
||||||
|
select: defaultFields,
|
||||||
|
relations: defaultRelations,
|
||||||
|
order: { created_at: "DESC" },
|
||||||
|
limit: limit,
|
||||||
|
skip: offset,
|
||||||
|
})
|
||||||
|
|
||||||
|
res.status(200).json({ gift_cards: giftCards })
|
||||||
}
|
}
|
||||||
@@ -47,9 +47,7 @@ export default async (req, res) => {
|
|||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
const schema = Validator.object().keys({
|
const schema = Validator.object().keys({
|
||||||
balance: Validator.number()
|
balance: Validator.number().precision(0).optional(),
|
||||||
.precision(0)
|
|
||||||
.optional(),
|
|
||||||
ends_at: Validator.date().optional(),
|
ends_at: Validator.date().optional(),
|
||||||
is_disabled: Validator.boolean().optional(),
|
is_disabled: Validator.boolean().optional(),
|
||||||
region_id: Validator.string().optional(),
|
region_id: Validator.string().optional(),
|
||||||
@@ -61,18 +59,14 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const giftCardService = req.scope.resolve("giftCardService")
|
||||||
const giftCardService = req.scope.resolve("giftCardService")
|
|
||||||
|
|
||||||
await giftCardService.update(id, value)
|
await giftCardService.update(id, value)
|
||||||
|
|
||||||
const giftCard = await giftCardService.retrieve(id, {
|
const giftCard = await giftCardService.retrieve(id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ gift_card: giftCard })
|
res.status(200).json({ gift_card: giftCard })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ import middlewares from "../../../middlewares"
|
|||||||
|
|
||||||
const route = Router()
|
const route = Router()
|
||||||
|
|
||||||
export default app => {
|
export default (app) => {
|
||||||
app.use("/notifications", route)
|
app.use("/notifications", route)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,63 +21,59 @@ import { defaultRelations, defaultFields } from "./"
|
|||||||
* $ref: "#/components/schemas/notification"
|
* $ref: "#/components/schemas/notification"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
try {
|
const notificationService = req.scope.resolve("notificationService")
|
||||||
const notificationService = req.scope.resolve("notificationService")
|
|
||||||
|
|
||||||
const limit = parseInt(req.query.limit) || 50
|
const limit = parseInt(req.query.limit) || 50
|
||||||
const offset = parseInt(req.query.offset) || 0
|
const offset = parseInt(req.query.offset) || 0
|
||||||
|
|
||||||
let selector = {}
|
const selector = {}
|
||||||
|
|
||||||
let includeFields = []
|
let includeFields = []
|
||||||
if ("fields" in req.query) {
|
if ("fields" in req.query) {
|
||||||
includeFields = req.query.fields.split(",")
|
includeFields = req.query.fields.split(",")
|
||||||
}
|
|
||||||
|
|
||||||
let expandFields = []
|
|
||||||
if ("expand" in req.query) {
|
|
||||||
expandFields = req.query.expand.split(",")
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("event_name" in req.query) {
|
|
||||||
const values = req.query.event_name.split(",")
|
|
||||||
selector.event_name = values.length > 1 ? values : values[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("resource_type" in req.query) {
|
|
||||||
const values = req.query.resource_type.split(",")
|
|
||||||
selector.resource_type = values.length > 1 ? values : values[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("resource_id" in req.query) {
|
|
||||||
const values = req.query.resource_id.split(",")
|
|
||||||
selector.resource_id = values.length > 1 ? values : values[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("to" in req.query) {
|
|
||||||
const values = req.query.to.split(",")
|
|
||||||
selector.to = values.length > 1 ? values : values[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!("include_resends" in req.query)) {
|
|
||||||
selector.parent_id = null
|
|
||||||
}
|
|
||||||
|
|
||||||
const listConfig = {
|
|
||||||
select: includeFields.length ? includeFields : defaultFields,
|
|
||||||
relations: expandFields.length ? expandFields : defaultRelations,
|
|
||||||
skip: offset,
|
|
||||||
take: limit,
|
|
||||||
order: { created_at: "DESC" },
|
|
||||||
}
|
|
||||||
|
|
||||||
const notifications = await notificationService.list(selector, listConfig)
|
|
||||||
|
|
||||||
const fields = [...listConfig.select, ...listConfig.relations]
|
|
||||||
const data = notifications.map(o => _.pick(o, fields))
|
|
||||||
|
|
||||||
res.json({ notifications: data, offset, limit })
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let expandFields = []
|
||||||
|
if ("expand" in req.query) {
|
||||||
|
expandFields = req.query.expand.split(",")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("event_name" in req.query) {
|
||||||
|
const values = req.query.event_name.split(",")
|
||||||
|
selector.event_name = values.length > 1 ? values : values[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("resource_type" in req.query) {
|
||||||
|
const values = req.query.resource_type.split(",")
|
||||||
|
selector.resource_type = values.length > 1 ? values : values[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("resource_id" in req.query) {
|
||||||
|
const values = req.query.resource_id.split(",")
|
||||||
|
selector.resource_id = values.length > 1 ? values : values[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("to" in req.query) {
|
||||||
|
const values = req.query.to.split(",")
|
||||||
|
selector.to = values.length > 1 ? values : values[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!("include_resends" in req.query)) {
|
||||||
|
selector.parent_id = null
|
||||||
|
}
|
||||||
|
|
||||||
|
const listConfig = {
|
||||||
|
select: includeFields.length ? includeFields : defaultFields,
|
||||||
|
relations: expandFields.length ? expandFields : defaultRelations,
|
||||||
|
skip: offset,
|
||||||
|
take: limit,
|
||||||
|
order: { created_at: "DESC" },
|
||||||
|
}
|
||||||
|
|
||||||
|
const notifications = await notificationService.list(selector, listConfig)
|
||||||
|
|
||||||
|
const fields = [...listConfig.select, ...listConfig.relations]
|
||||||
|
const data = notifications.map((o) => _.pick(o, fields))
|
||||||
|
|
||||||
|
res.json({ notifications: data, offset, limit })
|
||||||
}
|
}
|
||||||
@@ -32,24 +32,20 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const notificationService = req.scope.resolve("notificationService")
|
||||||
const notificationService = req.scope.resolve("notificationService")
|
|
||||||
|
|
||||||
const config = {}
|
const config = {}
|
||||||
|
|
||||||
if (value.to) {
|
if (value.to) {
|
||||||
config.to = value.to
|
config.to = value.to
|
||||||
}
|
|
||||||
|
|
||||||
await notificationService.resend(id, config)
|
|
||||||
|
|
||||||
const notification = await notificationService.retrieve(id, {
|
|
||||||
select: defaultFields,
|
|
||||||
relations: defaultRelations,
|
|
||||||
})
|
|
||||||
|
|
||||||
res.json({ notification })
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await notificationService.resend(id, config)
|
||||||
|
|
||||||
|
const notification = await notificationService.retrieve(id, {
|
||||||
|
select: defaultFields,
|
||||||
|
relations: defaultRelations,
|
||||||
|
})
|
||||||
|
|
||||||
|
res.json({ notification })
|
||||||
}
|
}
|
||||||
@@ -39,17 +39,13 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
|
||||||
|
|
||||||
await productService.addOption(id, value.title)
|
await productService.addOption(id, value.title)
|
||||||
const product = await productService.retrieve(id, {
|
const product = await productService.retrieve(id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.json({ product })
|
res.json({ product })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -188,9 +188,7 @@ export default async (req, res) => {
|
|||||||
description: Validator.string().allow(""),
|
description: Validator.string().allow(""),
|
||||||
is_giftcard: Validator.boolean().default(false),
|
is_giftcard: Validator.boolean().default(false),
|
||||||
discountable: Validator.boolean().default(true),
|
discountable: Validator.boolean().default(true),
|
||||||
images: Validator.array()
|
images: Validator.array().items(Validator.string()).optional(),
|
||||||
.items(Validator.string())
|
|
||||||
.optional(),
|
|
||||||
thumbnail: Validator.string().optional(),
|
thumbnail: Validator.string().optional(),
|
||||||
handle: Validator.string().optional(),
|
handle: Validator.string().optional(),
|
||||||
status: Validator.string()
|
status: Validator.string()
|
||||||
@@ -203,9 +201,7 @@ export default async (req, res) => {
|
|||||||
})
|
})
|
||||||
.allow(null)
|
.allow(null)
|
||||||
.optional(),
|
.optional(),
|
||||||
collection_id: Validator.string()
|
collection_id: Validator.string().allow(null).optional(),
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
tags: Validator.array()
|
tags: Validator.array()
|
||||||
.items({
|
.items({
|
||||||
id: Validator.string().optional(),
|
id: Validator.string().optional(),
|
||||||
@@ -225,30 +221,13 @@ export default async (req, res) => {
|
|||||||
inventory_quantity: Validator.number().default(0),
|
inventory_quantity: Validator.number().default(0),
|
||||||
allow_backorder: Validator.boolean().optional(),
|
allow_backorder: Validator.boolean().optional(),
|
||||||
manage_inventory: Validator.boolean().optional(),
|
manage_inventory: Validator.boolean().optional(),
|
||||||
weight: Validator.number()
|
weight: Validator.number().allow(null).optional(),
|
||||||
.allow(null)
|
length: Validator.number().allow(null).optional(),
|
||||||
.optional(),
|
height: Validator.number().allow(null).optional(),
|
||||||
length: Validator.number()
|
width: Validator.number().allow(null).optional(),
|
||||||
.allow(null)
|
origin_country: Validator.string().optional().allow("").allow(null),
|
||||||
.optional(),
|
mid_code: Validator.string().optional().allow("").allow(null),
|
||||||
height: Validator.number()
|
material: Validator.string().optional().allow("").allow(null),
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
width: Validator.number()
|
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
origin_country: Validator.string()
|
|
||||||
.optional()
|
|
||||||
.allow("")
|
|
||||||
.allow(null),
|
|
||||||
mid_code: Validator.string()
|
|
||||||
.optional()
|
|
||||||
.allow("")
|
|
||||||
.allow(null),
|
|
||||||
material: Validator.string()
|
|
||||||
.optional()
|
|
||||||
.allow("")
|
|
||||||
.allow(null),
|
|
||||||
metadata: Validator.object().optional(),
|
metadata: Validator.object().optional(),
|
||||||
prices: Validator.array()
|
prices: Validator.array()
|
||||||
.items(
|
.items(
|
||||||
@@ -256,9 +235,7 @@ export default async (req, res) => {
|
|||||||
.keys({
|
.keys({
|
||||||
region_id: Validator.string(),
|
region_id: Validator.string(),
|
||||||
currency_code: Validator.string(),
|
currency_code: Validator.string(),
|
||||||
amount: Validator.number()
|
amount: Validator.number().integer().required(),
|
||||||
.integer()
|
|
||||||
.required(),
|
|
||||||
sale_amount: Validator.number().optional(),
|
sale_amount: Validator.number().optional(),
|
||||||
})
|
})
|
||||||
.xor("region_id", "currency_code")
|
.xor("region_id", "currency_code")
|
||||||
@@ -270,30 +247,14 @@ export default async (req, res) => {
|
|||||||
})
|
})
|
||||||
.default([]),
|
.default([]),
|
||||||
}),
|
}),
|
||||||
weight: Validator.number()
|
weight: Validator.number().allow(null).optional(),
|
||||||
.allow(null)
|
length: Validator.number().allow(null).optional(),
|
||||||
.optional(),
|
height: Validator.number().allow(null).optional(),
|
||||||
length: Validator.number()
|
width: Validator.number().allow(null).optional(),
|
||||||
.allow(null)
|
hs_code: Validator.string().optional().allow(""),
|
||||||
.optional(),
|
origin_country: Validator.string().optional().allow(""),
|
||||||
height: Validator.number()
|
mid_code: Validator.string().optional().allow(""),
|
||||||
.allow(null)
|
material: Validator.string().optional().allow(""),
|
||||||
.optional(),
|
|
||||||
width: Validator.number()
|
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
hs_code: Validator.string()
|
|
||||||
.optional()
|
|
||||||
.allow(""),
|
|
||||||
origin_country: Validator.string()
|
|
||||||
.optional()
|
|
||||||
.allow(""),
|
|
||||||
mid_code: Validator.string()
|
|
||||||
.optional()
|
|
||||||
.allow(""),
|
|
||||||
material: Validator.string()
|
|
||||||
.optional()
|
|
||||||
.allow(""),
|
|
||||||
metadata: Validator.object().optional(),
|
metadata: Validator.object().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -302,66 +263,64 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
const productVariantService = req.scope.resolve("productVariantService")
|
||||||
const productVariantService = req.scope.resolve("productVariantService")
|
const shippingProfileService = req.scope.resolve("shippingProfileService")
|
||||||
const shippingProfileService = req.scope.resolve("shippingProfileService")
|
|
||||||
|
|
||||||
const entityManager = req.scope.resolve("manager")
|
const entityManager = req.scope.resolve("manager")
|
||||||
|
|
||||||
let newProduct
|
let newProduct
|
||||||
await entityManager.transaction(async manager => {
|
await entityManager.transaction(async (manager) => {
|
||||||
const { variants } = value
|
const { variants } = value
|
||||||
delete value.variants
|
delete value.variants
|
||||||
|
|
||||||
if (!value.thumbnail && value.images && value.images.length) {
|
if (!value.thumbnail && value.images && value.images.length) {
|
||||||
value.thumbnail = value.images[0]
|
value.thumbnail = value.images[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
let shippingProfile
|
||||||
|
// Get default shipping profile
|
||||||
|
if (value.is_giftcard) {
|
||||||
|
shippingProfile = await shippingProfileService.retrieveGiftCardDefault()
|
||||||
|
} else {
|
||||||
|
shippingProfile = await shippingProfileService.retrieveDefault()
|
||||||
|
}
|
||||||
|
|
||||||
|
newProduct = await productService
|
||||||
|
.withTransaction(manager)
|
||||||
|
.create({ ...value, profile_id: shippingProfile.id })
|
||||||
|
|
||||||
|
if (variants) {
|
||||||
|
for (const [i, variant] of variants.entries()) {
|
||||||
|
variant.variant_rank = i
|
||||||
}
|
}
|
||||||
|
|
||||||
let shippingProfile
|
const optionIds = value.options.map(
|
||||||
// Get default shipping profile
|
(o) => newProduct.options.find((newO) => newO.title === o.title).id
|
||||||
if (value.is_giftcard) {
|
)
|
||||||
shippingProfile = await shippingProfileService.retrieveGiftCardDefault()
|
|
||||||
} else {
|
|
||||||
shippingProfile = await shippingProfileService.retrieveDefault()
|
|
||||||
}
|
|
||||||
|
|
||||||
newProduct = await productService
|
await Promise.all(
|
||||||
.withTransaction(manager)
|
variants.map(async (v) => {
|
||||||
.create({ ...value, profile_id: shippingProfile.id })
|
const variant = {
|
||||||
|
...v,
|
||||||
|
options: v.options.map((o, index) => ({
|
||||||
|
...o,
|
||||||
|
option_id: optionIds[index],
|
||||||
|
})),
|
||||||
|
}
|
||||||
|
|
||||||
if (variants) {
|
await productVariantService
|
||||||
for (const [i, variant] of variants.entries()) variant.variant_rank = i
|
.withTransaction(manager)
|
||||||
|
.create(newProduct.id, variant)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const optionIds = value.options.map(
|
const product = await productService.retrieve(newProduct.id, {
|
||||||
o => newProduct.options.find(newO => newO.title === o.title).id
|
select: defaultFields,
|
||||||
)
|
relations: defaultRelations,
|
||||||
|
})
|
||||||
|
|
||||||
await Promise.all(
|
res.json({ product })
|
||||||
variants.map(async v => {
|
|
||||||
const variant = {
|
|
||||||
...v,
|
|
||||||
options: v.options.map((o, index) => ({
|
|
||||||
...o,
|
|
||||||
option_id: optionIds[index],
|
|
||||||
})),
|
|
||||||
}
|
|
||||||
|
|
||||||
await productVariantService
|
|
||||||
.withTransaction(manager)
|
|
||||||
.create(newProduct.id, variant)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const product = await productService.retrieve(newProduct.id, {
|
|
||||||
select: defaultFields,
|
|
||||||
relations: defaultRelations,
|
|
||||||
})
|
|
||||||
|
|
||||||
res.json({ product })
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -115,18 +115,10 @@ export default async (req, res) => {
|
|||||||
inventory_quantity: Validator.number().default(0),
|
inventory_quantity: Validator.number().default(0),
|
||||||
allow_backorder: Validator.boolean().optional(),
|
allow_backorder: Validator.boolean().optional(),
|
||||||
manage_inventory: Validator.boolean().optional(),
|
manage_inventory: Validator.boolean().optional(),
|
||||||
weight: Validator.number()
|
weight: Validator.number().allow(null).optional(),
|
||||||
.allow(null)
|
length: Validator.number().allow(null).optional(),
|
||||||
.optional(),
|
height: Validator.number().allow(null).optional(),
|
||||||
length: Validator.number()
|
width: Validator.number().allow(null).optional(),
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
height: Validator.number()
|
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
width: Validator.number()
|
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
origin_country: Validator.string().allow(""),
|
origin_country: Validator.string().allow(""),
|
||||||
mid_code: Validator.string().allow(""),
|
mid_code: Validator.string().allow(""),
|
||||||
material: Validator.string().allow(""),
|
material: Validator.string().allow(""),
|
||||||
@@ -137,9 +129,7 @@ export default async (req, res) => {
|
|||||||
.keys({
|
.keys({
|
||||||
region_id: Validator.string().empty(null),
|
region_id: Validator.string().empty(null),
|
||||||
currency_code: Validator.string().required(),
|
currency_code: Validator.string().required(),
|
||||||
amount: Validator.number()
|
amount: Validator.number().integer().required(),
|
||||||
.integer()
|
|
||||||
.required(),
|
|
||||||
sale_amount: Validator.number().optional(),
|
sale_amount: Validator.number().optional(),
|
||||||
})
|
})
|
||||||
.xor("region_id", "currency_code")
|
.xor("region_id", "currency_code")
|
||||||
@@ -158,19 +148,15 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const productVariantService = req.scope.resolve("productVariantService")
|
||||||
const productVariantService = req.scope.resolve("productVariantService")
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
|
||||||
|
|
||||||
await productVariantService.create(id, value)
|
await productVariantService.create(id, value)
|
||||||
|
|
||||||
const product = await productService.retrieve(id, {
|
const product = await productService.retrieve(id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.json({ product })
|
res.json({ product })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -31,21 +31,17 @@ import { defaultRelations, defaultFields } from "."
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { id, option_id } = req.params
|
const { id, option_id } = req.params
|
||||||
|
|
||||||
try {
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
await productService.deleteOption(id, option_id)
|
||||||
await productService.deleteOption(id, option_id)
|
const data = await productService.retrieve(id, {
|
||||||
const data = await productService.retrieve(id, {
|
select: defaultFields,
|
||||||
select: defaultFields,
|
relations: defaultRelations,
|
||||||
relations: defaultRelations,
|
})
|
||||||
})
|
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
option_id,
|
option_id,
|
||||||
object: "option",
|
object: "option",
|
||||||
deleted: true,
|
deleted: true,
|
||||||
product: data,
|
product: data,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -26,15 +26,11 @@
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
try {
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
await productService.delete(id)
|
||||||
await productService.delete(id)
|
res.json({
|
||||||
res.json({
|
id,
|
||||||
id,
|
object: "product",
|
||||||
object: "product",
|
deleted: true,
|
||||||
deleted: true,
|
})
|
||||||
})
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -29,24 +29,20 @@ import { defaultRelations, defaultFields } from "."
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { id, variant_id } = req.params
|
const { id, variant_id } = req.params
|
||||||
|
|
||||||
try {
|
const productVariantService = req.scope.resolve("productVariantService")
|
||||||
const productVariantService = req.scope.resolve("productVariantService")
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
|
||||||
|
|
||||||
await productVariantService.delete(variant_id)
|
await productVariantService.delete(variant_id)
|
||||||
|
|
||||||
const data = await productService.retrieve(id, {
|
const data = await productService.retrieve(id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
variant_id,
|
variant_id,
|
||||||
object: "product-variant",
|
object: "product-variant",
|
||||||
deleted: true,
|
deleted: true,
|
||||||
product: data,
|
product: data,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ import middlewares from "../../../middlewares"
|
|||||||
|
|
||||||
const route = Router()
|
const route = Router()
|
||||||
|
|
||||||
export default app => {
|
export default (app) => {
|
||||||
app.use("/products", route)
|
app.use("/products", route)
|
||||||
|
|
||||||
route.post("/", middlewares.wrap(require("./create-product").default))
|
route.post("/", middlewares.wrap(require("./create-product").default))
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import _ from "lodash"
|
|
||||||
import { MedusaError, Validator } from "medusa-core-utils"
|
import { MedusaError, Validator } from "medusa-core-utils"
|
||||||
import { defaultFields, defaultRelations, filterableFields } from "./"
|
import { defaultFields, defaultRelations, filterableFields } from "./"
|
||||||
|
|
||||||
@@ -42,52 +41,48 @@ export default async (req, res) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
|
||||||
|
|
||||||
const limit = parseInt(req.query.limit) || 50
|
const limit = parseInt(req.query.limit) || 50
|
||||||
const offset = parseInt(req.query.offset) || 0
|
const offset = parseInt(req.query.offset) || 0
|
||||||
|
|
||||||
const selector = {}
|
const selector = {}
|
||||||
|
|
||||||
if ("q" in req.query) {
|
if ("q" in req.query) {
|
||||||
selector.q = req.query.q
|
selector.q = req.query.q
|
||||||
}
|
|
||||||
|
|
||||||
let includeFields = []
|
|
||||||
if ("fields" in req.query) {
|
|
||||||
includeFields = req.query.fields.split(",")
|
|
||||||
}
|
|
||||||
|
|
||||||
let expandFields = []
|
|
||||||
if ("expand" in req.query) {
|
|
||||||
expandFields = req.query.expand.split(",")
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const k of filterableFields) {
|
|
||||||
if (k in value) {
|
|
||||||
selector[k] = value[k]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selector.status?.indexOf("null") > -1) {
|
|
||||||
selector.status.splice(selector.status.indexOf("null"), 1)
|
|
||||||
if (selector.status.length === 0) {
|
|
||||||
delete selector.status
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const listConfig = {
|
|
||||||
select: includeFields.length ? includeFields : defaultFields,
|
|
||||||
relations: expandFields.length ? expandFields : defaultRelations,
|
|
||||||
skip: offset,
|
|
||||||
take: limit,
|
|
||||||
}
|
|
||||||
|
|
||||||
let products = await productService.list(selector, listConfig)
|
|
||||||
|
|
||||||
res.json({ products, count: products.length, offset, limit })
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let includeFields = []
|
||||||
|
if ("fields" in req.query) {
|
||||||
|
includeFields = req.query.fields.split(",")
|
||||||
|
}
|
||||||
|
|
||||||
|
let expandFields = []
|
||||||
|
if ("expand" in req.query) {
|
||||||
|
expandFields = req.query.expand.split(",")
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const k of filterableFields) {
|
||||||
|
if (k in value) {
|
||||||
|
selector[k] = value[k]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selector.status?.indexOf("null") > -1) {
|
||||||
|
selector.status.splice(selector.status.indexOf("null"), 1)
|
||||||
|
if (selector.status.length === 0) {
|
||||||
|
delete selector.status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const listConfig = {
|
||||||
|
select: includeFields.length ? includeFields : defaultFields,
|
||||||
|
relations: expandFields.length ? expandFields : defaultRelations,
|
||||||
|
skip: offset,
|
||||||
|
take: limit,
|
||||||
|
}
|
||||||
|
|
||||||
|
const products = await productService.list(selector, listConfig)
|
||||||
|
|
||||||
|
res.json({ products, count: products.length, offset, limit })
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
try {
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
|
||||||
|
|
||||||
const tags = await productService.listTagsByUsage()
|
const tags = await productService.listTagsByUsage()
|
||||||
|
|
||||||
res.json({ tags })
|
res.json({ tags })
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -18,13 +18,9 @@
|
|||||||
* $ref: "#/components/schemas/product_type"
|
* $ref: "#/components/schemas/product_type"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
try {
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
|
||||||
|
|
||||||
const types = await productService.listTypes()
|
const types = await productService.listTypes()
|
||||||
|
|
||||||
res.json({ types })
|
res.json({ types })
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -14,19 +14,15 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
await productService.update(id, {
|
||||||
await productService.update(id, {
|
metadata: { [value.key]: value.value },
|
||||||
metadata: { [value.key]: value.value },
|
})
|
||||||
})
|
|
||||||
|
|
||||||
const product = await productService.retrieve(id, {
|
const product = await productService.retrieve(id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ product })
|
res.status(200).json({ product })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -41,18 +41,14 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
|
||||||
|
|
||||||
await productService.updateOption(id, option_id, value)
|
await productService.updateOption(id, option_id, value)
|
||||||
|
|
||||||
const product = await productService.retrieve(id, {
|
const product = await productService.retrieve(id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.json({ product })
|
res.json({ product })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -188,9 +188,7 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const schema = Validator.object().keys({
|
const schema = Validator.object().keys({
|
||||||
title: Validator.string().optional(),
|
title: Validator.string().optional(),
|
||||||
subtitle: Validator.string()
|
subtitle: Validator.string().optional().allow(null, ""),
|
||||||
.optional()
|
|
||||||
.allow(null, ""),
|
|
||||||
description: Validator.string().optional(),
|
description: Validator.string().optional(),
|
||||||
discountable: Validator.boolean().optional(),
|
discountable: Validator.boolean().optional(),
|
||||||
status: Validator.string().valid(
|
status: Validator.string().valid(
|
||||||
@@ -206,9 +204,7 @@ export default async (req, res) => {
|
|||||||
})
|
})
|
||||||
.allow(null)
|
.allow(null)
|
||||||
.optional(),
|
.optional(),
|
||||||
collection_id: Validator.string()
|
collection_id: Validator.string().allow(null).optional(),
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
tags: Validator.array()
|
tags: Validator.array()
|
||||||
.items({
|
.items({
|
||||||
id: Validator.string().optional(),
|
id: Validator.string().optional(),
|
||||||
@@ -216,26 +212,15 @@ export default async (req, res) => {
|
|||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
handle: Validator.string().optional(),
|
handle: Validator.string().optional(),
|
||||||
weight: Validator.number()
|
weight: Validator.number().allow(null).optional(),
|
||||||
.allow(null)
|
length: Validator.number().allow(null).optional(),
|
||||||
.optional(),
|
height: Validator.number().allow(null).optional(),
|
||||||
length: Validator.number()
|
width: Validator.number().allow(null).optional(),
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
height: Validator.number()
|
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
width: Validator.number()
|
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
origin_country: Validator.string().allow(null, ""),
|
origin_country: Validator.string().allow(null, ""),
|
||||||
hs_code: Validator.string().allow(null, ""),
|
hs_code: Validator.string().allow(null, ""),
|
||||||
mid_code: Validator.string().allow(null, ""),
|
mid_code: Validator.string().allow(null, ""),
|
||||||
material: Validator.string().allow(null, ""),
|
material: Validator.string().allow(null, ""),
|
||||||
images: Validator.array()
|
images: Validator.array().items(Validator.string()).optional().optional(),
|
||||||
.items(Validator.string())
|
|
||||||
.optional()
|
|
||||||
.optional(),
|
|
||||||
thumbnail: Validator.string().optional(),
|
thumbnail: Validator.string().optional(),
|
||||||
variants: Validator.array()
|
variants: Validator.array()
|
||||||
.items({
|
.items({
|
||||||
@@ -249,9 +234,7 @@ export default async (req, res) => {
|
|||||||
.keys({
|
.keys({
|
||||||
region_id: Validator.string(),
|
region_id: Validator.string(),
|
||||||
currency_code: Validator.string(),
|
currency_code: Validator.string(),
|
||||||
amount: Validator.number()
|
amount: Validator.number().integer().required(),
|
||||||
.integer()
|
|
||||||
.required(),
|
|
||||||
sale_amount: Validator.number().optional(),
|
sale_amount: Validator.number().optional(),
|
||||||
})
|
})
|
||||||
.xor("region_id", "currency_code")
|
.xor("region_id", "currency_code")
|
||||||
@@ -266,21 +249,11 @@ export default async (req, res) => {
|
|||||||
inventory_quantity: Validator.number().allow(null),
|
inventory_quantity: Validator.number().allow(null),
|
||||||
allow_backorder: Validator.boolean().allow(null),
|
allow_backorder: Validator.boolean().allow(null),
|
||||||
manage_inventory: Validator.boolean().allow(null),
|
manage_inventory: Validator.boolean().allow(null),
|
||||||
weight: Validator.number()
|
weight: Validator.number().allow(null).optional(),
|
||||||
.allow(null)
|
length: Validator.number().allow(null).optional(),
|
||||||
.optional(),
|
height: Validator.number().allow(null).optional(),
|
||||||
length: Validator.number()
|
width: Validator.number().allow(null).optional(),
|
||||||
.allow(null)
|
hs_code: Validator.string().optional().allow(null, ""),
|
||||||
.optional(),
|
|
||||||
height: Validator.number()
|
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
width: Validator.number()
|
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
hs_code: Validator.string()
|
|
||||||
.optional()
|
|
||||||
.allow(null, ""),
|
|
||||||
origin_country: Validator.string().allow(null, ""),
|
origin_country: Validator.string().allow(null, ""),
|
||||||
mid_code: Validator.string().allow(null, ""),
|
mid_code: Validator.string().allow(null, ""),
|
||||||
material: Validator.string().allow(null, ""),
|
material: Validator.string().allow(null, ""),
|
||||||
@@ -295,21 +268,17 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
const entityManager = req.scope.resolve("manager")
|
||||||
const entityManager = req.scope.resolve("manager")
|
|
||||||
|
|
||||||
await entityManager.transaction(async manager => {
|
await entityManager.transaction(async (manager) => {
|
||||||
await productService.withTransaction(manager).update(id, value)
|
await productService.withTransaction(manager).update(id, value)
|
||||||
})
|
})
|
||||||
|
|
||||||
const product = await productService.retrieve(id, {
|
const product = await productService.retrieve(id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.json({ product })
|
res.json({ product })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import _ from "lodash"
|
|
||||||
import { MedusaError, Validator } from "medusa-core-utils"
|
import { MedusaError, Validator } from "medusa-core-utils"
|
||||||
import { defaultFields, defaultRelations } from "./"
|
import { defaultFields, defaultRelations } from "./"
|
||||||
|
|
||||||
@@ -116,9 +115,7 @@ export default async (req, res) => {
|
|||||||
.keys({
|
.keys({
|
||||||
region_id: Validator.string().empty(null),
|
region_id: Validator.string().empty(null),
|
||||||
currency_code: Validator.string(),
|
currency_code: Validator.string(),
|
||||||
amount: Validator.number()
|
amount: Validator.number().integer().required(),
|
||||||
.integer()
|
|
||||||
.required(),
|
|
||||||
sale_amount: Validator.number().optional(),
|
sale_amount: Validator.number().optional(),
|
||||||
})
|
})
|
||||||
.xor("region_id", "currency_code")
|
.xor("region_id", "currency_code")
|
||||||
@@ -133,30 +130,14 @@ export default async (req, res) => {
|
|||||||
inventory_quantity: Validator.number().optional(),
|
inventory_quantity: Validator.number().optional(),
|
||||||
allow_backorder: Validator.boolean().optional(),
|
allow_backorder: Validator.boolean().optional(),
|
||||||
manage_inventory: Validator.boolean().optional(),
|
manage_inventory: Validator.boolean().optional(),
|
||||||
weight: Validator.number()
|
weight: Validator.number().allow(null).optional(),
|
||||||
.allow(null)
|
length: Validator.number().allow(null).optional(),
|
||||||
.optional(),
|
height: Validator.number().allow(null).optional(),
|
||||||
length: Validator.number()
|
width: Validator.number().allow(null).optional(),
|
||||||
.allow(null)
|
hs_code: Validator.string().optional().allow(null, ""),
|
||||||
.optional(),
|
origin_country: Validator.string().optional().allow(null, ""),
|
||||||
height: Validator.number()
|
mid_code: Validator.string().optional().allow(null, ""),
|
||||||
.allow(null)
|
material: Validator.string().optional().allow(null, ""),
|
||||||
.optional(),
|
|
||||||
width: Validator.number()
|
|
||||||
.allow(null)
|
|
||||||
.optional(),
|
|
||||||
hs_code: Validator.string()
|
|
||||||
.optional()
|
|
||||||
.allow(null, ""),
|
|
||||||
origin_country: Validator.string()
|
|
||||||
.optional()
|
|
||||||
.allow(null, ""),
|
|
||||||
mid_code: Validator.string()
|
|
||||||
.optional()
|
|
||||||
.allow(null, ""),
|
|
||||||
material: Validator.string()
|
|
||||||
.optional()
|
|
||||||
.allow(null, ""),
|
|
||||||
metadata: Validator.object().optional(),
|
metadata: Validator.object().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -165,18 +146,15 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
const productVariantService = req.scope.resolve("productVariantService")
|
||||||
const productVariantService = req.scope.resolve("productVariantService")
|
|
||||||
|
|
||||||
await productVariantService.update(variant_id, value)
|
await productVariantService.update(variant_id, value)
|
||||||
|
|
||||||
const product = await productService.retrieve(id, {
|
const product = await productService.retrieve(id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
res.json({ product })
|
|
||||||
} catch (err) {
|
res.json({ product })
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -39,17 +39,13 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
await regionService.addCountry(region_id, value.country_code)
|
||||||
await regionService.addCountry(region_id, value.country_code)
|
|
||||||
|
|
||||||
const region = await regionService.retrieve(region_id, {
|
const region = await regionService.retrieve(region_id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ region })
|
res.status(200).json({ region })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -39,16 +39,12 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
await regionService.addFulfillmentProvider(region_id, value.provider_id)
|
||||||
await regionService.addFulfillmentProvider(region_id, value.provider_id)
|
|
||||||
|
|
||||||
const data = await regionService.retrieve(region_id, {
|
const data = await regionService.retrieve(region_id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
res.status(200).json({ region: data })
|
res.status(200).json({ region: data })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -39,16 +39,12 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
await regionService.addPaymentProvider(region_id, value.provider_id)
|
||||||
await regionService.addPaymentProvider(region_id, value.provider_id)
|
|
||||||
|
|
||||||
const data = await regionService.retrieve(region_id, {
|
const data = await regionService.retrieve(region_id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
res.status(200).json({ region: data })
|
res.status(200).json({ region: data })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -66,17 +66,13 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
const result = await regionService.create(value)
|
||||||
const result = await regionService.create(value)
|
|
||||||
|
|
||||||
const region = await regionService.retrieve(result.id, {
|
const region = await regionService.retrieve(result.id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ region })
|
res.status(200).json({ region })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -23,17 +23,13 @@ import { defaultRelations, defaultFields } from "./"
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { id, key } = req.params
|
const { id, key } = req.params
|
||||||
|
|
||||||
try {
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
await regionService.deleteMetadata(id, key)
|
||||||
await regionService.deleteMetadata(id, key)
|
|
||||||
|
|
||||||
const region = await regionService.retrieve(id, {
|
const region = await regionService.retrieve(id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ region })
|
res.status(200).json({ region })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
import { MedusaError, Validator } from "medusa-core-utils"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [delete] /regions/{id}
|
* @oas [delete] /regions/{id}
|
||||||
* operationId: "DeleteRegionsRegion"
|
* operationId: "DeleteRegionsRegion"
|
||||||
@@ -27,16 +25,12 @@ import { MedusaError, Validator } from "medusa-core-utils"
|
|||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { region_id } = req.params
|
const { region_id } = req.params
|
||||||
try {
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
await regionService.delete(region_id)
|
||||||
await regionService.delete(region_id)
|
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
id: region_id,
|
id: region_id,
|
||||||
object: "region",
|
object: "region",
|
||||||
deleted: true,
|
deleted: true,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -22,25 +22,21 @@
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { region_id } = req.params
|
const { region_id } = req.params
|
||||||
|
|
||||||
try {
|
const fulfillmentProviderService = req.scope.resolve(
|
||||||
const fulfillmentProviderService = req.scope.resolve(
|
"fulfillmentProviderService"
|
||||||
"fulfillmentProviderService"
|
)
|
||||||
)
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
const region = await regionService.retrieve(region_id, {
|
||||||
const region = await regionService.retrieve(region_id, {
|
relations: ["fulfillment_providers"],
|
||||||
relations: ["fulfillment_providers"],
|
})
|
||||||
})
|
|
||||||
|
|
||||||
const fpsIds = region.fulfillment_providers.map(fp => fp.id) || []
|
const fpsIds = region.fulfillment_providers.map((fp) => fp.id) || []
|
||||||
|
|
||||||
const options = await fulfillmentProviderService.listFulfillmentOptions(
|
const options = await fulfillmentProviderService.listFulfillmentOptions(
|
||||||
fpsIds
|
fpsIds
|
||||||
)
|
)
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
fulfillment_options: options,
|
fulfillment_options: options,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { MedusaError, Validator } from "medusa-core-utils"
|
|
||||||
import { defaultRelations, defaultFields } from "./"
|
import { defaultRelations, defaultFields } from "./"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,15 +21,11 @@ import { defaultRelations, defaultFields } from "./"
|
|||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { region_id } = req.params
|
const { region_id } = req.params
|
||||||
try {
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
const data = await regionService.retrieve(region_id, {
|
||||||
const data = await regionService.retrieve(region_id, {
|
select: defaultFields,
|
||||||
select: defaultFields,
|
relations: defaultRelations,
|
||||||
relations: defaultRelations,
|
})
|
||||||
})
|
|
||||||
|
|
||||||
res.status(200).json({ region: data })
|
res.status(200).json({ region: data })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ import middlewares from "../../../middlewares"
|
|||||||
|
|
||||||
const route = Router()
|
const route = Router()
|
||||||
|
|
||||||
export default app => {
|
export default (app) => {
|
||||||
app.use("/regions", route)
|
app.use("/regions", route)
|
||||||
|
|
||||||
route.get("/", middlewares.wrap(require("./list-regions").default))
|
route.get("/", middlewares.wrap(require("./list-regions").default))
|
||||||
|
|||||||
@@ -20,25 +20,21 @@ import { defaultFields, defaultRelations } from "./"
|
|||||||
* $ref: "#/components/schemas/region"
|
* $ref: "#/components/schemas/region"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
try {
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
|
||||||
|
|
||||||
const limit = parseInt(req.query.limit) || 50
|
const limit = parseInt(req.query.limit) || 50
|
||||||
const offset = parseInt(req.query.offset) || 0
|
const offset = parseInt(req.query.offset) || 0
|
||||||
|
|
||||||
const selector = {}
|
const selector = {}
|
||||||
|
|
||||||
const listConfig = {
|
const listConfig = {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
skip: offset,
|
skip: offset,
|
||||||
take: limit,
|
take: limit,
|
||||||
}
|
|
||||||
|
|
||||||
let regions = await regionService.list(selector, listConfig)
|
|
||||||
|
|
||||||
res.json({ regions, count: regions.length, offset, limit })
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const regions = await regionService.list(selector, listConfig)
|
||||||
|
|
||||||
|
res.json({ regions, count: regions.length, offset, limit })
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { MedusaError, Validator } from "medusa-core-utils"
|
|
||||||
import { defaultRelations, defaultFields } from "./"
|
import { defaultRelations, defaultFields } from "./"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,17 +22,13 @@ import { defaultRelations, defaultFields } from "./"
|
|||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { region_id, country_code } = req.params
|
const { region_id, country_code } = req.params
|
||||||
try {
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
await regionService.removeCountry(region_id, country_code)
|
||||||
await regionService.removeCountry(region_id, country_code)
|
|
||||||
|
|
||||||
const region = await regionService.retrieve(region_id, {
|
const region = await regionService.retrieve(region_id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.json({ region })
|
res.json({ region })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { MedusaError, Validator } from "medusa-core-utils"
|
|
||||||
import { defaultRelations, defaultFields } from "./"
|
import { defaultRelations, defaultFields } from "./"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,18 +22,14 @@ import { defaultRelations, defaultFields } from "./"
|
|||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { region_id, provider_id } = req.params
|
const { region_id, provider_id } = req.params
|
||||||
try {
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
|
||||||
|
|
||||||
await regionService.removeFulfillmentProvider(region_id, provider_id)
|
await regionService.removeFulfillmentProvider(region_id, provider_id)
|
||||||
|
|
||||||
const region = await regionService.retrieve(region_id, {
|
const region = await regionService.retrieve(region_id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.json({ region })
|
res.json({ region })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { MedusaError, Validator } from "medusa-core-utils"
|
|
||||||
import { defaultRelations, defaultFields } from "./"
|
import { defaultRelations, defaultFields } from "./"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,17 +22,13 @@ import { defaultRelations, defaultFields } from "./"
|
|||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { region_id, provider_id } = req.params
|
const { region_id, provider_id } = req.params
|
||||||
try {
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
await regionService.removePaymentProvider(region_id, provider_id)
|
||||||
await regionService.removePaymentProvider(region_id, provider_id)
|
|
||||||
|
|
||||||
const region = await regionService.retrieve(region_id, {
|
const region = await regionService.retrieve(region_id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.json({ region })
|
res.json({ region })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { MedusaError, Validator } from "medusa-core-utils"
|
import { MedusaError, Validator } from "medusa-core-utils"
|
||||||
|
import { defaultFields, defaultRelations } from "."
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
@@ -13,17 +14,13 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
await regionService.setMetadata(id, value.key, value.value)
|
||||||
await regionService.setMetadata(id, value.key, value.value)
|
|
||||||
|
|
||||||
const region = await regionService.retrieve(region_id, {
|
const region = await regionService.retrieve(id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ region })
|
res.status(200).json({ region })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -70,16 +70,12 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const regionService = req.scope.resolve("regionService")
|
||||||
const regionService = req.scope.resolve("regionService")
|
await regionService.update(region_id, value)
|
||||||
await regionService.update(region_id, value)
|
const region = await regionService.retrieve(region_id, {
|
||||||
const region = await regionService.retrieve(region_id, {
|
select: defaultFields,
|
||||||
select: defaultFields,
|
relations: defaultRelations,
|
||||||
relations: defaultRelations,
|
})
|
||||||
})
|
|
||||||
|
|
||||||
res.status(200).json({ region })
|
res.status(200).json({ region })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -72,16 +72,12 @@ export default async (req, res) => {
|
|||||||
profile_id: Validator.string(),
|
profile_id: Validator.string(),
|
||||||
data: Validator.object().required(),
|
data: Validator.object().required(),
|
||||||
price_type: Validator.string().required(),
|
price_type: Validator.string().required(),
|
||||||
amount: Validator.number()
|
amount: Validator.number().integer().optional(),
|
||||||
.integer()
|
|
||||||
.optional(),
|
|
||||||
requirements: Validator.array()
|
requirements: Validator.array()
|
||||||
.items(
|
.items(
|
||||||
Validator.object({
|
Validator.object({
|
||||||
type: Validator.string().required(),
|
type: Validator.string().required(),
|
||||||
amount: Validator.number()
|
amount: Validator.number().integer().required(),
|
||||||
.integer()
|
|
||||||
.required(),
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.optional(),
|
.optional(),
|
||||||
@@ -94,24 +90,20 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const optionService = req.scope.resolve("shippingOptionService")
|
||||||
const optionService = req.scope.resolve("shippingOptionService")
|
const shippingProfileService = req.scope.resolve("shippingProfileService")
|
||||||
const shippingProfileService = req.scope.resolve("shippingProfileService")
|
|
||||||
|
|
||||||
// Add to default shipping profile
|
// Add to default shipping profile
|
||||||
if (!value.profile_id) {
|
if (!value.profile_id) {
|
||||||
const { id } = await shippingProfileService.retrieveDefault()
|
const { id } = await shippingProfileService.retrieveDefault()
|
||||||
value.profile_id = id
|
value.profile_id = id
|
||||||
}
|
|
||||||
|
|
||||||
const result = await optionService.create(value)
|
|
||||||
const data = await optionService.retrieve(result.id, {
|
|
||||||
select: defaultFields,
|
|
||||||
relations: defaultRelations,
|
|
||||||
})
|
|
||||||
|
|
||||||
res.status(200).json({ shipping_option: data })
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const result = await optionService.create(value)
|
||||||
|
const data = await optionService.retrieve(result.id, {
|
||||||
|
select: defaultFields,
|
||||||
|
relations: defaultRelations,
|
||||||
|
})
|
||||||
|
|
||||||
|
res.status(200).json({ shipping_option: data })
|
||||||
}
|
}
|
||||||
@@ -25,17 +25,13 @@
|
|||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { option_id } = req.params
|
const { option_id } = req.params
|
||||||
try {
|
const optionService = req.scope.resolve("shippingOptionService")
|
||||||
const optionService = req.scope.resolve("shippingOptionService")
|
|
||||||
|
|
||||||
await optionService.delete(option_id)
|
await optionService.delete(option_id)
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
id: option_id,
|
id: option_id,
|
||||||
object: "shipping-option",
|
object: "shipping-option",
|
||||||
deleted: true,
|
deleted: true,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -19,12 +19,8 @@
|
|||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { option_id } = req.params
|
const { option_id } = req.params
|
||||||
try {
|
const optionService = req.scope.resolve("shippingOptionService")
|
||||||
const optionService = req.scope.resolve("shippingOptionService")
|
const data = await optionService.retrieve(option_id)
|
||||||
const data = await optionService.retrieve(option_id)
|
|
||||||
|
|
||||||
res.status(200).json({ shipping_option: data })
|
res.status(200).json({ shipping_option: data })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ import middlewares from "../../../middlewares"
|
|||||||
|
|
||||||
const route = Router()
|
const route = Router()
|
||||||
|
|
||||||
export default app => {
|
export default (app) => {
|
||||||
app.use("/shipping-options", route)
|
app.use("/shipping-options", route)
|
||||||
|
|
||||||
route.get("/", middlewares.wrap(require("./list-shipping-options").default))
|
route.get("/", middlewares.wrap(require("./list-shipping-options").default))
|
||||||
|
|||||||
@@ -21,17 +21,13 @@ import { defaultFields, defaultRelations } from "./"
|
|||||||
* $ref: "#/components/schemas/shipping_option"
|
* $ref: "#/components/schemas/shipping_option"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
try {
|
const query = _.pick(req.query, ["region_id", "is_return", "admin_only"])
|
||||||
const query = _.pick(req.query, ["region_id", "is_return", "admin_only"])
|
|
||||||
|
|
||||||
const optionService = req.scope.resolve("shippingOptionService")
|
const optionService = req.scope.resolve("shippingOptionService")
|
||||||
const data = await optionService.list(query, {
|
const data = await optionService.list(query, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ shipping_options: data })
|
res.status(200).json({ shipping_options: data })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import _ from "lodash"
|
|
||||||
import { MedusaError, Validator } from "medusa-core-utils"
|
import { MedusaError, Validator } from "medusa-core-utils"
|
||||||
import { defaultFields, defaultRelations } from "./"
|
import { defaultFields, defaultRelations } from "./"
|
||||||
|
|
||||||
@@ -50,17 +49,13 @@ export default async (req, res) => {
|
|||||||
const { option_id } = req.params
|
const { option_id } = req.params
|
||||||
const schema = Validator.object().keys({
|
const schema = Validator.object().keys({
|
||||||
name: Validator.string().optional(),
|
name: Validator.string().optional(),
|
||||||
amount: Validator.number()
|
amount: Validator.number().integer().optional(),
|
||||||
.integer()
|
|
||||||
.optional(),
|
|
||||||
requirements: Validator.array()
|
requirements: Validator.array()
|
||||||
.items(
|
.items(
|
||||||
Validator.object({
|
Validator.object({
|
||||||
id: Validator.string().optional(),
|
id: Validator.string().optional(),
|
||||||
type: Validator.string().required(),
|
type: Validator.string().required(),
|
||||||
amount: Validator.number()
|
amount: Validator.number().integer().required(),
|
||||||
.integer()
|
|
||||||
.required(),
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.optional(),
|
.optional(),
|
||||||
@@ -73,18 +68,14 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const optionService = req.scope.resolve("shippingOptionService")
|
||||||
const optionService = req.scope.resolve("shippingOptionService")
|
|
||||||
|
|
||||||
await optionService.update(option_id, value)
|
await optionService.update(option_id, value)
|
||||||
|
|
||||||
const data = await optionService.retrieve(option_id, {
|
const data = await optionService.retrieve(option_id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ shipping_option: data })
|
res.status(200).json({ shipping_option: data })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -22,16 +22,12 @@ import { defaultFields, defaultRelations } from "./"
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
try {
|
const swapService = req.scope.resolve("swapService")
|
||||||
const swapService = req.scope.resolve("swapService")
|
|
||||||
|
|
||||||
const swap = await swapService.retrieve(id, {
|
const swap = await swapService.retrieve(id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.json({ swap })
|
res.json({ swap })
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ import middlewares from "../../../middlewares"
|
|||||||
|
|
||||||
const route = Router()
|
const route = Router()
|
||||||
|
|
||||||
export default app => {
|
export default (app) => {
|
||||||
app.use("/swaps", route)
|
app.use("/swaps", route)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import _ from "lodash"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [get] /swaps
|
* @oas [get] /swaps
|
||||||
* operationId: "GetSwaps"
|
* operationId: "GetSwaps"
|
||||||
@@ -20,24 +18,20 @@ import _ from "lodash"
|
|||||||
* $ref: "#/components/schemas/swap"
|
* $ref: "#/components/schemas/swap"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
try {
|
const swapService = req.scope.resolve("swapService")
|
||||||
const swapService = req.scope.resolve("swapService")
|
|
||||||
|
|
||||||
const limit = parseInt(req.query.limit) || 50
|
const limit = parseInt(req.query.limit) || 50
|
||||||
const offset = parseInt(req.query.offset) || 0
|
const offset = parseInt(req.query.offset) || 0
|
||||||
|
|
||||||
const selector = {}
|
const selector = {}
|
||||||
|
|
||||||
const listConfig = {
|
const listConfig = {
|
||||||
skip: offset,
|
skip: offset,
|
||||||
take: limit,
|
take: limit,
|
||||||
order: { created_at: "DESC" },
|
order: { created_at: "DESC" },
|
||||||
}
|
|
||||||
|
|
||||||
const swaps = await swapService.list(selector, { ...listConfig })
|
|
||||||
|
|
||||||
res.json({ swaps, count: swaps.length, offset, limit })
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const swaps = await swapService.list(selector, { ...listConfig })
|
||||||
|
|
||||||
|
res.json({ swaps, count: swaps.length, offset, limit })
|
||||||
}
|
}
|
||||||
@@ -13,14 +13,10 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const userService = req.scope.resolve("userService")
|
||||||
const userService = req.scope.resolve("userService")
|
const data = _.pick(value, ["email", "name"])
|
||||||
const data = _.pick(value, ["email", "name"])
|
|
||||||
|
|
||||||
const user = await userService.create(data, value.password)
|
const user = await userService.create(data, value.password)
|
||||||
|
|
||||||
res.status(200).json({ user })
|
res.status(200).json({ user })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,8 @@
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { user_id } = req.params
|
const { user_id } = req.params
|
||||||
|
|
||||||
try {
|
const userService = req.scope.resolve("userService")
|
||||||
const userService = req.scope.resolve("userService")
|
|
||||||
|
|
||||||
const user = await userService.retrieve(user_id)
|
const user = await userService.retrieve(user_id)
|
||||||
res.json({ user })
|
res.json({ user })
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
try {
|
const userService = req.scope.resolve("userService")
|
||||||
const userService = req.scope.resolve("userService")
|
const users = await userService.list({})
|
||||||
const users = await userService.list({})
|
|
||||||
|
|
||||||
res.status(200).json({ users })
|
res.status(200).json({ users })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -9,16 +9,11 @@ export default async (req, res) => {
|
|||||||
if (error) {
|
if (error) {
|
||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
const userService = req.scope.resolve("userService")
|
||||||
|
const user = await userService.retrieveByEmail(value.email)
|
||||||
|
|
||||||
try {
|
// Should call a email service provider that sends the token to the user
|
||||||
const userService = req.scope.resolve("userService")
|
await userService.generateResetPasswordToken(user.id)
|
||||||
const user = await userService.retrieveByEmail(value.email)
|
|
||||||
|
|
||||||
// Should call a email service provider that sends the token to the user
|
res.sendStatus(204)
|
||||||
await userService.generateResetPasswordToken(user.id)
|
|
||||||
|
|
||||||
res.sendStatus(204)
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -12,21 +12,16 @@ export default async (req, res) => {
|
|||||||
if (error) {
|
if (error) {
|
||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
const userService = req.scope.resolve("userService")
|
||||||
|
const user = await userService.retrieveByEmail(value.email)
|
||||||
|
|
||||||
try {
|
const decodedToken = await jwt.verify(value.token, user.password_hash)
|
||||||
const userService = req.scope.resolve("userService")
|
if (!decodedToken || decodedToken.user_id !== user.id) {
|
||||||
const user = await userService.retrieveByEmail(value.email)
|
res.status(401).send("Invalid or expired password reset token")
|
||||||
|
return
|
||||||
const decodedToken = await jwt.verify(value.token, user.password_hash)
|
|
||||||
if (!decodedToken || decodedToken.user_id !== user.id) {
|
|
||||||
res.status(401).send("Invalid or expired password reset token")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await userService.setPassword(user.id, value.password)
|
|
||||||
|
|
||||||
res.status(200).json({ user: data })
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const data = await userService.setPassword(user.id, value.password)
|
||||||
|
|
||||||
|
res.status(200).json({ user: data })
|
||||||
}
|
}
|
||||||
@@ -12,11 +12,7 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const userService = req.scope.resolve("userService")
|
||||||
const userService = req.scope.resolve("userService")
|
const data = await userService.update(user_id, value)
|
||||||
const data = await userService.update(user_id, value)
|
res.status(200).json({ user: data })
|
||||||
res.status(200).json({ user: data })
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
import { Validator, MedusaError } from "medusa-core-utils"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [get] /auth/{email}
|
* @oas [get] /auth/{email}
|
||||||
* operationId: "GetAuthEmail"
|
* operationId: "GetAuthEmail"
|
||||||
|
|||||||
@@ -16,17 +16,13 @@
|
|||||||
* $ref: "#/components/schemas/customer"
|
* $ref: "#/components/schemas/customer"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
try {
|
if (req.user && req.user.customer_id) {
|
||||||
if (req.user && req.user.customer_id) {
|
const customerService = req.scope.resolve("customerService")
|
||||||
const customerService = req.scope.resolve("customerService")
|
const customer = await customerService.retrieve(req.user.customer_id, {
|
||||||
const customer = await customerService.retrieve(req.user.customer_id, {
|
relations: ["shipping_addresses", "orders", "orders.items"],
|
||||||
relations: ["shipping_addresses", "orders", "orders.items"],
|
})
|
||||||
})
|
res.json({ customer })
|
||||||
res.json({ customer })
|
} else {
|
||||||
} else {
|
res.sendStatus(401)
|
||||||
res.sendStatus(401)
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,17 +41,13 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const customerService = req.scope.resolve("customerService")
|
||||||
const customerService = req.scope.resolve("customerService")
|
|
||||||
|
|
||||||
let customer = await customerService.addAddress(id, value.address)
|
let customer = await customerService.addAddress(id, value.address)
|
||||||
customer = await customerService.retrieve(id, {
|
customer = await customerService.retrieve(id, {
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ customer })
|
res.status(200).json({ customer })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -40,22 +40,18 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const customerService = req.scope.resolve("customerService")
|
||||||
const customerService = req.scope.resolve("customerService")
|
let customer = await customerService.create(value)
|
||||||
let customer = await customerService.create(value)
|
|
||||||
|
|
||||||
// Add JWT to cookie
|
// Add JWT to cookie
|
||||||
req.session.jwt = jwt.sign({ customer_id: customer.id }, config.jwtSecret, {
|
req.session.jwt = jwt.sign({ customer_id: customer.id }, config.jwtSecret, {
|
||||||
expiresIn: "30d",
|
expiresIn: "30d",
|
||||||
})
|
})
|
||||||
|
|
||||||
customer = await customerService.retrieve(customer.id, {
|
customer = await customerService.retrieve(customer.id, {
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ customer })
|
res.status(200).json({ customer })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -25,15 +25,11 @@ export default async (req, res) => {
|
|||||||
const { address_id } = req.params
|
const { address_id } = req.params
|
||||||
|
|
||||||
const customerService = req.scope.resolve("customerService")
|
const customerService = req.scope.resolve("customerService")
|
||||||
try {
|
await customerService.removeAddress(id, address_id)
|
||||||
await customerService.removeAddress(id, address_id)
|
const customer = await customerService.retrieve(id, {
|
||||||
customer = await customerService.retrieve(id, {
|
relations: defaultRelations,
|
||||||
relations: defaultRelations,
|
select: defaultFields,
|
||||||
select: defaultFields,
|
})
|
||||||
})
|
|
||||||
|
|
||||||
res.json({ customer })
|
res.json({ customer })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -19,14 +19,10 @@ import { defaultRelations, defaultFields } from "./"
|
|||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const id = req.user.customer_id
|
const id = req.user.customer_id
|
||||||
try {
|
const customerService = req.scope.resolve("customerService")
|
||||||
const customerService = req.scope.resolve("customerService")
|
const customer = await customerService.retrieve(id, {
|
||||||
const customer = await customerService.retrieve(id, {
|
relations: defaultRelations,
|
||||||
relations: defaultRelations,
|
select: defaultFields,
|
||||||
select: defaultFields,
|
})
|
||||||
})
|
res.json({ customer })
|
||||||
res.json({ customer })
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -27,29 +27,25 @@
|
|||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const id = req.user.customer_id
|
const id = req.user.customer_id
|
||||||
try {
|
const storeService = req.scope.resolve("storeService")
|
||||||
const storeService = req.scope.resolve("storeService")
|
const paymentProviderService = req.scope.resolve("paymentProviderService")
|
||||||
const paymentProviderService = req.scope.resolve("paymentProviderService")
|
const customerService = req.scope.resolve("customerService")
|
||||||
const customerService = req.scope.resolve("customerService")
|
|
||||||
|
|
||||||
const customer = await customerService.retrieve(id)
|
const customer = await customerService.retrieve(id)
|
||||||
|
|
||||||
const store = await storeService.retrieve(["payment_providers"])
|
const store = await storeService.retrieve(["payment_providers"])
|
||||||
|
|
||||||
const methods = await Promise.all(
|
const methods = await Promise.all(
|
||||||
store.payment_providers.map(async (next) => {
|
store.payment_providers.map(async (next) => {
|
||||||
const provider = paymentProviderService.retrieveProvider(next)
|
const provider = paymentProviderService.retrieveProvider(next)
|
||||||
|
|
||||||
const pMethods = await provider.retrieveSavedMethods(customer)
|
const pMethods = await provider.retrieveSavedMethods(customer)
|
||||||
return pMethods.map((m) => ({
|
return pMethods.map((m) => ({
|
||||||
provider_id: next,
|
provider_id: next,
|
||||||
data: m,
|
data: m,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
res.json({ payment_methods: methods.flat() })
|
res.json({ payment_methods: methods.flat() })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import _ from "lodash"
|
|
||||||
import {
|
import {
|
||||||
defaultRelations,
|
defaultRelations,
|
||||||
defaultFields,
|
defaultFields,
|
||||||
@@ -29,43 +28,37 @@ import {
|
|||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const id = req.user.customer_id
|
const id = req.user.customer_id
|
||||||
try {
|
|
||||||
const orderService = req.scope.resolve("orderService")
|
|
||||||
|
|
||||||
const selector = {
|
const orderService = req.scope.resolve("orderService")
|
||||||
customer_id: id,
|
|
||||||
}
|
|
||||||
|
|
||||||
const limit = parseInt(req.query.limit) || 10
|
const selector = {
|
||||||
const offset = parseInt(req.query.offset) || 0
|
customer_id: id,
|
||||||
|
|
||||||
let includeFields = []
|
|
||||||
if ("fields" in req.query) {
|
|
||||||
includeFields = req.query.fields.split(",")
|
|
||||||
includeFields = includeFields.filter((f) => allowedFields.includes(f))
|
|
||||||
}
|
|
||||||
|
|
||||||
let expandFields = []
|
|
||||||
if ("expand" in req.query) {
|
|
||||||
expandFields = req.query.expand.split(",")
|
|
||||||
expandFields = expandFields.filter((f) => allowedRelations.includes(f))
|
|
||||||
}
|
|
||||||
|
|
||||||
const listConfig = {
|
|
||||||
select: includeFields.length ? includeFields : defaultFields,
|
|
||||||
relations: expandFields.length ? expandFields : defaultRelations,
|
|
||||||
skip: offset,
|
|
||||||
take: limit,
|
|
||||||
order: { created_at: "DESC" },
|
|
||||||
}
|
|
||||||
|
|
||||||
const [orders, count] = await orderService.listAndCount(
|
|
||||||
selector,
|
|
||||||
listConfig
|
|
||||||
)
|
|
||||||
|
|
||||||
res.json({ orders, count, offset, limit })
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const limit = parseInt(req.query.limit) || 10
|
||||||
|
const offset = parseInt(req.query.offset) || 0
|
||||||
|
|
||||||
|
let includeFields = []
|
||||||
|
if ("fields" in req.query) {
|
||||||
|
includeFields = req.query.fields.split(",")
|
||||||
|
includeFields = includeFields.filter((f) => allowedFields.includes(f))
|
||||||
|
}
|
||||||
|
|
||||||
|
let expandFields = []
|
||||||
|
if ("expand" in req.query) {
|
||||||
|
expandFields = req.query.expand.split(",")
|
||||||
|
expandFields = expandFields.filter((f) => allowedRelations.includes(f))
|
||||||
|
}
|
||||||
|
|
||||||
|
const listConfig = {
|
||||||
|
select: includeFields.length ? includeFields : defaultFields,
|
||||||
|
relations: expandFields.length ? expandFields : defaultRelations,
|
||||||
|
skip: offset,
|
||||||
|
take: limit,
|
||||||
|
order: { created_at: "DESC" },
|
||||||
|
}
|
||||||
|
|
||||||
|
const [orders, count] = await orderService.listAndCount(selector, listConfig)
|
||||||
|
|
||||||
|
res.json({ orders, count, offset, limit })
|
||||||
}
|
}
|
||||||
@@ -21,15 +21,11 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const customerService = req.scope.resolve("customerService")
|
||||||
const customerService = req.scope.resolve("customerService")
|
const customer = await customerService.retrieveByEmail(value.email)
|
||||||
const customer = await customerService.retrieveByEmail(value.email)
|
|
||||||
|
|
||||||
// Will generate a token and send it to the customer via an email privder
|
// Will generate a token and send it to the customer via an email privder
|
||||||
await customerService.generateResetPasswordToken(customer.id)
|
await customerService.generateResetPasswordToken(customer.id)
|
||||||
|
|
||||||
res.sendStatus(204)
|
res.sendStatus(204)
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -43,20 +43,17 @@ export default async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const customerService = req.scope.resolve("customerService")
|
const customerService = req.scope.resolve("customerService")
|
||||||
try {
|
|
||||||
let customer = await customerService.updateAddress(
|
|
||||||
id,
|
|
||||||
address_id,
|
|
||||||
value.address
|
|
||||||
)
|
|
||||||
|
|
||||||
customer = await customerService.retrieve(id, {
|
let customer = await customerService.updateAddress(
|
||||||
relations: defaultRelations,
|
id,
|
||||||
select: defaultFields,
|
address_id,
|
||||||
})
|
value.address
|
||||||
|
)
|
||||||
|
|
||||||
res.json({ customer })
|
customer = await customerService.retrieve(id, {
|
||||||
} catch (err) {
|
relations: defaultRelations,
|
||||||
throw err
|
select: defaultFields,
|
||||||
}
|
})
|
||||||
|
|
||||||
|
res.json({ customer })
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { optional } from "joi"
|
|
||||||
import { Validator, MedusaError } from "medusa-core-utils"
|
import { Validator, MedusaError } from "medusa-core-utils"
|
||||||
import { defaultRelations, defaultFields } from "./"
|
import { defaultRelations, defaultFields } from "./"
|
||||||
|
|
||||||
@@ -64,17 +63,13 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const customerService = req.scope.resolve("customerService")
|
||||||
const customerService = req.scope.resolve("customerService")
|
await customerService.update(id, value)
|
||||||
await customerService.update(id, value)
|
|
||||||
|
|
||||||
const customer = await customerService.retrieve(id, {
|
const customer = await customerService.retrieve(id, {
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ customer })
|
res.status(200).json({ customer })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -22,15 +22,11 @@ import { defaultFields, defaultRelations } from "."
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { cart_id } = req.params
|
const { cart_id } = req.params
|
||||||
|
|
||||||
try {
|
const orderService = req.scope.resolve("orderService")
|
||||||
const orderService = req.scope.resolve("orderService")
|
const order = await orderService.retrieveByCartId(cart_id, {
|
||||||
const order = await orderService.retrieveByCartId(cart_id, {
|
select: defaultFields,
|
||||||
select: defaultFields,
|
relations: defaultRelations,
|
||||||
relations: defaultRelations,
|
})
|
||||||
})
|
|
||||||
|
|
||||||
res.json({ order })
|
res.json({ order })
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { MedusaError, Validator } from "medusa-core-utils"
|
|
||||||
import { defaultRelations } from "."
|
import { defaultRelations } from "."
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,30 +29,26 @@ import { defaultRelations } from "."
|
|||||||
* $ref: "#/components/schemas/product"
|
* $ref: "#/components/schemas/product"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
try {
|
const productService = req.scope.resolve("productService")
|
||||||
const productService = req.scope.resolve("productService")
|
|
||||||
|
|
||||||
const limit = parseInt(req.query.limit) || 100
|
const limit = parseInt(req.query.limit) || 100
|
||||||
const offset = parseInt(req.query.offset) || 0
|
const offset = parseInt(req.query.offset) || 0
|
||||||
|
|
||||||
const selector = {}
|
const selector = {}
|
||||||
|
|
||||||
if ("is_giftcard" in req.query && req.query.is_giftcard === "true") {
|
if ("is_giftcard" in req.query && req.query.is_giftcard === "true") {
|
||||||
selector.is_giftcard = req.query.is_giftcard === "true"
|
selector.is_giftcard = req.query.is_giftcard === "true"
|
||||||
}
|
|
||||||
|
|
||||||
selector.status = ["published"]
|
|
||||||
|
|
||||||
const listConfig = {
|
|
||||||
relations: defaultRelations,
|
|
||||||
skip: offset,
|
|
||||||
take: limit,
|
|
||||||
}
|
|
||||||
|
|
||||||
const products = await productService.list(selector, listConfig)
|
|
||||||
|
|
||||||
res.json({ products, count: products.length, offset, limit })
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selector.status = ["published"]
|
||||||
|
|
||||||
|
const listConfig = {
|
||||||
|
relations: defaultRelations,
|
||||||
|
skip: offset,
|
||||||
|
take: limit,
|
||||||
|
}
|
||||||
|
|
||||||
|
const products = await productService.list(selector, listConfig)
|
||||||
|
|
||||||
|
res.json({ products, count: products.length, offset, limit })
|
||||||
}
|
}
|
||||||
@@ -16,20 +16,16 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const { q, offset, limit, filter, ...options } = value
|
||||||
const { q, offset, limit, filter, ...options } = value
|
const paginationOptions = { offset, limit }
|
||||||
const paginationOptions = { offset, limit }
|
|
||||||
|
|
||||||
const searchService = req.scope.resolve("searchService")
|
const searchService = req.scope.resolve("searchService")
|
||||||
|
|
||||||
const results = await searchService.search(ProductService.IndexName, q, {
|
const results = await searchService.search(ProductService.IndexName, q, {
|
||||||
paginationOptions,
|
paginationOptions,
|
||||||
filter,
|
filter,
|
||||||
additionalOptions: options,
|
additionalOptions: options,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).send(results)
|
res.status(200).send(results)
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -25,34 +25,29 @@ export default async (req, res) => {
|
|||||||
const productIds =
|
const productIds =
|
||||||
(req.query.product_ids && req.query.product_ids.split(",")) || []
|
(req.query.product_ids && req.query.product_ids.split(",")) || []
|
||||||
const regionId = req.query.region_id
|
const regionId = req.query.region_id
|
||||||
|
const productService = req.scope.resolve("productService")
|
||||||
|
const shippingOptionService = req.scope.resolve("shippingOptionService")
|
||||||
|
|
||||||
try {
|
const query = {}
|
||||||
const productService = req.scope.resolve("productService")
|
|
||||||
const shippingOptionService = req.scope.resolve("shippingOptionService")
|
|
||||||
|
|
||||||
const query = {}
|
if ("is_return" in req.query) {
|
||||||
|
query.is_return = req.query.is_return === "true"
|
||||||
if ("is_return" in req.query) {
|
|
||||||
query.is_return = req.query.is_return === "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (regionId) {
|
|
||||||
query.region_id = regionId
|
|
||||||
}
|
|
||||||
|
|
||||||
query.admin_only = false
|
|
||||||
|
|
||||||
if (productIds.length) {
|
|
||||||
const prods = await productService.list({ id: productIds })
|
|
||||||
query.profile_id = prods.map((p) => p.profile_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = await shippingOptionService.list(query, {
|
|
||||||
relations: ["requirements"],
|
|
||||||
})
|
|
||||||
|
|
||||||
res.status(200).json({ shipping_options: options })
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (regionId) {
|
||||||
|
query.region_id = regionId
|
||||||
|
}
|
||||||
|
|
||||||
|
query.admin_only = false
|
||||||
|
|
||||||
|
if (productIds.length) {
|
||||||
|
const prods = await productService.list({ id: productIds })
|
||||||
|
query.profile_id = prods.map((p) => p.profile_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
const options = await shippingOptionService.list(query, {
|
||||||
|
relations: ["requirements"],
|
||||||
|
})
|
||||||
|
|
||||||
|
res.status(200).json({ shipping_options: options })
|
||||||
}
|
}
|
||||||
@@ -31,19 +31,15 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const cartService = req.scope.resolve("cartService")
|
||||||
const cartService = req.scope.resolve("cartService")
|
const shippingProfileService = req.scope.resolve("shippingProfileService")
|
||||||
const shippingProfileService = req.scope.resolve("shippingProfileService")
|
|
||||||
|
|
||||||
const cart = await cartService.retrieve(value.cart_id, {
|
const cart = await cartService.retrieve(value.cart_id, {
|
||||||
select: ["subtotal"],
|
select: ["subtotal"],
|
||||||
relations: ["region", "items", "items.variant", "items.variant.product"],
|
relations: ["region", "items", "items.variant", "items.variant.product"],
|
||||||
})
|
})
|
||||||
|
|
||||||
const options = await shippingProfileService.fetchCartOptions(cart)
|
const options = await shippingProfileService.fetchCartOptions(cart)
|
||||||
|
|
||||||
res.status(200).json({ shipping_options: options })
|
res.status(200).json({ shipping_options: options })
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { IdMap } from "../../../../../../../medusa-test-utils/dist"
|
|
||||||
import { request } from "../../../../../helpers/test-request"
|
import { request } from "../../../../../helpers/test-request"
|
||||||
import { ProductVariantServiceMock } from "../../../../../services/__mocks__/product-variant"
|
import { ProductVariantServiceMock } from "../../../../../services/__mocks__/product-variant"
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import _ from "lodash"
|
|
||||||
import { MedusaError } from "medusa-core-utils"
|
import { MedusaError } from "medusa-core-utils"
|
||||||
import { BaseService } from "medusa-interfaces"
|
import { BaseService } from "medusa-interfaces"
|
||||||
import { Brackets } from "typeorm"
|
import { Brackets } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides layer to manipulate products.
|
* Provides layer to manipulate products.
|
||||||
* @implements BaseService
|
* @extends BaseService
|
||||||
*/
|
*/
|
||||||
class ProductService extends BaseService {
|
class ProductService extends BaseService {
|
||||||
static IndexName = `products`
|
static IndexName = `products`
|
||||||
@@ -88,7 +87,8 @@ class ProductService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} listOptions - the query object for find
|
* @param {object} selector - selector for query
|
||||||
|
* @param {Object} config - config for query object for find
|
||||||
* @return {Promise} the result of the find operation
|
* @return {Promise} the result of the find operation
|
||||||
*/
|
*/
|
||||||
async list(selector = {}, config = { relations: [], skip: 0, take: 20 }) {
|
async list(selector = {}, config = { relations: [], skip: 0, take: 20 }) {
|
||||||
@@ -112,7 +112,7 @@ class ProductService extends BaseService {
|
|||||||
query.select = config.select
|
query.select = config.select
|
||||||
}
|
}
|
||||||
|
|
||||||
let rels = query.relations
|
const rels = query.relations
|
||||||
delete query.relations
|
delete query.relations
|
||||||
|
|
||||||
if (q) {
|
if (q) {
|
||||||
@@ -162,6 +162,7 @@ class ProductService extends BaseService {
|
|||||||
* Gets a product by id.
|
* Gets a product by id.
|
||||||
* Throws in case of DB Error and if product was not found.
|
* Throws in case of DB Error and if product was not found.
|
||||||
* @param {string} productId - id of the product to get.
|
* @param {string} productId - id of the product to get.
|
||||||
|
* @param {object} config - config of the product to get.
|
||||||
* @return {Promise<Product>} the result of the find one operation.
|
* @return {Promise<Product>} the result of the find one operation.
|
||||||
*/
|
*/
|
||||||
async retrieve(productId, config = {}) {
|
async retrieve(productId, config = {}) {
|
||||||
@@ -258,7 +259,7 @@ class ProductService extends BaseService {
|
|||||||
this.productTagRepository_
|
this.productTagRepository_
|
||||||
)
|
)
|
||||||
|
|
||||||
let newTags = []
|
const newTags = []
|
||||||
for (const tag of tags) {
|
for (const tag of tags) {
|
||||||
const existing = await productTagRepository.findOne({
|
const existing = await productTagRepository.findOne({
|
||||||
where: { value: tag.value },
|
where: { value: tag.value },
|
||||||
@@ -339,7 +340,7 @@ class ProductService extends BaseService {
|
|||||||
this.imageRepository_
|
this.imageRepository_
|
||||||
)
|
)
|
||||||
|
|
||||||
let productImages = []
|
const productImages = []
|
||||||
for (const img of images) {
|
for (const img of images) {
|
||||||
const existing = await imageRepository.findOne({
|
const existing = await imageRepository.findOne({
|
||||||
where: { url: img },
|
where: { url: img },
|
||||||
@@ -376,8 +377,7 @@ class ProductService extends BaseService {
|
|||||||
relations: ["variants", "tags", "images"],
|
relations: ["variants", "tags", "images"],
|
||||||
})
|
})
|
||||||
|
|
||||||
const { variants, metadata, options, images, tags, type, ...rest } =
|
const { variants, metadata, images, tags, type, ...rest } = update
|
||||||
update
|
|
||||||
|
|
||||||
if (!product.thumbnail && !update.thumbnail && images?.length) {
|
if (!product.thumbnail && !update.thumbnail && images?.length) {
|
||||||
product.thumbnail = images[0]
|
product.thumbnail = images[0]
|
||||||
@@ -473,7 +473,9 @@ class ProductService extends BaseService {
|
|||||||
{ relations: ["variants"] }
|
{ relations: ["variants"] }
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!product) return Promise.resolve()
|
if (!product) {
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
await productRepo.softRemove(product)
|
await productRepo.softRemove(product)
|
||||||
|
|
||||||
@@ -574,7 +576,7 @@ class ProductService extends BaseService {
|
|||||||
* optionOrder and the length of the product's options are different. Will
|
* optionOrder and the length of the product's options are different. Will
|
||||||
* throw optionOrder contains an id not associated with the product.
|
* throw optionOrder contains an id not associated with the product.
|
||||||
* @param {string} productId - the product whose options we are reordering
|
* @param {string} productId - the product whose options we are reordering
|
||||||
* @param {[ObjectId]} optionId - the ids of the product's options in the
|
* @param {string[]} optionOrder - the ids of the product's options in the
|
||||||
* new order
|
* new order
|
||||||
* @return {Promise} the result of the update operation
|
* @return {Promise} the result of the update operation
|
||||||
*/
|
*/
|
||||||
@@ -727,7 +729,7 @@ class ProductService extends BaseService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorates a product with product variants.
|
* Decorates a product with product variants.
|
||||||
* @param {Product} product - the product to decorate.
|
* @param {string} productId - the productId to decorate.
|
||||||
* @param {string[]} fields - the fields to include.
|
* @param {string[]} fields - the fields to include.
|
||||||
* @param {string[]} expandFields - fields to expand.
|
* @param {string[]} expandFields - fields to expand.
|
||||||
* @return {Product} return the decorated product.
|
* @return {Product} return the decorated product.
|
||||||
|
|||||||
Executable
+40
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
IS_CI="${CI:-false}"
|
||||||
|
GREP_PATTERN=$1
|
||||||
|
|
||||||
|
if [ "$IS_CI" = true ]; then
|
||||||
|
git config --local url."https://github.com/".insteadOf git@github.com:
|
||||||
|
git config --local user.name "Medusajs Bot"
|
||||||
|
git config --local user.email "core@medusa-commerce.com"
|
||||||
|
|
||||||
|
git fetch origin
|
||||||
|
git merge --no-edit origin/master
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Branch has conflicts with master, rolling back test."
|
||||||
|
git merge --abort
|
||||||
|
fi
|
||||||
|
|
||||||
|
git config --local --unset user.name
|
||||||
|
git config --local --unset user.email
|
||||||
|
git config --local --unset url."https://github.com/".insteadOf
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Make sure that we are diffing towards the right branch, in github actions this is different
|
||||||
|
# depending on whether or not we are creating a pull request or not.
|
||||||
|
[ ! -z ${GITHUB_BASE_REF} ] && HAS_BASE=true || HAS_BASE=false
|
||||||
|
[ HAS_BASE = true ] && COMPARE="${GITHUB_BASE_REF#refs/heads/}" || COMPARE="develop"
|
||||||
|
FILES_COUNT="$(git diff-tree --no-commit-id --name-only -r origin/"$COMPARE" | grep -E "$GREP_PATTERN" -c)"
|
||||||
|
|
||||||
|
if [ "$IS_CI" = true ]; then
|
||||||
|
# reset to previous state
|
||||||
|
git reset --hard $GITHUB_SHA
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$FILES_COUNT" -eq 0 ]; then
|
||||||
|
echo "0 files matching '$GREP_PATTERN'; exiting and marking successful."
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "$FILES_COUNT file(s) matching '$GREP_PATTERN'; continuing."
|
||||||
|
fi
|
||||||
Reference in new issue
Block a user