fix: make packages/medusa/src/api/routes/admin/users pass eslint
This commit is contained in:
1 parent
71561b0a61
commit
a6a612c941
8 files changed
+29
-56
No files matched your search
@@ -43,7 +43,6 @@
|
|||||||
/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/swaps
|
||||||
/packages/medusa/src/api/routes/admin/users
|
|
||||||
|
|
||||||
|
|
||||||
/packages/medusa/src/api/routes/store/auth
|
/packages/medusa/src/api/routes/store/auth
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"endOfLine": "lf",
|
"endOfLine": "auto",
|
||||||
"semi": false,
|
"semi": false,
|
||||||
"singleQuote": false,
|
"singleQuote": false,
|
||||||
"tabWidth": 2,
|
"tabWidth": 2,
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user