-
Notifications
You must be signed in to change notification settings - Fork 5
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
NON-270: Improve REST client #238
Conversation
…methods allowing for query parameters as well as body payloads
username: string | ||
name?: string | ||
active?: boolean | ||
authSource?: string | ||
uuid?: string | ||
userId?: string | ||
staffId?: number // deprecated, use userId | ||
activeCaseLoadId?: string // deprecated, use user roles api |
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.
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.
slightly odd that some of these fields are prison specific - though activeCaseLoadId was here before anyway
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 fine for now as it matches the auth response. I guess auth ideally would expose this as a union type
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.
it took me quite a while to unpick what user-type info comes from where (the stuff in non-associations is more complex as it also loads caseloads) and this is the simplest thing i felt was meaningful… it's what hmpps-auth (allegedly) returns. in practice, i dunno whether all "auth sources" provide some of these fields. it felt like a sensible thing to mark the nullable ones in hmpps-auth as possibly-undefined here. the link to the UserDetail object above suggests getting caseload stuff from other apis.
still, whether this set of fields is good or good enough, i think it's nice to wire it up into res.locals
– right?
auth ideally would expose this as a union type
<3
interface Locals { | ||
user: Express.User | ||
} |
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 setUpCurrentUser
middleware always populates res.locals.user
via the user service
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.
Nice work!
query?: string | ||
interface Request { | ||
path: string | ||
query?: object | 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.
think this will need to be Record<string, unknown>
otherwise you won't be able to pass anything other than empty object?
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.
Record<string, unknown>
"satisfies" object
. i just used the official type accepted by the superagent function:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/8139a88dd28ea580afedc673c18ceb24df95effb/types/superagent/index.d.ts#L166
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.
LGTM!
REST client improvements:
encodeURIComponent
)unknown
)Also, propagate user types into
res.locals
in request handlers.Before:
After: