Defaults
This commit is contained in:
@@ -11,9 +11,12 @@ class BaseFulfillmentService extends BaseService {
|
||||
super()
|
||||
}
|
||||
|
||||
getFulfillmentOptions() {
|
||||
getIdentifier() {
|
||||
return this.constructor.identifier
|
||||
}
|
||||
|
||||
getFulfillmentOptions() {}
|
||||
|
||||
validateFulfillmentData(data, cart) {
|
||||
throw Error("validateFulfillmentData must be overridden by the child class")
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ class BasePaymentService extends BaseService {
|
||||
super()
|
||||
}
|
||||
|
||||
getIdentifier() {
|
||||
return this.constructor.identifier
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to create a payment to be processed with the service's payment gateway.
|
||||
* @param cart {object} - the cart that the payment should cover.
|
||||
|
||||
@@ -5,7 +5,7 @@ export default async (req, res) => {
|
||||
name: Validator.string().required(),
|
||||
region_id: Validator.string().required(),
|
||||
provider_id: Validator.string().required(),
|
||||
profile_id: Validator.string().required(),
|
||||
profile_id: Validator.string(),
|
||||
data: Validator.object().required(),
|
||||
price: Validator.object()
|
||||
.keys({
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import _ from "lodash"
|
||||
|
||||
export default async (req, res) => {
|
||||
const { optionId } = req.params
|
||||
try {
|
||||
const query = _.pick(req.query, ["region_id", "region_id[]"])
|
||||
|
||||
const optionService = req.scope.resolve("shippingOptionService")
|
||||
const data = await optionService.list()
|
||||
const data = await optionService.list(query)
|
||||
|
||||
res.status(200).json({ shipping_options: data })
|
||||
} catch (err) {
|
||||
|
||||
@@ -2,6 +2,25 @@ export default async ({ container }) => {
|
||||
const storeService = container.resolve("storeService")
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ class StoreModel extends BaseModel {
|
||||
name: { type: String, required: true, default: "Medusa Store" },
|
||||
default_currency: { type: String, required: true, default: "USD" },
|
||||
currencies: { type: [String], default: [] },
|
||||
payment_providers: { type: [String], default: [] },
|
||||
fulfillment_providers: { type: [String], default: [] },
|
||||
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ class RegionService extends BaseService {
|
||||
}
|
||||
|
||||
const existing = await this.regionModel_.findOne({ countries: countryCode })
|
||||
if (existing && existing._id !== id) {
|
||||
if (existing && !existing._id.equals(id)) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_ALLOWED,
|
||||
`${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
|
||||
*/
|
||||
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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,10 +43,12 @@ class StoreService extends BaseService {
|
||||
* Creates a store if it doesn't already exist.
|
||||
* @return {Promise<Store>} the store.
|
||||
*/
|
||||
async create() {
|
||||
const store = await this.retrieve()
|
||||
async create(providers) {
|
||||
let store = await this.retrieve()
|
||||
if (!store) {
|
||||
return this.storeModel_.create({})
|
||||
return this.storeModel_.create(providers)
|
||||
} else {
|
||||
store = await this.update(providers)
|
||||
}
|
||||
|
||||
return store
|
||||
|
||||
Reference in New Issue
Block a user