Skip to content

Commit

Permalink
Required changes done
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyper3x committed Nov 12, 2024
1 parent a588419 commit a5f538e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 127 deletions.
75 changes: 21 additions & 54 deletions packages/gateway/src/features/registration/root-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import {
confirmRegistration
} from '@gateway/workflow/index'
import { getRecordById } from '@gateway/records'
import { tokenExchangeHandler } from './token-exchange'

async function getAnonymousToken() {
const res = await fetch(new URL('/anonymous-token', AUTH_URL).toString())
Expand Down Expand Up @@ -639,78 +638,46 @@ export const resolvers: GQLResolver = {

return taskEntry.resource.id
},
async confirmRegistration(_, { id, details }, { headers: authHeader }) {
const token = authHeader.Authorization.replace("Bearer ", "").trim();
const recordSpecificToken = await tokenExchangeHandler(
token,
authHeader,
id
)

authHeader.Authorization = `Bearer ${recordSpecificToken.access_token}`

async confirmRegistration(_, { id, details }, { headers: authHeader }) {
if (!inScope(authHeader, ['record.confirm-registration'])) {
throw new Error('User does not have a Confirm Registration scope');
throw new Error('User does not have a Confirm Registration scope')
}

if (!hasRecordAccess(authHeader, id)) {
throw new Error('User does not have access to the record');
throw new Error('User does not have access to the record')
}

try {
const taskEntry = await confirmRegistration(
id,
authHeader,
{
error: details.error,
registrationNumber: details.registrationNumber,
childIdentifiers: details.identifiers,
compositionId: id
}
);

return taskEntry.resource.id;
const taskEntry = await confirmRegistration(id, authHeader, {
error: details.error,
registrationNumber: details.registrationNumber,
childIdentifiers: details.identifiers,
compositionId: id
})

return taskEntry.resource.id
} catch (error) {
throw new Error(`Failed to confirm registration: ${error.message}`);
throw new Error(`Failed to confirm registration: ${error.message}`)
}
},
async rejectRegistration(
_,
{ id, details },
{ headers: authHeader }
) {

const token = authHeader.Authorization.replace("Bearer ", "").trim();
const recordSpecificToken = await tokenExchangeHandler(
token,
authHeader,
id
)

authHeader.Authorization = `Bearer ${recordSpecificToken.access_token}`

async rejectRegistration(_, { id, details }, { headers: authHeader }) {
if (!inScope(authHeader, ['record.reject-registration'])) {
throw new Error('User does not have a Reject Registration" scope');
throw new Error('User does not have a Reject Registration" scope')
}

if (!hasRecordAccess(authHeader, id)) {
throw new Error('User does not have access to the record');
throw new Error('User does not have access to the record')
}

try {
const taskEntry = await rejectRegistration(
id,
authHeader,
{
comment: details.comment || 'No comment provided',
reason: details.reason
}
);
const taskEntry = await rejectRegistration(id, authHeader, {
comment: details.comment || 'No comment provided',
reason: details.reason
})

// Return the task ID from the rejected record
return taskEntry.resource.id;
return taskEntry.resource.id
} catch (error) {
throw new Error(`Error in rejectRegistration: ${error.message}`);
throw new Error(`Error in rejectRegistration: ${error.message}`)
}
}
}
Expand Down
61 changes: 0 additions & 61 deletions packages/gateway/src/features/registration/token-exchange.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const newChannel: Channel = {
secured: false,
host: 'workflow',
port: 5050,
path: '/records/{id}/confirm',
path: '/confirm/registration',
pathTransform: '',
primary: true,
username: '',
Expand All @@ -52,7 +52,7 @@ const newChannel: Channel = {
rewriteUrlsConfig: [],
name: 'Confirm Registration',
description: 'Confirm registration & assign a BRN',
urlPattern: '^/records/{id}/confirm$',
urlPattern: '^/confirm/registration$',
priority: 1,
maxBodyAgeDays: 30,
matchContentRegex: null,
Expand Down
10 changes: 0 additions & 10 deletions packages/workflow/src/config/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ export const getRoutes = () => {
description: 'Health check endpoint'
}
},
// {
// method: 'POST',
// path: '/confirm/registration',
// handler: markEventAsRegisteredCallbackHandler,
// config: {
// tags: ['api'],
// description:
// 'Register event based on tracking id and registration number.'
// }
// },
{
method: 'POST',
path: '/records/{id}/confirm',
Expand Down

0 comments on commit a5f538e

Please sign in to comment.