Skip to content

Commit 5e1c096

Browse files
committed
feat: new api reqs for finding sessions
1 parent 094a1f6 commit 5e1c096

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

apps/api/src/sessions/sessions.controller.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ export class SessionsController {
2424
findByID(@Param('id') id: string, @CurrentUser('ability') ability: AppAbility): Promise<Session> {
2525
return this.sessionsService.findById(id, { ability });
2626
}
27+
28+
@ApiOperation({ description: 'Find Session by ID' })
29+
@Post('list')
30+
@RouteAccess({ action: 'read', subject: 'Session' })
31+
findSessionList(@Query('ids') ids: string[]): Promise<Session[]> {
32+
const idArray = Array.isArray(ids) ? ids : (ids as string).split(',');
33+
return this.sessionsService.findSessionList(idArray);
34+
}
2735
}

apps/api/src/sessions/sessions.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ export class SessionsService {
103103
return session;
104104
}
105105

106+
async findSessionList(ids: string[], { ability }: EntityOperationOptions = {}) {
107+
const sessionsArray = await Promise.all(
108+
ids.map(async (id) => {
109+
const session = await this.sessionModel.findFirst({
110+
where: { AND: [accessibleQuery(ability, 'read', 'Session')], id }
111+
});
112+
if (!session) {
113+
throw new NotFoundException(`Failed to find session with ID: ${id}`);
114+
}
115+
return session;
116+
})
117+
);
118+
return sessionsArray;
119+
}
120+
106121
/** Get the subject if they exist, otherwise create them */
107122
private async resolveSubject(subjectData: CreateSubjectData) {
108123
this.loggingService.debug({ message: 'Attempting to resolve subject', subjectData });

apps/web/src/hooks/useInstrumentVisualization.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { useInstrumentInfoQuery } from '@/hooks/useInstrumentInfoQuery';
1212
import { useInstrumentRecords } from '@/hooks/useInstrumentRecords';
1313
import { useAppStore } from '@/store';
1414
import { downloadSubjectTableExcel } from '@/utils/excel';
15-
import { useFindSession } from './useFindSession';
1615

1716
type InstrumentVisualizationRecord = {
1817
[key: string]: unknown;
@@ -55,19 +54,6 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
5554
}
5655
});
5756

58-
const usersQuery = recordsQuery.data?.map((item) => {
59-
const sessionInfo = useFindSession({
60-
enabled: true,
61-
params: { id: item.sessionId }
62-
});
63-
if (sessionInfo.data) {
64-
return sessionInfo.data.userId;
65-
}
66-
return 'N/A';
67-
});
68-
69-
console.log(usersQuery);
70-
7157
const dl = (option: 'CSV' | 'CSV Long' | 'Excel' | 'Excel Long' | 'JSON' | 'TSV' | 'TSV Long') => {
7258
if (!instrument) {
7359
notifications.addNotification({ message: t('errors.noInstrumentSelected'), type: 'error' });

0 commit comments

Comments
 (0)