Skip to content

Commit d52992e

Browse files
committed
create idea of new important information format
1 parent a4960fa commit d52992e

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

common/achievement/derive.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ async function derivePupilMatching(user: User, pupil: Pupil, result: achievement
104104
});
105105

106106
const userAchievement = userAchievements.find((row) => row.template.group === 'pupil_new_match');
107+
const matches = await prisma.match.findMany({ where: { pupilId: pupil.id } });
108+
109+
// if (!userAchievement && matches.length > 0) {
110+
// return [];
111+
// }
112+
107113
if (!userAchievement) {
108114
const groups = await getAchievementTemplates(TemplateSelectEnum.BY_GROUP);
109115
if (!groups.has('pupil_new_match') || groups.get('pupil_new_match').length === 0) {

graphql/user/fields.ts

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import {
88
StudentWhereInput,
99
PupilWhereInput,
1010
Log,
11-
Important_information,
1211
Push_subscription as PushSubscription,
1312
} from '../generated';
14-
import { Root, Authorized, FieldResolver, Query, Resolver, Arg, Ctx, ObjectType, Field, Int } from 'type-graphql';
13+
import { Root, Authorized, FieldResolver, Query, Resolver, Arg, Ctx, ObjectType, Field, Int, createUnionType } from 'type-graphql';
1514
import { UNAUTHENTICATED_USER, loginAsUser } from '../authentication';
1615
import { GraphQLContext } from '../context';
1716
import { Role } from '../authorizations';
@@ -35,6 +34,7 @@ import { createChatSignature } from '../../common/chat/create';
3534
import assert from 'assert';
3635
import { AchievementState } from '../../common/achievement/types';
3736
import { getPushSubscriptions, publicKey } from '../../common/notification/channels/push';
37+
import { important_information_language_enum, important_information_recipients_enum } from '@prisma/client';
3838

3939
@ObjectType()
4040
export class UserContact implements UserContactType {
@@ -57,6 +57,54 @@ export class Contact {
5757
@Field((_type) => String, { nullable: true })
5858
chatId?: string;
5959
}
60+
61+
@ObjectType()
62+
export class ImportantInformationNew {
63+
@Field((_type) => String)
64+
title: string;
65+
@Field((_type) => String)
66+
description: string;
67+
@Field((_type) => String)
68+
type: 'normal' | 'sequence';
69+
70+
@Field((_type) => Int, { nullable: true })
71+
maxSteps: number | null;
72+
@Field((_type) => Int, { nullable: true })
73+
finishedSteps: number | null;
74+
// @Field((_type) => important_information_recipients_enum)
75+
@Field((_type) => String)
76+
recipients: 'students' | 'pupils';
77+
// @Field((_type) => important_information_language_enum)
78+
@Field((_type) => String)
79+
language: 'en' | 'de';
80+
@Field((_type) => ImportantInformationModal)
81+
modal: typeof ImportantInformationModal;
82+
}
83+
84+
@ObjectType()
85+
export class ImportantInformationTextModal {
86+
@Field((_type) => String)
87+
text: string;
88+
@Field((_type) => String, { nullable: true })
89+
navigateTo: string | null;
90+
}
91+
92+
export const ImportantInformationAchievementModal = Achievement;
93+
94+
export const ImportantInformationModal = createUnionType({
95+
name: 'Modal',
96+
types: () => [ImportantInformationAchievementModal, ImportantInformationTextModal] as const,
97+
resolveType: (value) => {
98+
if ('tagline' in value) {
99+
return ImportantInformationAchievementModal;
100+
}
101+
if ('text' in value) {
102+
return ImportantInformationTextModal;
103+
}
104+
return undefined;
105+
},
106+
});
107+
60108
@Resolver((of) => UserType)
61109
export class UserFieldsResolver {
62110
@FieldResolver((returns) => String)
@@ -290,20 +338,22 @@ export class UserFieldsResolver {
290338
return await getAppointmentsForUser(user, take, skip, cursor, direction);
291339
}
292340

293-
@FieldResolver((returns) => [Important_information])
341+
@FieldResolver((returns) => [ImportantInformationNew])
294342
@Authorized(Role.ADMIN, Role.OWNER)
295343
async importantInformations(@Ctx() context: GraphQLContext) {
296344
const achievements = await getUserAchievements(context.user);
297345
return achievements
298346
.filter((a) => a.achievementType === 'SEQUENTIAL' && a.achievementState === AchievementState.ACTIVE)
299347
.map(
300-
(a): Important_information => ({
301-
id: a.id,
348+
(a): ImportantInformationNew => ({
302349
description: a.description,
303350
title: a.title,
304351
recipients: 'students',
305352
language: 'de',
306-
image: '',
353+
type: 'sequence',
354+
maxSteps: a.maxSteps,
355+
finishedSteps: a.currentStep,
356+
modal: a,
307357
})
308358
);
309359
}

0 commit comments

Comments
 (0)