* fixed linting errors on packages/medusa/src/services/user.js #531 fixing merge conflicts * fix: resolving a few issues as raised in the PR, issue: #531 Co-authored-by: Sergiy Fomin <sergiy.fomin@sourcedgroup.com>
This commit is contained in:
@@ -31,7 +31,6 @@
|
||||
/packages/medusa/src/services/swap.js
|
||||
/packages/medusa/src/services/system-payment-provider.js
|
||||
/packages/medusa/src/services/totals.js
|
||||
/packages/medusa/src/services/user.js
|
||||
|
||||
/packages/medusa/src/subscribers/notification.js
|
||||
/packages/medusa/src/subscribers/order.js
|
||||
|
||||
@@ -6,7 +6,7 @@ import { BaseService } from "medusa-interfaces"
|
||||
|
||||
/**
|
||||
* Provides layer to manipulate users.
|
||||
* @implements BaseService
|
||||
* @extends BaseService
|
||||
*/
|
||||
class UserService extends BaseService {
|
||||
static Events = {
|
||||
@@ -75,6 +75,7 @@ class UserService extends BaseService {
|
||||
* Gets a user by id.
|
||||
* Throws in case of DB Error and if user was not found.
|
||||
* @param {string} userId - the id of the user to get.
|
||||
* @param {Object} config - query configs
|
||||
* @return {Promise<User>} the user document.
|
||||
*/
|
||||
async retrieve(userId, config = {}) {
|
||||
@@ -99,6 +100,7 @@ class UserService extends BaseService {
|
||||
* Gets a user by api token.
|
||||
* Throws in case of DB Error and if user was not found.
|
||||
* @param {string} apiToken - the token of the user to get.
|
||||
* @param {string[]} relations - relations to include with the user
|
||||
* @return {Promise<User>} the user document.
|
||||
*/
|
||||
async retrieveByApiToken(apiToken, relations = []) {
|
||||
@@ -123,6 +125,7 @@ class UserService extends BaseService {
|
||||
* Gets a user by email.
|
||||
* Throws in case of DB Error and if user was not found.
|
||||
* @param {string} email - the email of the user to get.
|
||||
* @param {Object} config - query config
|
||||
* @return {Promise<User>} the user document.
|
||||
*/
|
||||
async retrieveByEmail(email, config = {}) {
|
||||
@@ -144,7 +147,7 @@ class UserService extends BaseService {
|
||||
/**
|
||||
* Hashes a password
|
||||
* @param {string} password - the value to hash
|
||||
* @return hashed password
|
||||
* @return {string} hashed password
|
||||
*/
|
||||
async hashPassword_(password) {
|
||||
const buf = await Scrypt.kdf(password, { logN: 1, r: 1, p: 1 })
|
||||
@@ -155,6 +158,7 @@ class UserService extends BaseService {
|
||||
* Creates a user with username being validated.
|
||||
* Fails if email is not a valid format.
|
||||
* @param {object} user - the user to create
|
||||
* @param {string} password - user's password to hash
|
||||
* @return {Promise} the result of create
|
||||
*/
|
||||
async create(user, password) {
|
||||
@@ -177,7 +181,8 @@ class UserService extends BaseService {
|
||||
|
||||
/**
|
||||
* Updates a user.
|
||||
* @param {object} user - the user to create
|
||||
* @param {object} userId - id of the user to update
|
||||
* @param {object} update - the values to be updated on the user
|
||||
* @return {Promise} the result of create
|
||||
*/
|
||||
async update(userId, update) {
|
||||
@@ -228,7 +233,9 @@ class UserService extends BaseService {
|
||||
// Should not fail, if user does not exist, since delete is idempotent
|
||||
const user = await userRepo.findOne({ where: { id: userId } })
|
||||
|
||||
if (!user) return Promise.resolve()
|
||||
if (!user) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
await userRepo.softRemove(user)
|
||||
|
||||
@@ -242,7 +249,7 @@ class UserService extends BaseService {
|
||||
* password does not work.
|
||||
* @param {string} userId - the userId to set password for
|
||||
* @param {string} password - the old password to set
|
||||
* @returns {Promise} the result of the update operation
|
||||
* @return {Promise} the result of the update operation
|
||||
*/
|
||||
async setPassword_(userId, password) {
|
||||
return this.atomicPhase_(async manager => {
|
||||
@@ -270,8 +277,8 @@ class UserService extends BaseService {
|
||||
* The token will be signed with the users current password hash as a secret
|
||||
* a long side a payload with userId and the expiry time for the token, which
|
||||
* is always 15 minutes.
|
||||
* @param {User} user - the user to reset password for
|
||||
* @returns {string} the generated JSON web token
|
||||
* @param {string} userId - the id of the user to reset password for
|
||||
* @return {string} the generated JSON web token
|
||||
*/
|
||||
async generateResetPasswordToken(userId) {
|
||||
const user = await this.retrieve(userId)
|
||||
|
||||
Reference in New Issue
Block a user