Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ocrvs 6093 #768

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"p-queue": "^6.6.2",
"pino": "^5.14.0",
"regex-to-strings": "^2.1.0",
"short-uid": "^0.1.0",
"short-uuid": "^4.1.0",
"ts-node": "^10.9.1",
"tsconfig-paths": "^3.8.0",
Expand Down
10 changes: 10 additions & 0 deletions src/api/tracking-id/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as Hapi from '@hapi/hapi'
import { generateTrackingId } from './service'

export function trackingIDHandler(
request: Hapi.Request,
h: Hapi.ResponseToolkit
) {
const trackingId = generateTrackingId(request.params.eventType)
return h.response(trackingId)
}
8 changes: 8 additions & 0 deletions src/api/tracking-id/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as ShortUIDGen from 'short-uid'

export function generateTrackingId(eventType: string): string {
// using first letter of eventType for prefix
// TODO: for divorce, need to think about prefix as Death & Divorce prefix is same 'D'
const prefix = eventType.charAt(0)
return prefix.concat(new ShortUIDGen().randomUUID()).toUpperCase()
}
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { validatorsHandler } from './form/common/custom-validation-conditionals/
import { conditionalsHandler } from './form/common/custom-validation-conditionals/conditionals-handler'
import { COUNTRY_WIDE_CRUDE_DEATH_RATE } from './api/application/application-config-default'
import { handlebarsHandler } from './form/common/custom-validation-conditionals/handlebars-handler'
import { trackingIDHandler } from './api/tracking-id/handler'

export interface ITokenPayload {
sub: string
Expand Down Expand Up @@ -469,6 +470,16 @@ export async function createServer() {
}
})

server.route({
method: 'GET',
path: '/tracking-id/{eventType}',
handler: trackingIDHandler,
options: {
tags: ['api'],
description: 'Provides a tracking id'
}
})

server.ext({
type: 'onRequest',
method(request: Hapi.Request & { sentryScope?: any }, h) {
Expand Down
1 change: 1 addition & 0 deletions typings/short-uid.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'short-uid'
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9173,6 +9173,11 @@ shellwords@^0.1.1:
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==

short-uid@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/short-uid/-/short-uid-0.1.0.tgz#069d94d044fc498afb0ea7bb22c5e634979434c8"
integrity sha512-FcrUzrOPh7gZcJ9piR15qs3bTSOyZWzpPFeKYK37A4Mr20wKnwskWFdYRj+mk8AWSO1wsflM+HgyeNTbgBecPg==

short-uuid@^4.1.0:
version "4.2.2"
resolved "https://registry.yarnpkg.com/short-uuid/-/short-uuid-4.2.2.tgz#4bb3d926da04a4a5f34420d17b5551fd6d9d535c"
Expand Down
Loading