diff --git a/src/server/models/projectModel.js b/src/server/models/projectModel.js index b5e2968..a6e1e67 100644 --- a/src/server/models/projectModel.js +++ b/src/server/models/projectModel.js @@ -17,6 +17,13 @@ const isValidTerm = (value) => { }) } +const isDecimal = (value) => { + return validator.isDecimal(value + '', { + decimal_digits: '0,2', + locale: 'en-GB', + }) +} + const projectSchema = new mongoose.Schema( { // cloudwatch gives it a unique id - automatically set using a sequence!! @@ -59,7 +66,10 @@ const projectSchema = new mongoose.Schema( // project type (mostly IA, RIA, RA, or CSA) type: String, // the project's total budget (EC contrib plus partner's own contribs) - totalCost: Number, + totalCost: { + type: Number, + validate: [isDecimal, 'At most 2 decimals allowed.'], + }, // project home page url: { type: String, diff --git a/src/server/views/admin/editProject.pug b/src/server/views/admin/editProject.pug index 2c5b9aa..24bb8d9 100644 --- a/src/server/views/admin/editProject.pug +++ b/src/server/views/admin/editProject.pug @@ -71,7 +71,7 @@ block content input#projecttype.form__input(type='string', value=project.type) .form__group label.form__label(for='totalCost') Budget (optional) - input#totalCost.form__input(type='number', value=project.totalCost) + input#totalCost.form__input(type='number', step=".01", value=project.totalCost) .form__group label.form__label(for='url') Project homepage input#url.form__input(type='string', value=project.url)