fix: /api/routes/store/customers pass linting (#646)
This commit is contained in:
@@ -49,7 +49,6 @@
|
|||||||
|
|
||||||
/packages/medusa/src/api/routes/store/auth
|
/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/regions
|
/packages/medusa/src/api/routes/store/regions
|
||||||
/packages/medusa/src/api/routes/store/return-reasons
|
/packages/medusa/src/api/routes/store/return-reasons
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user