Skip to content

Commit

Permalink
BUGFIX: Allow decimal values for project budgets in client side, and …
Browse files Browse the repository at this point in the history
…via validator serverside
  • Loading branch information
mdrescher committed Feb 8, 2021
1 parent 3e0a56e commit 7241a8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/server/models/projectModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!!
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/server/views/admin/editProject.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7241a8a

Please sign in to comment.