From d52992eee727eee5245cd70844fd930b1dd8120e 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 --- common/achievement/derive.ts | 6 ++++ graphql/user/fields.ts | 62 ++++++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/common/achievement/derive.ts b/common/achievement/derive.ts index d6aed3946..c7d9052c1 100644 --- a/common/achievement/derive.ts +++ b/common/achievement/derive.ts @@ -104,6 +104,12 @@ async function derivePupilMatching(user: User, pupil: Pupil, result: achievement }); const userAchievement = userAchievements.find((row) => row.template.group === 'pupil_new_match'); + const matches = await prisma.match.findMany({ where: { pupilId: pupil.id } }); + + // if (!userAchievement && matches.length > 0) { + // return []; + // } + if (!userAchievement) { const groups = await getAchievementTemplates(TemplateSelectEnum.BY_GROUP); if (!groups.has('pupil_new_match') || groups.get('pupil_new_match').length === 0) { 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, }) ); }