Adds default_currency to store settings
This commit is contained in:
@@ -3,6 +3,7 @@ import { MedusaError, Validator } from "medusa-core-utils"
|
||||
export default async (req, res) => {
|
||||
const schema = Validator.object().keys({
|
||||
name: Validator.string(),
|
||||
default_currency: Validator.string(),
|
||||
currencies: Validator.array().items(Validator.string()),
|
||||
})
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ class StoreModel extends BaseModel {
|
||||
static modelName = "Store"
|
||||
static schema = {
|
||||
name: { type: String, required: true, default: "Medusa Store" },
|
||||
default_currency: { type: String, required: true, default: "USD" },
|
||||
currencies: { type: [String], default: [] },
|
||||
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
}
|
||||
|
||||
@@ -81,6 +81,16 @@ class StoreService extends BaseService {
|
||||
)
|
||||
}
|
||||
|
||||
if (update.default_currency) {
|
||||
update.default_currency = update.default_currency.toUpperCase()
|
||||
if (!currencies[update.default_currency]) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Invalid currency ${update.default_currency}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (update.currencies) {
|
||||
update.currencies = update.currencies.map(c => c.toUpperCase())
|
||||
update.currencies.forEach(c => {
|
||||
|
||||
Reference in New Issue
Block a user