Skip to content

Commit

Permalink
create idea of new important information format
Browse files Browse the repository at this point in the history
  • Loading branch information
dhenkel92 committed May 29, 2024
1 parent a4960fa commit aab1189
Showing 1 changed file with 56 additions and 6 deletions.
62 changes: 56 additions & 6 deletions graphql/user/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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,
})
);
}
Expand Down

0 comments on commit aab1189

Please sign in to comment.