mirror of
https://gitplac.si/aljaxus/upn-qr.git
synced 2025-12-17 04:00:59 +00:00
simplified the query checking
This commit is contained in:
69
src/index.js
69
src/index.js
@@ -13,55 +13,34 @@ app.use(cors())
|
|||||||
app.get('/api/qrcode', async (req, res) => {
|
app.get('/api/qrcode', async (req, res) => {
|
||||||
const errors = []
|
const errors = []
|
||||||
|
|
||||||
if (!req.query.client_name) errors.push("client_name is required")
|
function check (name, rgxp) {
|
||||||
if (!String(req.query.client_name).match(/^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)) {
|
if (!req.query[name]) errors.push(`${name} is required`)
|
||||||
errors.push("client_name does not match the required format")
|
else {
|
||||||
}
|
req.query[name] = String(req.query[name]).trim()
|
||||||
if (!req.query.client_address) errors.push("client_address is required")
|
if (!String(req.query[name]).match(rgxp)) {
|
||||||
if (!String(req.query.client_address).match(/^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)) {
|
errors.push(`${name} does not match the required format`)
|
||||||
errors.push("client_address does not match the required format")
|
}
|
||||||
}
|
}
|
||||||
if (!req.query.client_city) errors.push("client_city is required")
|
|
||||||
if (!String(req.query.client_city).match(/^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)) {
|
|
||||||
errors.push("client_city does not match the required format")
|
|
||||||
}
|
|
||||||
if (!req.query.amount) errors.push("amount is required")
|
|
||||||
if (!String(req.query.amount).match(/^(?=.{11}$)[0]{1,11}[0-9]{0,11}$/)) {
|
|
||||||
errors.push("amount does not match the required format")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check('client_name', /^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)
|
||||||
|
check('client_address', /^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)
|
||||||
|
check('client_city', /^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)
|
||||||
|
check('amount', /^(?=.{11}$)[0]{1,11}[0-9]{0,11}$/)
|
||||||
|
check('payment_purpose', /^[A-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,40}[A-Z0-9ČŠŽĐ])?$/i)
|
||||||
|
check('iban', /^[A-Z]{2}\d{17}$/)
|
||||||
|
check('reference', /^[A-Z]{2}[0-9\-]{1,24}$/)
|
||||||
|
check('issuer_name', /^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)
|
||||||
|
check('issuer_address', /^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)
|
||||||
|
check('issuer_city', /^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)
|
||||||
|
|
||||||
// SET DEFAULT PURPOSE_CODE
|
// SET DEFAULT PURPOSE_CODE
|
||||||
if (!req.query.purpose_code) req.query.purpose_code = "OTHR"
|
if (!req.query.purpose_code) req.query.purpose_code = "OTHR"
|
||||||
if (!String(req.query.purpose_code).match(/^[A-Z]{4}$/)) {
|
else {
|
||||||
errors.push("purpose_code does not match the required format")
|
req.query.amount = String(req.query.amount).trim()
|
||||||
}
|
if (!String(req.query.purpose_code).match(/^[A-Z]{4}$/)) {
|
||||||
|
errors.push("purpose_code does not match the required format")
|
||||||
if (!req.query.payment_purpose) errors.push("payment_purpose is required")
|
}
|
||||||
if (!String(req.query.payment_purpose).match(/^[A-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,40}[A-Z0-9ČŠŽĐ])?$/i)) {
|
|
||||||
errors.push("payment_purpose does not match the required format")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!req.query.iban) errors.push("iban is required")
|
|
||||||
if (!String(req.query.iban).match(/^[A-Z]{2}\d{17}$/)) {
|
|
||||||
errors.push("iban does not match the required format")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!req.query.reference) errors.push("reference is required")
|
|
||||||
if (!String(req.query.reference).match(/^[A-Z]{2}[0-9\-]{1,24}$/)) {
|
|
||||||
errors.push("reference does not match the required format")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!req.query.issuer_name) errors.push("issuer_name is required")
|
|
||||||
if (!String(req.query.issuer_name).match(/^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)) {
|
|
||||||
errors.push("issuer_name does not match the required format")
|
|
||||||
}
|
|
||||||
if (!req.query.issuer_address) errors.push("issuer_address is required")
|
|
||||||
if (!String(req.query.issuer_address).match(/^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)) {
|
|
||||||
errors.push("issuer_address does not match the required format")
|
|
||||||
}
|
|
||||||
if (!req.query.issuer_city) errors.push("issuer_city is required")
|
|
||||||
if (!String(req.query.issuer_city).match(/^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)) {
|
|
||||||
errors.push("issuer_city does not match the required format")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errors.length > 0) return res.status(400).send({
|
if (errors.length > 0) return res.status(400).send({
|
||||||
|
|||||||
Reference in New Issue
Block a user