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) => {
|
export default async (req, res) => {
|
||||||
const schema = Validator.object().keys({
|
const schema = Validator.object().keys({
|
||||||
name: Validator.string(),
|
name: Validator.string(),
|
||||||
|
default_currency: Validator.string(),
|
||||||
currencies: Validator.array().items(Validator.string()),
|
currencies: Validator.array().items(Validator.string()),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ class StoreModel extends BaseModel {
|
|||||||
static modelName = "Store"
|
static modelName = "Store"
|
||||||
static schema = {
|
static schema = {
|
||||||
name: { type: String, required: true, default: "Medusa Store" },
|
name: { type: String, required: true, default: "Medusa Store" },
|
||||||
|
default_currency: { type: String, required: true, default: "USD" },
|
||||||
currencies: { type: [String], default: [] },
|
currencies: { type: [String], default: [] },
|
||||||
metadata: { type: mongoose.Schema.Types.Mixed, 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) {
|
if (update.currencies) {
|
||||||
update.currencies = update.currencies.map(c => c.toUpperCase())
|
update.currencies = update.currencies.map(c => c.toUpperCase())
|
||||||
update.currencies.forEach(c => {
|
update.currencies.forEach(c => {
|
||||||
|
|||||||
Reference in New Issue
Block a user