@@ -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' ;
1514import { UNAUTHENTICATED_USER , loginAsUser } from '../authentication' ;
1615import { GraphQLContext } from '../context' ;
1716import { Role } from '../authorizations' ;
@@ -35,6 +34,7 @@ import { createChatSignature } from '../../common/chat/create';
3534import assert from 'assert' ;
3635import { AchievementState } from '../../common/achievement/types' ;
3736import { getPushSubscriptions , publicKey } from '../../common/notification/channels/push' ;
37+ import { important_information_language_enum , important_information_recipients_enum } from '@prisma/client' ;
3838
3939@ObjectType ( )
4040export 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 )
61109export 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