fix: autofix

This commit is contained in:
Sebastian Rindom
2021-10-13 20:19:09 +02:00
parent f926e0245c
commit d9608e15e8
2 changed files with 23 additions and 25 deletions
+18 -18
View File
@@ -86,7 +86,7 @@ class RegionService extends BaseService {
* @return {Region} the newly created region * @return {Region} the newly created region
*/ */
async create(regionObject) { async create(regionObject) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const regionRepository = manager.getCustomRepository( const regionRepository = manager.getCustomRepository(
this.regionRepository_ this.regionRepository_
) )
@@ -144,7 +144,7 @@ class RegionService extends BaseService {
* @return {Promise} the result of the update operation * @return {Promise} the result of the update operation
*/ */
async update(regionId, update) { async update(regionId, update) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const regionRepository = manager.getCustomRepository( const regionRepository = manager.getCustomRepository(
this.regionRepository_ this.regionRepository_
) )
@@ -217,17 +217,17 @@ class RegionService extends BaseService {
if (region.countries) { if (region.countries) {
region.countries = await Promise.all( region.countries = await Promise.all(
region.countries.map(countryCode => region.countries.map((countryCode) =>
this.validateCountry_(countryCode, id) this.validateCountry_(countryCode, id)
) )
).catch(err => { ).catch((err) => {
throw err throw err
}) })
} }
if (region.payment_providers) { if (region.payment_providers) {
region.payment_providers = await Promise.all( region.payment_providers = await Promise.all(
region.payment_providers.map(async pId => { region.payment_providers.map(async (pId) => {
const pp = await ppRepository.findOne({ where: { id: pId } }) const pp = await ppRepository.findOne({ where: { id: pId } })
if (!pp) { if (!pp) {
throw new MedusaError( throw new MedusaError(
@@ -243,7 +243,7 @@ class RegionService extends BaseService {
if (region.fulfillment_providers) { if (region.fulfillment_providers) {
region.fulfillment_providers = await Promise.all( region.fulfillment_providers = await Promise.all(
region.fulfillment_providers.map(async fId => { region.fulfillment_providers.map(async (fId) => {
const fp = await fpRepository.findOne({ where: { id: fId } }) const fp = await fpRepository.findOne({ where: { id: fId } })
if (!fp) { if (!fp) {
throw new MedusaError( throw new MedusaError(
@@ -282,7 +282,7 @@ class RegionService extends BaseService {
.withTransaction(this.transactionManager_) .withTransaction(this.transactionManager_)
.retrieve(["currencies"]) .retrieve(["currencies"])
const storeCurrencies = store.currencies.map(curr => curr.code) const storeCurrencies = store.currencies.map((curr) => curr.code)
if (!storeCurrencies.includes(currencyCode.toLowerCase())) { if (!storeCurrencies.includes(currencyCode.toLowerCase())) {
throw new MedusaError( throw new MedusaError(
@@ -304,7 +304,7 @@ class RegionService extends BaseService {
) )
const countryCode = code.toUpperCase() const countryCode = code.toUpperCase()
const validCountry = countries.find(c => c.alpha2 === countryCode) const validCountry = countries.find((c) => c.alpha2 === countryCode)
if (!validCountry) { if (!validCountry) {
throw new MedusaError( throw new MedusaError(
MedusaError.Types.INVALID_DATA, MedusaError.Types.INVALID_DATA,
@@ -378,7 +378,7 @@ class RegionService extends BaseService {
* @return {Promise} the result of the delete operation * @return {Promise} the result of the delete operation
*/ */
async delete(regionId) { async delete(regionId) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const regionRepo = manager.getCustomRepository(this.regionRepository_) const regionRepo = manager.getCustomRepository(this.regionRepository_)
const region = await regionRepo.findOne({ where: { id: regionId } }) const region = await regionRepo.findOne({ where: { id: regionId } })
@@ -400,7 +400,7 @@ class RegionService extends BaseService {
* @return {Promise} the result of the update operation * @return {Promise} the result of the update operation
*/ */
async addCountry(regionId, code) { async addCountry(regionId, code) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const regionRepo = manager.getCustomRepository(this.regionRepository_) const regionRepo = manager.getCustomRepository(this.regionRepository_)
const country = await this.validateCountry_(code, regionId) const country = await this.validateCountry_(code, regionId)
@@ -410,7 +410,7 @@ class RegionService extends BaseService {
// Check if region already has country // Check if region already has country
if ( if (
region.countries && region.countries &&
region.countries.map(c => c.iso_2).includes(country.iso_2) region.countries.map((c) => c.iso_2).includes(country.iso_2)
) { ) {
return region return region
} }
@@ -437,7 +437,7 @@ class RegionService extends BaseService {
* @return {Promise} the result of the update operation * @return {Promise} the result of the update operation
*/ */
async removeCountry(regionId, code) { async removeCountry(regionId, code) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const regionRepo = manager.getCustomRepository(this.regionRepository_) const regionRepo = manager.getCustomRepository(this.regionRepository_)
const region = await this.retrieve(regionId, { relations: ["countries"] }) const region = await this.retrieve(regionId, { relations: ["countries"] })
@@ -445,13 +445,13 @@ class RegionService extends BaseService {
// Check if region contains country. If not, we simpy resolve // Check if region contains country. If not, we simpy resolve
if ( if (
region.countries && region.countries &&
!region.countries.map(c => c.iso_2).includes(code) !region.countries.map((c) => c.iso_2).includes(code)
) { ) {
return region return region
} }
region.countries = region.countries.filter( region.countries = region.countries.filter(
country => country.iso_2 !== code (country) => country.iso_2 !== code
) )
const updated = await regionRepo.save(region) const updated = await regionRepo.save(region)
@@ -473,7 +473,7 @@ class RegionService extends BaseService {
* @return {Promise} the result of the update operation * @return {Promise} the result of the update operation
*/ */
async addPaymentProvider(regionId, providerId) { async addPaymentProvider(regionId, providerId) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const regionRepo = manager.getCustomRepository(this.regionRepository_) const regionRepo = manager.getCustomRepository(this.regionRepository_)
const ppRepo = manager.getCustomRepository( const ppRepo = manager.getCustomRepository(
this.paymentProviderRepository_ this.paymentProviderRepository_
@@ -520,7 +520,7 @@ class RegionService extends BaseService {
* @return {Promise} the result of the update operation * @return {Promise} the result of the update operation
*/ */
async addFulfillmentProvider(regionId, providerId) { async addFulfillmentProvider(regionId, providerId) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const regionRepo = manager.getCustomRepository(this.regionRepository_) const regionRepo = manager.getCustomRepository(this.regionRepository_)
const fpRepo = manager.getCustomRepository( const fpRepo = manager.getCustomRepository(
this.fulfillmentProviderRepository_ this.fulfillmentProviderRepository_
@@ -564,7 +564,7 @@ class RegionService extends BaseService {
* @return {Promise} the result of the update operation * @return {Promise} the result of the update operation
*/ */
async removePaymentProvider(regionId, providerId) { async removePaymentProvider(regionId, providerId) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const regionRepo = manager.getCustomRepository(this.regionRepository_) const regionRepo = manager.getCustomRepository(this.regionRepository_)
const region = await this.retrieve(regionId, { const region = await this.retrieve(regionId, {
@@ -598,7 +598,7 @@ class RegionService extends BaseService {
* @return {Promise} the result of the update operation * @return {Promise} the result of the update operation
*/ */
async removeFulfillmentProvider(regionId, providerId) { async removeFulfillmentProvider(regionId, providerId) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const regionRepo = manager.getCustomRepository(this.regionRepository_) const regionRepo = manager.getCustomRepository(this.regionRepository_)
const region = await this.retrieve(regionId, { const region = await this.retrieve(regionId, {
+5 -7
View File
@@ -48,9 +48,7 @@ class UserService extends BaseService {
* @return {string} the validated email * @return {string} the validated email
*/ */
validateEmail_(email) { validateEmail_(email) {
const schema = Validator.string() const schema = Validator.string().email().required()
.email()
.required()
const { value, error } = schema.validate(email) const { value, error } = schema.validate(email)
if (error) { if (error) {
throw new MedusaError( throw new MedusaError(
@@ -162,7 +160,7 @@ class UserService extends BaseService {
* @return {Promise} the result of create * @return {Promise} the result of create
*/ */
async create(user, password) { async create(user, password) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const userRepo = manager.getCustomRepository(this.userRepository_) const userRepo = manager.getCustomRepository(this.userRepository_)
const validatedEmail = this.validateEmail_(user.email) const validatedEmail = this.validateEmail_(user.email)
@@ -186,7 +184,7 @@ class UserService extends BaseService {
* @return {Promise} the result of create * @return {Promise} the result of create
*/ */
async update(userId, update) { async update(userId, update) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const userRepo = manager.getCustomRepository(this.userRepository_) const userRepo = manager.getCustomRepository(this.userRepository_)
const validatedId = this.validateId_(userId) const validatedId = this.validateId_(userId)
@@ -227,7 +225,7 @@ class UserService extends BaseService {
* @return {Promise} the result of the delete operation. * @return {Promise} the result of the delete operation.
*/ */
async delete(userId) { async delete(userId) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const userRepo = manager.getCustomRepository(this.userRepository_) const userRepo = manager.getCustomRepository(this.userRepository_)
// Should not fail, if user does not exist, since delete is idempotent // Should not fail, if user does not exist, since delete is idempotent
@@ -252,7 +250,7 @@ class UserService extends BaseService {
* @return {Promise} the result of the update operation * @return {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) => {
const userRepo = manager.getCustomRepository(this.userRepository_) const userRepo = manager.getCustomRepository(this.userRepository_)
const user = await this.retrieve(userId) const user = await this.retrieve(userId)