Skip to content

Commit 0b31dbb

Browse files
committed
add chatbots to OLAT API
1 parent cfe8f88 commit 0b31dbb

5 files changed

Lines changed: 72 additions & 0 deletions

File tree

apps/olat-api/src/services.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,25 @@ export async function getCourseActivityTypes(
9595
},
9696
select: {
9797
isGamificationEnabled: true,
98+
permissions: {
99+
where: { userId: account.userId },
100+
select: { permissionLevel: true },
101+
},
98102
liveQuizzes: { where: { isDeleted: false } },
99103
practiceQuizzes: { where: { isDeleted: false } },
100104
microLearnings: { where: { isDeleted: false } },
105+
chatbots: { select: { id: true } },
101106
},
102107
})
103108
if (!course) return null
104109

110+
const isManager = course.permissions.some(
111+
(permission) =>
112+
permission.permissionLevel === 'OWNER' ||
113+
permission.permissionLevel === 'ADMIN'
114+
)
115+
const hasChatbots = course.chatbots.length > 0
116+
105117
const mapSubselection: Record<
106118
string,
107119
LiveQuiz[] | PracticeQuiz[] | MicroLearning[]
@@ -122,6 +134,20 @@ export async function getCourseActivityTypes(
122134
olatConfigurationKey,
123135
isSubselectionRequired,
124136
}) => {
137+
if (olatConfigurationKey === 'chatbot') {
138+
return isManager && hasChatbots
139+
? {
140+
id,
141+
title_de: titleDE,
142+
title_en: titleEN,
143+
title_fr: titleFR,
144+
title_it: titleIT,
145+
olatConfigurationKey,
146+
isSubselectionRequired,
147+
}
148+
: []
149+
}
150+
125151
// Subselection activities: only include if they have items
126152
if (olatConfigurationKey in mapSubselection) {
127153
return {
@@ -183,6 +209,35 @@ export async function getActivities(
183209
})
184210
if (!account) return null
185211

212+
if (activityTypeKey === 'chatbot') {
213+
const course = await prisma.course.findUnique({
214+
where: {
215+
id: courseID,
216+
permissions: {
217+
some: {
218+
userId: account.userId,
219+
permissionLevel: { in: ['OWNER', 'ADMIN'] },
220+
},
221+
},
222+
},
223+
select: {
224+
chatbots: {
225+
select: { id: true, name: true },
226+
orderBy: { name: 'asc' },
227+
},
228+
},
229+
})
230+
if (!course) return null
231+
232+
return course.chatbots.map((chatbot) => ({
233+
id: chatbot.id,
234+
title_de: chatbot.name,
235+
title_en: chatbot.name,
236+
title_fr: chatbot.name,
237+
title_it: chatbot.name,
238+
}))
239+
}
240+
186241
const course = await prisma.course.findUnique({
187242
where: {
188243
id: courseID,

apps/olat-api/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const activityOlatConfigurationKeys = [
3434
'live-quiz',
3535
'practice-quiz',
3636
'micro-learning',
37+
'chatbot',
3738
] as const // NOTE: add more if required
3839
export type ActivityOlatConfigurationKey =
3940
(typeof activityOlatConfigurationKeys)[number]

apps/olat-api/static/activityTypes.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@
5454
"isSubselectionRequired": true,
5555
"isEmailTransferRequired": false
5656
},
57+
{
58+
"id": "CHATBOT",
59+
"title_de": "Chatbot",
60+
"title_en": "Chatbot",
61+
"title_fr": "Chatbot",
62+
"title_it": "Chatbot",
63+
"path": "/chatbot",
64+
"olatConfigurationKey": "chatbot",
65+
"isSubselectionRequired": true,
66+
"isEmailTransferRequired": false
67+
},
5768
{
5869
"id": "COURSE_LEADERBOARD",
5970
"title_de": "Kurs-Rangliste",

apps/olat-api/static/openapi.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ components:
229229
- live-quiz
230230
- practice-quiz
231231
- micro-learning
232+
- chatbot
232233
- course-leaderboard
233234
- manage-account
234235
- docs

apps/olat-api/test/docker/Dockerfile.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ RUN echo '#!/bin/bash\n\
1313
\n\
1414
cd /usr/src/app\n\
1515
\n\
16+
# Install dependencies in-container (linux)\n\
17+
echo "Installing dependencies..."\n\
18+
pnpm install --frozen-lockfile\n\
19+
\n\
1620
# Ensure PostgreSQL is ready\n\
1721
echo "Waiting for PostgreSQL to be ready..."\n\
1822
for i in {1..10}; do\n\

0 commit comments

Comments
 (0)