From 4e73365142bc5bd2174e019552ff24d352d07a8f Mon Sep 17 00:00:00 2001 From: CDP21 <132059856+c2d13p@users.noreply.github.com> Date: Thu, 10 Oct 2024 09:26:37 +0000 Subject: [PATCH] add sanity checks for trailing spaces --- server/controllers/processes/sanityCheck.js | 34 +++++++++++++++++++-- src/processes/SanityCheck.js | 10 ++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/server/controllers/processes/sanityCheck.js b/server/controllers/processes/sanityCheck.js index af51059f..80af8292 100644 --- a/server/controllers/processes/sanityCheck.js +++ b/server/controllers/processes/sanityCheck.js @@ -31,7 +31,7 @@ router.get('/', async (req, res) => { count: { $gt: 1 } } } - ]) + ]) // find duplicated emails and alternativeEmails const duplicatedEmails = await Person.aggregate([ @@ -98,6 +98,34 @@ router.get('/', async (req, res) => { } ]) + // find persons with trailing spaces + const personsWithTrailingSpaces = await Person.aggregate([ + { + $match: { + $or: [ + { firstName: { $regex: /\s+$/, $options: "s" } }, + { lastName: { $regex: /\s+$/, $options: "s" } }, + { email: { $regex: /\s+$/, $options: "s" } }, + { alternativeEmails: { $regex: /\s+$/, $options: "s" } } + ] + } + } + ]); + + // find institutions with trailing spaces + const institutionsWithTrailingSpaces = await Institution.aggregate([ + { + $match: { + $or: [ + { name: { $regex: /\s+$/, $options: "s" } }, + { country: { $regex: /\s+$/, $options: "s" } }, + { city: { $regex: /\s+$/, $options: "s" } }, + { code: { $regex: /\s+$/, $options: "s" } } + ] + } + } + ]); + // find duplicated institutions const duplicatedInstitutions = await Institution.aggregate([ { $project: { @@ -120,6 +148,7 @@ router.get('/', async (req, res) => { } ]); + // find duplicated seminars const duplicatedSeminars = await Seminar.aggregate([ { $facet: { @@ -192,6 +221,7 @@ router.get('/', async (req, res) => { } ]) + // find duplicated events const duplicatedEvents = await Event.aggregate([ { $facet: { @@ -269,7 +299,7 @@ router.get('/', async (req, res) => { } ]) - return res.json({duplicatedNames, duplicatedEmails, missingMatricola, missingSSD, missingInstitutionCountry, duplicatedInstitutions, duplicatedSeminars, duplicatedEvents}) + return res.json({duplicatedNames, personsWithTrailingSpaces, institutionsWithTrailingSpaces, duplicatedEmails, missingMatricola, missingSSD, missingInstitutionCountry, duplicatedInstitutions, duplicatedSeminars, duplicatedEvents}) }) module.exports = router \ No newline at end of file diff --git a/src/processes/SanityCheck.js b/src/processes/SanityCheck.js index b87c2bab..6d510558 100644 --- a/src/processes/SanityCheck.js +++ b/src/processes/SanityCheck.js @@ -105,6 +105,16 @@ export default function SanityCheck() { )} /> + RenderCheckSingleItem(item, i, '/person')} + /> + RenderCheckSingleItem(item, i, '/institution')} + /> ); } \ No newline at end of file