This reverts commit cf5b405a56.
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
/packages/medusa/src/services/swap.js
|
/packages/medusa/src/services/swap.js
|
||||||
/packages/medusa/src/services/system-payment-provider.js
|
/packages/medusa/src/services/system-payment-provider.js
|
||||||
/packages/medusa/src/services/totals.js
|
/packages/medusa/src/services/totals.js
|
||||||
|
/packages/medusa/src/services/user.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
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ module.exports = {
|
|||||||
plugins: [`eslint-plugin-prettier`],
|
plugins: [`eslint-plugin-prettier`],
|
||||||
extends: [`eslint:recommended`, `google`, `eslint-config-prettier`],
|
extends: [`eslint:recommended`, `google`, `eslint-config-prettier`],
|
||||||
rules: {
|
rules: {
|
||||||
|
"prettier/prettier": `error`,
|
||||||
curly: [2, `all`],
|
curly: [2, `all`],
|
||||||
"new-cap": `off`,
|
"new-cap": `off`,
|
||||||
"require-jsdoc": `off`,
|
"require-jsdoc": `off`,
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
const babelPreset = require(`babel-preset-medusa-package`)();
|
const babelPreset = require(`babel-preset-medusa-package`)()
|
||||||
module.exports = require(`babel-jest`).createTransformer({
|
module.exports = require(`babel-jest`).createTransformer({
|
||||||
...babelPreset,
|
...babelPreset,
|
||||||
});
|
})
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Brackets } from "typeorm"
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides layer to manipulate gift cards.
|
* Provides layer to manipulate gift cards.
|
||||||
* @implements BaseService
|
* @extends BaseService
|
||||||
*/
|
*/
|
||||||
class GiftCardService extends BaseService {
|
class GiftCardService extends BaseService {
|
||||||
static Events = {
|
static Events = {
|
||||||
@@ -101,7 +101,7 @@ class GiftCardService extends BaseService {
|
|||||||
.select(["gift_card.id"])
|
.select(["gift_card.id"])
|
||||||
.where(where)
|
.where(where)
|
||||||
.andWhere(
|
.andWhere(
|
||||||
new Brackets(qb => {
|
new Brackets((qb) => {
|
||||||
return qb
|
return qb
|
||||||
.where(`gift_card.code ILIKE :q`, { q: `%${q}%` })
|
.where(`gift_card.code ILIKE :q`, { q: `%${q}%` })
|
||||||
.orWhere(`display_id::varchar(255) ILIKE :dId`, { dId: `${q}` })
|
.orWhere(`display_id::varchar(255) ILIKE :dId`, { dId: `${q}` })
|
||||||
@@ -111,14 +111,14 @@ class GiftCardService extends BaseService {
|
|||||||
|
|
||||||
return giftCardRepo.findWithRelations(
|
return giftCardRepo.findWithRelations(
|
||||||
rels,
|
rels,
|
||||||
raw.map(i => i.id)
|
raw.map((i) => i.id)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return giftCardRepo.findWithRelations(rels, query)
|
return giftCardRepo.findWithRelations(rels, query)
|
||||||
}
|
}
|
||||||
|
|
||||||
async createTransaction(data) {
|
async createTransaction(data) {
|
||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async (manager) => {
|
||||||
const gctRepo = manager.getCustomRepository(this.giftCardTransactionRepo_)
|
const gctRepo = manager.getCustomRepository(this.giftCardTransactionRepo_)
|
||||||
const created = gctRepo.create(data)
|
const created = gctRepo.create(data)
|
||||||
const saved = await gctRepo.save(created)
|
const saved = await gctRepo.save(created)
|
||||||
@@ -132,7 +132,7 @@ class GiftCardService extends BaseService {
|
|||||||
* @return {Promise<GiftCard>} the result of the create operation
|
* @return {Promise<GiftCard>} the result of the create operation
|
||||||
*/
|
*/
|
||||||
async create(giftCard) {
|
async create(giftCard) {
|
||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async (manager) => {
|
||||||
const giftCardRepo = manager.getCustomRepository(this.giftCardRepository_)
|
const giftCardRepo = manager.getCustomRepository(this.giftCardRepository_)
|
||||||
|
|
||||||
if (!giftCard.region_id) {
|
if (!giftCard.region_id) {
|
||||||
@@ -169,6 +169,7 @@ class GiftCardService extends BaseService {
|
|||||||
/**
|
/**
|
||||||
* Gets a gift card by id.
|
* Gets a gift card by id.
|
||||||
* @param {string} giftCardId - id of gift card to retrieve
|
* @param {string} giftCardId - id of gift card to retrieve
|
||||||
|
* @param {object} config - optional values to include with gift card query
|
||||||
* @return {Promise<GiftCard>} the gift card
|
* @return {Promise<GiftCard>} the gift card
|
||||||
*/
|
*/
|
||||||
async retrieve(giftCardId, config = {}) {
|
async retrieve(giftCardId, config = {}) {
|
||||||
@@ -244,7 +245,7 @@ class GiftCardService extends BaseService {
|
|||||||
* @return {Promise} the result of the update operation
|
* @return {Promise} the result of the update operation
|
||||||
*/
|
*/
|
||||||
async update(giftCardId, update) {
|
async update(giftCardId, update) {
|
||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async (manager) => {
|
||||||
const giftCardRepo = manager.getCustomRepository(this.giftCardRepository_)
|
const giftCardRepo = manager.getCustomRepository(this.giftCardRepository_)
|
||||||
|
|
||||||
const giftCard = await this.retrieve(giftCardId)
|
const giftCard = await this.retrieve(giftCardId)
|
||||||
@@ -285,12 +286,14 @@ class GiftCardService extends BaseService {
|
|||||||
* @return {Promise} the result of the delete operation
|
* @return {Promise} the result of the delete operation
|
||||||
*/
|
*/
|
||||||
async delete(giftCardId) {
|
async delete(giftCardId) {
|
||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async (manager) => {
|
||||||
const giftCardRepo = manager.getCustomRepository(this.giftCardRepository_)
|
const giftCardRepo = manager.getCustomRepository(this.giftCardRepository_)
|
||||||
|
|
||||||
const giftCard = await giftCardRepo.findOne({ where: { id: giftCardId } })
|
const giftCard = await giftCardRepo.findOne({ where: { id: giftCardId } })
|
||||||
|
|
||||||
if (!giftCard) return Promise.resolve()
|
if (!giftCard) {
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
await giftCardRepo.softRemove(giftCard)
|
await giftCardRepo.softRemove(giftCard)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { BaseService } from "medusa-interfaces"
|
import { BaseService } from "medusa-interfaces"
|
||||||
import mongoose from "mongoose"
|
import mongoose from "mongoose"
|
||||||
import _ from "lodash"
|
|
||||||
|
|
||||||
class TransactionService extends BaseService {
|
class TransactionService extends BaseService {
|
||||||
constructor({}) {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { BaseService } from "medusa-interfaces"
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides layer to manipulate users.
|
* Provides layer to manipulate users.
|
||||||
* @extends BaseService
|
* @implements BaseService
|
||||||
*/
|
*/
|
||||||
class UserService extends BaseService {
|
class UserService extends BaseService {
|
||||||
static Events = {
|
static Events = {
|
||||||
@@ -75,7 +75,6 @@ class UserService extends BaseService {
|
|||||||
* Gets a user by id.
|
* Gets a user by id.
|
||||||
* Throws in case of DB Error and if user was not found.
|
* Throws in case of DB Error and if user was not found.
|
||||||
* @param {string} userId - the id of the user to get.
|
* @param {string} userId - the id of the user to get.
|
||||||
* @param {Object} config - query configs
|
|
||||||
* @return {Promise<User>} the user document.
|
* @return {Promise<User>} the user document.
|
||||||
*/
|
*/
|
||||||
async retrieve(userId, config = {}) {
|
async retrieve(userId, config = {}) {
|
||||||
@@ -100,7 +99,6 @@ class UserService extends BaseService {
|
|||||||
* Gets a user by api token.
|
* Gets a user by api token.
|
||||||
* Throws in case of DB Error and if user was not found.
|
* Throws in case of DB Error and if user was not found.
|
||||||
* @param {string} apiToken - the token of the user to get.
|
* @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.
|
* @return {Promise<User>} the user document.
|
||||||
*/
|
*/
|
||||||
async retrieveByApiToken(apiToken, relations = []) {
|
async retrieveByApiToken(apiToken, relations = []) {
|
||||||
@@ -125,7 +123,6 @@ class UserService extends BaseService {
|
|||||||
* Gets a user by email.
|
* Gets a user by email.
|
||||||
* Throws in case of DB Error and if user was not found.
|
* Throws in case of DB Error and if user was not found.
|
||||||
* @param {string} email - the email of the user to get.
|
* @param {string} email - the email of the user to get.
|
||||||
* @param {Object} config - query config
|
|
||||||
* @return {Promise<User>} the user document.
|
* @return {Promise<User>} the user document.
|
||||||
*/
|
*/
|
||||||
async retrieveByEmail(email, config = {}) {
|
async retrieveByEmail(email, config = {}) {
|
||||||
@@ -147,7 +144,7 @@ class UserService extends BaseService {
|
|||||||
/**
|
/**
|
||||||
* Hashes a password
|
* Hashes a password
|
||||||
* @param {string} password - the value to hash
|
* @param {string} password - the value to hash
|
||||||
* @return {string} hashed password
|
* @return hashed password
|
||||||
*/
|
*/
|
||||||
async hashPassword_(password) {
|
async hashPassword_(password) {
|
||||||
const buf = await Scrypt.kdf(password, { logN: 1, r: 1, p: 1 })
|
const buf = await Scrypt.kdf(password, { logN: 1, r: 1, p: 1 })
|
||||||
@@ -158,7 +155,6 @@ class UserService extends BaseService {
|
|||||||
* Creates a user with username being validated.
|
* Creates a user with username being validated.
|
||||||
* Fails if email is not a valid format.
|
* Fails if email is not a valid format.
|
||||||
* @param {object} user - the user to create
|
* @param {object} user - the user to create
|
||||||
* @param {string} password - user's password to hash
|
|
||||||
* @return {Promise} the result of create
|
* @return {Promise} the result of create
|
||||||
*/
|
*/
|
||||||
async create(user, password) {
|
async create(user, password) {
|
||||||
@@ -181,8 +177,7 @@ class UserService extends BaseService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a user.
|
* Updates a user.
|
||||||
* @param {object} userId - id of the user to update
|
* @param {object} user - the user to create
|
||||||
* @param {object} update - the values to be updated on the user
|
|
||||||
* @return {Promise} the result of create
|
* @return {Promise} the result of create
|
||||||
*/
|
*/
|
||||||
async update(userId, update) {
|
async update(userId, update) {
|
||||||
@@ -233,9 +228,7 @@ class UserService extends BaseService {
|
|||||||
// Should not fail, if user does not exist, since delete is idempotent
|
// Should not fail, if user does not exist, since delete is idempotent
|
||||||
const user = await userRepo.findOne({ where: { id: userId } })
|
const user = await userRepo.findOne({ where: { id: userId } })
|
||||||
|
|
||||||
if (!user) {
|
if (!user) return Promise.resolve()
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
|
|
||||||
await userRepo.softRemove(user)
|
await userRepo.softRemove(user)
|
||||||
|
|
||||||
@@ -249,7 +242,7 @@ class UserService extends BaseService {
|
|||||||
* password does not work.
|
* password does not work.
|
||||||
* @param {string} userId - the userId to set password for
|
* @param {string} userId - the userId to set password for
|
||||||
* @param {string} password - the old password to set
|
* @param {string} password - the old password to set
|
||||||
* @return {Promise} the result of the update operation
|
* @returns {Promise} the result of the update operation
|
||||||
*/
|
*/
|
||||||
async setPassword_(userId, password) {
|
async setPassword_(userId, password) {
|
||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async manager => {
|
||||||
@@ -277,8 +270,8 @@ class UserService extends BaseService {
|
|||||||
* The token will be signed with the users current password hash as a secret
|
* 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
|
* a long side a payload with userId and the expiry time for the token, which
|
||||||
* is always 15 minutes.
|
* is always 15 minutes.
|
||||||
* @param {string} userId - the id of the user to reset password for
|
* @param {User} user - the user to reset password for
|
||||||
* @return {string} the generated JSON web token
|
* @returns {string} the generated JSON web token
|
||||||
*/
|
*/
|
||||||
async generateResetPasswordToken(userId) {
|
async generateResetPasswordToken(userId) {
|
||||||
const user = await this.retrieve(userId)
|
const user = await this.retrieve(userId)
|
||||||
|
|||||||
Reference in New Issue
Block a user