-
Notifications
You must be signed in to change notification settings - Fork 16
Add username to export #1227
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
Add username to export #1227
Changes from all commits
f94f1aa
4c2f8ce
afc75ec
67a2fec
50b12da
582d8ff
d9864a5
72a3659
57ed21f
3dc66b2
3106352
6aefd4f
1cf8276
3a2e07c
7247e53
784d576
ebe30a4
29a4895
aaa9e19
441218d
c5e9c6d
b58dd17
7c08a6b
9ce8825
e4fca74
5248ffe
78d4456
b366c83
d42bac2
ca014eb
b534f9b
85034fe
3dce520
1f2a215
98b220d
f7e7ab6
7c4c807
688e779
b6e51b3
33f53b1
6e8bb64
945e6be
490c373
2b4e691
abd0ddd
a5f0b71
ddf1ac2
4e86bec
12a49c4
0267288
017cdf5
e4a6175
9fda503
2d5cf94
b5664b1
350964d
9a505d1
8daaf56
78717a1
2a3f220
db573d1
fc31951
02845cd
e071da8
d81b8c5
0fc8f52
30dc81c
cb271da
a4584e9
5392053
14a2220
e1f9a75
e7161a8
4890054
58407e1
191127e
6d8fcca
31da08f
1c3d955
85809da
066c5a9
a954235
856d824
efe9d87
9c15607
8349bd0
adf6df7
fad53a5
19515b8
895495b
c070dec
20c046c
7e71a32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -46,7 +46,9 @@ export class SessionsService { | |||||||||||||
| let group: Group | null = null; | ||||||||||||||
| if (groupId && !subject.groupIds.includes(groupId)) { | ||||||||||||||
| group = await this.groupsService.findById(groupId); | ||||||||||||||
| await this.subjectsService.addGroupForSubject(subject.id, group.id); | ||||||||||||||
| if (group) { | ||||||||||||||
| await this.subjectsService.addGroupForSubject(subject.id, group.id); | ||||||||||||||
| } | ||||||||||||||
joshunrau marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const { id } = await this.sessionModel.create({ | ||||||||||||||
|
|
@@ -94,6 +96,26 @@ export class SessionsService { | |||||||||||||
| }); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| async findAllIncludeUsernames(groupId?: string, { ability }: EntityOperationOptions = {}) { | ||||||||||||||
| const sessionsWithUsers = await this.sessionModel.findMany({ | ||||||||||||||
| include: { | ||||||||||||||
| subject: true, | ||||||||||||||
| user: { | ||||||||||||||
| select: { | ||||||||||||||
| username: true | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| }, | ||||||||||||||
| where: { | ||||||||||||||
| AND: [accessibleQuery(ability, 'read', 'Session'), { groupId }] | ||||||||||||||
| } | ||||||||||||||
| }); | ||||||||||||||
| if (!sessionsWithUsers) { | ||||||||||||||
| throw new NotFoundException(`Failed to find users`); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+113
to
+115
Contributor
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. Remove incorrect null check and fix error message.
Apply this diff: - if (!sessionsWithUsers) {
- throw new NotFoundException(`Failed to find users`);
+ if (sessionsWithUsers.length === 0) {
+ throw new NotFoundException(`Failed to find sessions`);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Collaborator
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. @david-roper yes
Contributor
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.
|
||||||||||||||
| return sessionsWithUsers; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| async findById(id: string, { ability }: EntityOperationOptions = {}) { | ||||||||||||||
| const session = await this.sessionModel.findFirst({ | ||||||||||||||
| where: { AND: [accessibleQuery(ability, 'read', 'Session')], id } | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,7 +88,7 @@ export const Sidebar = () => { | |
| > | ||
| <h5 className="text-sm font-medium">{t('common.sessionInProgress')}</h5> | ||
| <hr className="my-1.5 h-[1px] border-none bg-slate-700" /> | ||
| {isSubjectWithPersonalInfo(currentSession.subject) ? ( | ||
| {isSubjectWithPersonalInfo(currentSession.subject!) ? ( | ||
|
Collaborator
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. Is the old PR superseded by this? If so, please close it. |
||
| <div data-testid="current-session-info"> | ||
| <p>{`${t('core.fullName')}: ${currentSession.subject.firstName} ${currentSession.subject.lastName}`}</p> | ||
| <p> | ||
|
|
@@ -100,7 +100,7 @@ export const Sidebar = () => { | |
| </div> | ||
| ) : ( | ||
| <div data-testid="current-session-info"> | ||
| <p>ID: {removeSubjectIdScope(currentSession.subject.id)}</p> | ||
| <p>ID: {removeSubjectIdScope(currentSession.subject!.id)}</p> | ||
| </div> | ||
| )} | ||
| </motion.div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { $SessionWithUser } from '@opendatacapture/schemas/session'; | ||
| import type { SessionWithUserQueryParams } from '@opendatacapture/schemas/session'; | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import axios from 'axios'; | ||
|
|
||
| //Change this query to into a hook method and name it useFindSessionQuery | ||
|
|
||
| //Change the api call to have an include tag which includes the username from users | ||
|
|
||
| //Change the return type to | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type UseSessionOptions = { | ||
| enabled?: boolean; | ||
| params: SessionWithUserQueryParams; | ||
| }; | ||
|
|
||
| export const useFindSessionQuery = ( | ||
|
Collaborator
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. This should be named |
||
| { enabled, params }: UseSessionOptions = { | ||
| enabled: true, | ||
| params: {} | ||
| } | ||
| ) => { | ||
| return useQuery({ | ||
| enabled, | ||
| queryFn: async () => { | ||
| const response = await axios.get('/v1/sessions', { | ||
| params | ||
| }); | ||
| return $SessionWithUser.array().parseAsync(response.data); | ||
| }, | ||
| queryKey: ['sessions', ...Object.values(params)] | ||
| }); | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.