Adds default_currency to store settings

This commit is contained in:
Sebastian Rindom
2020-06-30 22:06:01 +02:00
parent ea0c563bd6
commit 3e033bf646
3 changed files with 12 additions and 0 deletions

View File

@@ -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()),
})

View File

@@ -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: {} },
}

View File

@@ -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 => {