This commit is contained in:
Sebastian Rindom committed 2020-07-06 11:52:16 +02:00
1 parent 2491bd6779
commit f9b232da54
9 files changed
+49 -10

No files matched your search

@@ -11,9 +11,12 @@ class BaseFulfillmentService extends BaseService {
super() super()
} }
getFulfillmentOptions() { getIdentifier() {
return this.constructor.identifier
} }
getFulfillmentOptions() {}
validateFulfillmentData(data, cart) { validateFulfillmentData(data, cart) {
throw Error("validateFulfillmentData must be overridden by the child class") throw Error("validateFulfillmentData must be overridden by the child class")
} }
@@ -11,6 +11,10 @@ class BasePaymentService extends BaseService {
super() super()
} }
getIdentifier() {
return this.constructor.identifier
}
/** /**
* Used to create a payment to be processed with the service's payment gateway. * Used to create a payment to be processed with the service's payment gateway.
* @param cart {object} - the cart that the payment should cover. * @param cart {object} - the cart that the payment should cover.
@@ -5,7 +5,7 @@ export default async (req, res) => {
name: Validator.string().required(), name: Validator.string().required(),
region_id: Validator.string().required(), region_id: Validator.string().required(),
provider_id: Validator.string().required(), provider_id: Validator.string().required(),
profile_id: Validator.string().required(), profile_id: Validator.string(),
data: Validator.object().required(), data: Validator.object().required(),
price: Validator.object() price: Validator.object()
.keys({ .keys({
@@ -1,8 +1,11 @@
import _ from "lodash"
export default async (req, res) => { export default async (req, res) => {
const { optionId } = req.params
try { try {
const query = _.pick(req.query, ["region_id", "region_id[]"])
const optionService = req.scope.resolve("shippingOptionService") const optionService = req.scope.resolve("shippingOptionService")
const data = await optionService.list() const data = await optionService.list(query)
res.status(200).json({ shipping_options: data }) res.status(200).json({ shipping_options: data })
} catch (err) { } catch (err) {
+20 -1
View File
@@ -2,6 +2,25 @@ export default async ({ container }) => {
const storeService = container.resolve("storeService") const storeService = container.resolve("storeService")
const profileService = container.resolve("shippingProfileService") const profileService = container.resolve("shippingProfileService")
await storeService.create() let payIds
try {
const payProviders = container.resolve("paymentProviders")
payIds = payProviders.map(p => p.getIdentifier())
} catch (e) {
payIds = []
}
let fulfilIds
try {
const fulfilProviders = container.resolve("fulfillmentProviders")
fulfilIds = fulfilProviders.map(p => p.getIdentifier())
} catch (e) {
fulfilIds = []
}
await storeService.create({
fulfillment_providers: fulfilIds,
payment_providers: payIds,
})
await profileService.createDefault() await profileService.createDefault()
} }
+2
View File
@@ -7,6 +7,8 @@ class StoreModel extends BaseModel {
name: { type: String, required: true, default: "Medusa Store" }, name: { type: String, required: true, default: "Medusa Store" },
default_currency: { type: String, required: true, default: "USD" }, default_currency: { type: String, required: true, default: "USD" },
currencies: { type: [String], default: [] }, currencies: { type: [String], default: [] },
payment_providers: { type: [String], default: [] },
fulfillment_providers: { type: [String], default: [] },
metadata: { type: mongoose.Schema.Types.Mixed, default: {} }, metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
} }
} }
+1 -1
View File
@@ -154,7 +154,7 @@ class RegionService extends BaseService {
} }
const existing = await this.regionModel_.findOne({ countries: countryCode }) const existing = await this.regionModel_.findOne({ countries: countryCode })
if (existing && existing._id !== id) { if (existing && !existing._id.equals(id)) {
throw new MedusaError( throw new MedusaError(
MedusaError.Types.NOT_ALLOWED, MedusaError.Types.NOT_ALLOWED,
`${country.name} already exists in ${existing.name}, delete it in that region before adding it` `${country.name} already exists in ${existing.name}, delete it in that region before adding it`
@@ -79,7 +79,13 @@ class ShippingOptionService extends BaseService {
* @return {Promise} the result of the find operation * @return {Promise} the result of the find operation
*/ */
list(selector) { list(selector) {
return this.optionModel_.find(selector) const query = {}
if (selector.region_id !== undefined) {
query.region_id = selector.region_id
}
return this.optionModel_.find(query)
} }
/** /**
+5 -3
View File
@@ -43,10 +43,12 @@ class StoreService extends BaseService {
* Creates a store if it doesn't already exist. * Creates a store if it doesn't already exist.
* @return {Promise<Store>} the store. * @return {Promise<Store>} the store.
*/ */
async create() { async create(providers) {
const store = await this.retrieve() let store = await this.retrieve()
if (!store) { if (!store) {
return this.storeModel_.create({}) return this.storeModel_.create(providers)
} else {
store = await this.update(providers)
} }
return store return store