fix: make packages/medusa/src/services/notification.js pass eslint (#566)

This commit is contained in:
Yyee
2021-10-15 09:00:43 +02:00
committed by GitHub
parent fbd08e0feb
commit 38559b5454
2 changed files with 10 additions and 7 deletions
-1
View File
@@ -9,7 +9,6 @@
/packages/medusa/src/services/inventory.js /packages/medusa/src/services/inventory.js
/packages/medusa/src/services/middleware.js /packages/medusa/src/services/middleware.js
/packages/medusa/src/services/note.js /packages/medusa/src/services/note.js
/packages/medusa/src/services/notification.js
/packages/medusa/src/services/oauth.js /packages/medusa/src/services/oauth.js
/packages/medusa/src/services/payment-provider.js /packages/medusa/src/services/payment-provider.js
/packages/medusa/src/services/product-collection.js /packages/medusa/src/services/product-collection.js
+10 -6
View File
@@ -1,10 +1,9 @@
import { MedusaError } from "medusa-core-utils" import { MedusaError } from "medusa-core-utils"
import { BaseService } from "medusa-interfaces" import { BaseService } from "medusa-interfaces"
import _ from "lodash"
/** /**
* Provides layer to manipulate orchestrate notifications. * Provides layer to manipulate orchestrate notifications.
* @implements BaseService * @extends BaseService
*/ */
class NotificationService extends BaseService { class NotificationService extends BaseService {
constructor(container) { constructor(container) {
@@ -34,6 +33,7 @@ class NotificationService extends BaseService {
/** /**
* Registers an attachment generator to the service. The generator can be * Registers an attachment generator to the service. The generator can be
* used to generate on demand invoices or other documents. * used to generate on demand invoices or other documents.
* @param {object} service
*/ */
registerAttachmentGenerator(service) { registerAttachmentGenerator(service) {
this.attachmentGenerator_ = service this.attachmentGenerator_ = service
@@ -42,16 +42,18 @@ class NotificationService extends BaseService {
/** /**
* Sets the service's manager to a given transaction manager. * Sets the service's manager to a given transaction manager.
* @param {EntityManager} transactionManager - the manager to use * @param {EntityManager} transactionManager - the manager to use
* return {NotificationService} a cloned notification service * @return {NotificationService} a cloned notification service
*/ */
withTransaction(transactionManager) { withTransaction(transactionManager) {
if (!transactionManager) { if (!transactionManager) {
return this return this
} }
const cloned = new LineItemService({ const cloned = new NotificationService({
manager: transactionManager, manager: transactionManager,
notificationProviderRepository: this.notificationProviderRepository_,
notificationRepository: this.notificationRepository_, notificationRepository: this.notificationRepository_,
logger: this.logger_,
}) })
cloned.transactionManager_ = transactionManager cloned.transactionManager_ = transactionManager
@@ -93,6 +95,7 @@ class NotificationService extends BaseService {
/** /**
* Retrieves a notification with a given id * Retrieves a notification with a given id
* @param {string} id - the id of the notification * @param {string} id - the id of the notification
* @param {object} config - the configuration to apply to the query
* @return {Notification} the notification * @return {Notification} the notification
*/ */
async retrieve(id, config = {}) { async retrieve(id, config = {}) {
@@ -158,6 +161,7 @@ class NotificationService extends BaseService {
* order to allow for resends. Will log any errors that are encountered. * order to allow for resends. Will log any errors that are encountered.
* @param {string} eventName - the event to handle * @param {string} eventName - the event to handle
* @param {object} data - the data the event was sent with * @param {object} data - the data the event was sent with
* @return {Promise} - the result of notification subscribed
*/ */
handleEvent(eventName, data) { handleEvent(eventName, data) {
const subs = this.subscribers_[eventName] const subs = this.subscribers_[eventName]
@@ -169,8 +173,8 @@ class NotificationService extends BaseService {
} }
return Promise.all( return Promise.all(
subs.map(async providerId => { subs.map(async (providerId) => {
return this.send(eventName, data, providerId).catch(err => { return this.send(eventName, data, providerId).catch((err) => {
console.log(err) console.log(err)
this.logger_.warn( this.logger_.warn(
`An error occured while ${providerId} was processing a notification for ${eventName}: ${err.message}` `An error occured while ${providerId} was processing a notification for ${eventName}: ${err.message}`