Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

50 lines
1.4KB

  1. import { Context, Parent, ResolveField, Resolver } from '@nestjs/graphql';
  2. import { Person } from '../models/Person';
  3. import { Client } from '../../client';
  4. import { UUID } from '../../global/scalars/UUID';
  5. import {EmailAddress} from '../../global/scalars/EmailAddress'
  6. @Resolver(() => Person)
  7. export class PersonResolver {
  8. @ResolveField(() => UUID, { nullable: false })
  9. async _id(
  10. @Context('client') client: Client,
  11. @Parent() parent: Person
  12. ): Promise<UUID> {
  13. return parent._id as UUID;
  14. }
  15. @ResolveField(() => String, { nullable: false })
  16. async givenName(
  17. @Context('client') client: Client,
  18. @Parent() parent: Person
  19. ): Promise<string> {
  20. return parent.givenName;
  21. }
  22. @ResolveField(() => String, { nullable: false })
  23. async familyName(
  24. @Context('client') client: Client,
  25. @Parent() parent: Person
  26. ): Promise<string> {
  27. return parent.familyName;
  28. }
  29. @ResolveField(() => String, { nullable: true })
  30. async token(
  31. @Context('client') client: Client,
  32. @Parent() parent: Person
  33. ): Promise<string> {
  34. if (!client.isSelf(parent._id)) return null;
  35. return client.getToken();
  36. }
  37. @ResolveField(() => EmailAddress, { nullable: true })
  38. async email(
  39. @Context('client') client: Client,
  40. @Parent() parent: Person
  41. ): Promise<EmailAddress> {
  42. if (!client.isMaster() && !client.isSelf(parent._id)) return null;
  43. return parent.email;
  44. }
  45. }