Skip to content

Commit

Permalink
update objectid format
Browse files Browse the repository at this point in the history
  • Loading branch information
harishv7 committed Nov 15, 2023
1 parent 6cb178a commit 152b35e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/routes/formsg/formsgEGazette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 152b35e

Please sign in to comment.