-
Notifications
You must be signed in to change notification settings - Fork 73
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
Simplifying gateways' return values #7863
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
94b3485
simplifying gateways' return values
noah-brunate 1f0b4f4
odified the test file
noah-brunate 86ee8d3
made some fixes
noah-brunate 6c450a1
Merge branch 'develop' into ocrvs-2520
rikukissa bf0f77d
Merge branch 'develop' into ocrvs-2520
rikukissa 7719f0d
rectified unused variable error
noah-brunate 4ecd9f3
made some fixes
noah-brunate 1d2fdc4
Merge branch 'develop' into ocrvs-2520
Zangetsu101 d6156ef
Merge branch 'develop' into ocrvs-2520
noah-brunate 5cdfecd
Merge branch 'develop' into ocrvs-2520
Zangetsu101 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -61,6 +61,7 @@ import { | |||
markNotADuplicate | ||||
} from '@gateway/workflow/index' | ||||
import { getRecordById } from '@gateway/records' | ||||
import { Scope } from '@opencrvs/commons/authentication' | ||||
|
||||
async function getAnonymousToken() { | ||||
const res = await fetch(new URL('/anonymous-token', AUTH_URL).toString()) | ||||
|
@@ -83,9 +84,7 @@ export const resolvers: GQLResolver = { | |||
{ headers: authHeader } | ||||
): Promise<Saved<Bundle>[]> { | ||||
if (!hasScope(authHeader, 'sysadmin')) { | ||||
return await Promise.reject( | ||||
new Error('User does not have a sysadmin scope') | ||||
) | ||||
throw new Error('User does not have a sysadmin scope') | ||||
} | ||||
const res = await fetchFHIR<Saved<Bundle<Saved<Composition>>>>( | ||||
`/Composition?date=gt${fromDate.toISOString()}&date=lte${toDate.toISOString()}&_count=0`, | ||||
|
@@ -110,9 +109,7 @@ export const resolvers: GQLResolver = { | |||
{ headers: authHeader } | ||||
): Promise<Saved<Bundle>[]> { | ||||
if (!hasScope(authHeader, 'sysadmin')) { | ||||
return await Promise.reject( | ||||
new Error('User does not have a sysadmin scope') | ||||
) | ||||
throw new Error('User does not have a sysadmin scope') | ||||
} | ||||
const res = await fetchFHIR<Saved<Bundle<Saved<Composition>>>>( | ||||
`/Composition?date=gt${fromDate.toISOString()}&date=lte${toDate.toISOString()}&_count=0`, | ||||
|
@@ -143,9 +140,7 @@ export const resolvers: GQLResolver = { | |||
) | ||||
return context.record | ||||
} else { | ||||
return await Promise.reject( | ||||
new Error('User does not have a register or validate scope') | ||||
) | ||||
throw new Error('User does not have a register or validate scope') | ||||
} | ||||
}, | ||||
async fetchDeathRegistration(_, { id }, context): Promise<Saved<Bundle>> { | ||||
|
@@ -160,9 +155,7 @@ export const resolvers: GQLResolver = { | |||
) | ||||
return context.record | ||||
} else { | ||||
return await Promise.reject( | ||||
new Error('User does not have a register or validate scope') | ||||
) | ||||
throw new Error('User does not have a register or validate scope') | ||||
} | ||||
}, | ||||
async fetchMarriageRegistration( | ||||
|
@@ -181,9 +174,7 @@ export const resolvers: GQLResolver = { | |||
) | ||||
return context.record | ||||
} else { | ||||
return await Promise.reject( | ||||
new Error('User does not have a register or validate scope') | ||||
) | ||||
throw new Error('User does not have a register or validate scope') | ||||
} | ||||
}, | ||||
async queryRegistrationByIdentifier( | ||||
|
@@ -211,9 +202,7 @@ export const resolvers: GQLResolver = { | |||
|
||||
return await fetchFHIR(`/${task.focus.reference}`, authHeader) | ||||
} else { | ||||
return await Promise.reject( | ||||
new Error('User does not have a register or validate scope') | ||||
) | ||||
throw new Error('User does not have a register or validate scope') | ||||
} | ||||
}, | ||||
async fetchRegistration(_, { id }, context): Promise<Saved<Bundle>> { | ||||
|
@@ -246,9 +235,7 @@ export const resolvers: GQLResolver = { | |||
|
||||
return person | ||||
} else { | ||||
return await Promise.reject( | ||||
new Error('User does not have enough scope') | ||||
) | ||||
throw new Error('User does not have enough scope') | ||||
} | ||||
}, | ||||
async queryPersonByNidIdentifier( | ||||
|
@@ -279,9 +266,7 @@ export const resolvers: GQLResolver = { | |||
return response.data | ||||
} | ||||
} else { | ||||
return await Promise.reject( | ||||
new Error('User does not have enough scope') | ||||
) | ||||
throw new Error('User does not have enough scope') | ||||
} | ||||
}, | ||||
async fetchRegistrationCountByStatus( | ||||
|
@@ -334,9 +319,7 @@ export const resolvers: GQLResolver = { | |||
total | ||||
} | ||||
} else { | ||||
return await Promise.reject( | ||||
new Error('User does not have enough scope') | ||||
) | ||||
throw new Error('User does not have enough scope') | ||||
} | ||||
}, | ||||
async fetchRecordDetailsForVerification(_, { id }, context) { | ||||
|
@@ -382,9 +365,7 @@ export const resolvers: GQLResolver = { | |||
throw new UnassignError('User has been unassigned') | ||||
} | ||||
if (!hasScope(authHeader, 'validate')) { | ||||
return await Promise.reject( | ||||
new Error('User does not have a validate scope') | ||||
) | ||||
throw new Error('User does not have a validate scope') | ||||
} else { | ||||
return await markEventAsValidated( | ||||
id, | ||||
|
@@ -400,9 +381,7 @@ export const resolvers: GQLResolver = { | |||
throw new UnassignError('User has been unassigned') | ||||
} | ||||
if (!hasScope(authHeader, 'validate')) { | ||||
return await Promise.reject( | ||||
new Error('User does not have a validate scope') | ||||
) | ||||
throw new Error('User does not have a validate scope') | ||||
} | ||||
return await markEventAsValidated( | ||||
id, | ||||
|
@@ -417,9 +396,7 @@ export const resolvers: GQLResolver = { | |||
throw new UnassignError('User has been unassigned') | ||||
} | ||||
if (!hasScope(authHeader, 'validate')) { | ||||
return await Promise.reject( | ||||
new Error('User does not have a validate scope') | ||||
) | ||||
throw new Error('User does not have a validate scope') | ||||
} else { | ||||
return await markEventAsValidated( | ||||
id, | ||||
|
@@ -437,9 +414,7 @@ export const resolvers: GQLResolver = { | |||
if (hasScope(authHeader, 'register')) { | ||||
return markEventAsRegistered(id, authHeader, EVENT_TYPE.BIRTH, details) | ||||
} else { | ||||
return await Promise.reject( | ||||
new Error('User does not have a register scope') | ||||
) | ||||
throw new Error('User does not have a register scope') | ||||
} | ||||
}, | ||||
async markDeathAsRegistered(_, { id, details }, { headers: authHeader }) { | ||||
|
@@ -450,9 +425,7 @@ export const resolvers: GQLResolver = { | |||
if (hasScope(authHeader, 'register')) { | ||||
return markEventAsRegistered(id, authHeader, EVENT_TYPE.DEATH, details) | ||||
} else { | ||||
return await Promise.reject( | ||||
new Error('User does not have a register scope') | ||||
) | ||||
throw new Error('User does not have a register scope') | ||||
} | ||||
}, | ||||
async markMarriageAsRegistered( | ||||
|
@@ -472,9 +445,7 @@ export const resolvers: GQLResolver = { | |||
details | ||||
) | ||||
} else { | ||||
return await Promise.reject( | ||||
new Error('User does not have a register scope') | ||||
) | ||||
throw new Error('User does not have a register scope') | ||||
} | ||||
}, | ||||
async markEventAsVoided( | ||||
|
@@ -487,13 +458,11 @@ export const resolvers: GQLResolver = { | |||
throw new UnassignError('User has been unassigned') | ||||
} | ||||
if (!inScope(authHeader, ['register', 'validate'])) { | ||||
return await Promise.reject( | ||||
new Error('User does not have a register or validate scope') | ||||
) | ||||
throw new Error('User does not have a register or validate scope') | ||||
} | ||||
const taskEntry = await rejectDeclaration(id, authHeader, reason, comment) | ||||
if (!taskEntry) { | ||||
return await Promise.reject(new Error('Task not found')) | ||||
throw new Error('Task not found') | ||||
} | ||||
|
||||
// return the taskId | ||||
|
@@ -509,9 +478,7 @@ export const resolvers: GQLResolver = { | |||
throw new UnassignError('User has been unassigned') | ||||
} | ||||
if (!inScope(authHeader, ['register', 'validate'])) { | ||||
return await Promise.reject( | ||||
new Error('User does not have a register or validate scope') | ||||
) | ||||
throw new Error('User does not have a register or validate scope') | ||||
} | ||||
const taskEntry = await archiveRegistration( | ||||
id, | ||||
|
@@ -529,9 +496,7 @@ export const resolvers: GQLResolver = { | |||
throw new UnassignError('User has been unassigned') | ||||
} | ||||
if (!inScope(authHeader, ['register', 'validate'])) { | ||||
return await Promise.reject( | ||||
new Error('User does not have a register or validate scope') | ||||
) | ||||
throw new Error('User does not have a register or validate scope') | ||||
} | ||||
|
||||
const { taskId, prevRegStatus } = await reinstateRegistration( | ||||
|
@@ -593,16 +558,12 @@ export const resolvers: GQLResolver = { | |||
|
||||
return composition.id | ||||
} else { | ||||
return await Promise.reject( | ||||
new Error('User does not have a register scope') | ||||
) | ||||
throw new Error('User does not have a register scope') | ||||
} | ||||
}, | ||||
async markEventAsUnassigned(_, { id }, { headers: authHeader }) { | ||||
if (!inScope(authHeader, ['register', 'validate'])) { | ||||
return await Promise.reject( | ||||
new Error('User does not have a register or validate scope') | ||||
) | ||||
throw new Error('User does not have a register or validate scope') | ||||
} | ||||
const task = getTaskFromSavedBundle( | ||||
await unassignRegistration(id, authHeader) | ||||
|
@@ -621,9 +582,7 @@ export const resolvers: GQLResolver = { | |||
throw new UnassignError('User has been unassigned') | ||||
} | ||||
if (!inScope(authHeader, ['register', 'validate'])) { | ||||
return await Promise.reject( | ||||
new Error('User does not have a register or validate scope') | ||||
) | ||||
throw new Error('User does not have a register or validate scope') | ||||
} | ||||
|
||||
const taskEntry = await duplicateRegistration( | ||||
|
@@ -637,7 +596,7 @@ export const resolvers: GQLResolver = { | |||
return taskEntry.resource.id | ||||
}, | ||||
async confirmRegistration(_, { id }, { headers: authHeader }) { | ||||
if (!inScope(authHeader, ['record.confirm-registration'])) { | ||||
if (!inScope(authHeader, ['record.confirm-registration'] as unknown as Scope[])) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
as unknown as Scope[] should be needed
|
||||
throw new Error( | ||||
'User does not have a "record.confirm-registration" scope' | ||||
) | ||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an unnecessary assertion: the compiler seems to already know it's a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the parameter "language" was being implicitly given an any type which was causing an error when i ran the tests