From 152b35e828fe2b9b1b96f888a32c2e736e7a9986 Mon Sep 17 00:00:00 2001 From: Harish V Date: Thu, 9 Nov 2023 17:45:59 +0800 Subject: [PATCH] update objectid format --- src/routes/formsg/formsgEGazette.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/routes/formsg/formsgEGazette.ts b/src/routes/formsg/formsgEGazette.ts index 51a18ba42..061ff9744 100644 --- a/src/routes/formsg/formsgEGazette.ts +++ b/src/routes/formsg/formsgEGazette.ts @@ -50,6 +50,18 @@ function toTimestamp(strDate: string) { return datum.getTime() } +function formatObjectId(objectId: string) { + // Remove apostrophes and whitespaces + let formattedId = objectId.replace(/['\s]/g, "") + + // If the first character is a dash, remove it + if (formattedId.startsWith("-")) { + formattedId = formattedId.substring(1) + } + + return formattedId +} + function getS3ObjectUrl( bucketName: string, region: string, @@ -240,9 +252,13 @@ export class FormsgEGazetteRouter { } if (gazetteSubCategory) { - newSearchRecord.objectID = `${gazetteCategory}-${gazetteSubCategory}-${gazetteNotificationNum}` + newSearchRecord.objectID = formatObjectId( + `${gazetteCategory}-${gazetteSubCategory}-${gazetteNotificationNum}-${gazetteTitle}` + ) } else { - newSearchRecord.objectID = `${gazetteCategory}-${gazetteNotificationNum}` + newSearchRecord.objectID = formatObjectId( + `${gazetteCategory}-${gazetteNotificationNum}-${gazetteTitle}` + ) } logger.info(