Skip to content

Commit

Permalink
EDF: [premieroctet#128] add function to test if a string contains onl…
Browse files Browse the repository at this point in the history
…y numbers for actions params
  • Loading branch information
Bastien-Wappizy committed Dec 17, 2024
1 parent 2555b4b commit 758f6c5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions backend/web/server/plugins/entreprisedufutur/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,22 @@ const readContent = async ({ value }, user) => {
addAction('smartdiet_read_content', readContent)


const generateTables = async ({value, nb_seats, nb_tables}, user) => {

const testNumber = (value) => {
const nbRegex = new RegExp (`^[0-9]*$`)
return nbRegex.test(value)
}

const generateTables = async ({value, nb_seats, nb_tables}, user) => {

if (!value) {
throw new NotFoundError(`no tablemap id`)
}

if (!nbRegex.test(nb_seats)) {
if (!testNumber(nb_seats)) {
throw new TypeError(`nb_seats is not a number`)
}

if (!nbRegex.test(nb_tables)) {
if (!testNumber(nb_tables)) {
throw new TypeError(`nb_tables is not a number`)
}

Expand Down

0 comments on commit 758f6c5

Please sign in to comment.