From aab118986d508cdcdc25c3a993cbe6c35116884a Mon Sep 17 00:00:00 2001 From: Daniel Henkel Date: Wed, 29 May 2024 20:16:31 +0200 Subject: [PATCH] create idea of new important information format --- graphql/user/fields.ts | 62 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/graphql/user/fields.ts b/graphql/user/fields.ts index d717cf700..0f0497425 100644 --- a/graphql/user/fields.ts +++ b/graphql/user/fields.ts @@ -8,10 +8,9 @@ import { StudentWhereInput, PupilWhereInput, Log, - Important_information, Push_subscription as PushSubscription, } from '../generated'; -import { Root, Authorized, FieldResolver, Query, Resolver, Arg, Ctx, ObjectType, Field, Int } from 'type-graphql'; +import { Root, Authorized, FieldResolver, Query, Resolver, Arg, Ctx, ObjectType, Field, Int, createUnionType } from 'type-graphql'; import { UNAUTHENTICATED_USER, loginAsUser } from '../authentication'; import { GraphQLContext } from '../context'; import { Role } from '../authorizations'; @@ -35,6 +34,7 @@ import { createChatSignature } from '../../common/chat/create'; import assert from 'assert'; import { AchievementState } from '../../common/achievement/types'; import { getPushSubscriptions, publicKey } from '../../common/notification/channels/push'; +import { important_information_language_enum, important_information_recipients_enum } from '@prisma/client'; @ObjectType() export class UserContact implements UserContactType { @@ -57,6 +57,54 @@ export class Contact { @Field((_type) => String, { nullable: true }) chatId?: string; } + +@ObjectType() +export class ImportantInformationNew { + @Field((_type) => String) + title: string; + @Field((_type) => String) + description: string; + @Field((_type) => String) + type: 'normal' | 'sequence'; + + @Field((_type) => Int, { nullable: true }) + maxSteps: number | null; + @Field((_type) => Int, { nullable: true }) + finishedSteps: number | null; + // @Field((_type) => important_information_recipients_enum) + @Field((_type) => String) + recipients: 'students' | 'pupils'; + // @Field((_type) => important_information_language_enum) + @Field((_type) => String) + language: 'en' | 'de'; + @Field((_type) => ImportantInformationModal) + modal: typeof ImportantInformationModal; +} + +@ObjectType() +export class ImportantInformationTextModal { + @Field((_type) => String) + text: string; + @Field((_type) => String, { nullable: true }) + navigateTo: string | null; +} + +export const ImportantInformationAchievementModal = Achievement; + +export const ImportantInformationModal = createUnionType({ + name: 'Modal', + types: () => [ImportantInformationAchievementModal, ImportantInformationTextModal] as const, + resolveType: (value) => { + if ('tagline' in value) { + return ImportantInformationAchievementModal; + } + if ('text' in value) { + return ImportantInformationTextModal; + } + return undefined; + }, +}); + @Resolver((of) => UserType) export class UserFieldsResolver { @FieldResolver((returns) => String) @@ -290,20 +338,22 @@ export class UserFieldsResolver { return await getAppointmentsForUser(user, take, skip, cursor, direction); } - @FieldResolver((returns) => [Important_information]) + @FieldResolver((returns) => [ImportantInformationNew]) @Authorized(Role.ADMIN, Role.OWNER) async importantInformations(@Ctx() context: GraphQLContext) { const achievements = await getUserAchievements(context.user); return achievements .filter((a) => a.achievementType === 'SEQUENTIAL' && a.achievementState === AchievementState.ACTIVE) .map( - (a): Important_information => ({ - id: a.id, + (a): ImportantInformationNew => ({ description: a.description, title: a.title, recipients: 'students', language: 'de', - image: '', + type: 'sequence', + maxSteps: a.maxSteps, + finishedSteps: a.currentStep, + modal: a, }) ); }