type Event { | type Event { | ||||
_id: UUID! | _id: UUID! | ||||
name: String | |||||
date: Date! | date: Date! | ||||
timeslots: [Timeslot!]! | timeslots: [Timeslot!]! | ||||
_organizer: UUID! | _organizer: UUID! | ||||
organizer: Organizer! | |||||
} | } | ||||
"""A date string YYYY-MM-DD""" | """A date string YYYY-MM-DD""" | ||||
} | } | ||||
type Mutation { | type Mutation { | ||||
login(token: String, passwort: String, email: String): Person | |||||
login(token: String, passwort: String, email: String): Person! | |||||
PersonRegister(passwort: String!, email: EmailAddress!, familyName: String!, givenName: String!, organizer: UUID!): Person! | PersonRegister(passwort: String!, email: EmailAddress!, familyName: String!, givenName: String!, organizer: UUID!): Person! | ||||
ConfirmMail(confirmCode: String!, email: String!): Person | |||||
PersonConfirmMail(confirmCode: String!, email: String!): Person | |||||
ChangePassword(newPassword: String!, oldPassword: String!): Boolean! | ChangePassword(newPassword: String!, oldPassword: String!): Boolean! | ||||
OrganizerRegister(ort: String, plz: Int, name: String!): Organizer! | OrganizerRegister(ort: String, plz: Int, name: String!): Organizer! | ||||
EventCreate(name: String, date: Date!, organizer: UUID!): Event! | |||||
} | } |
import { Injectable } from '@nestjs/common'; | import { Injectable } from '@nestjs/common'; | ||||
import { db } from '../db'; | |||||
import { Apparatus } from './models/Apparatus'; | import { Apparatus } from './models/Apparatus'; | ||||
import { Client } from '../client'; | import { Client } from '../client'; | ||||
import { UUID } from '../global/scalars/UUID'; | |||||
import { Service } from '../global/service' | |||||
@Injectable() | @Injectable() | ||||
export class ApparatusService { | |||||
async findOneById(id: UUID): Promise<Apparatus> { | |||||
const data = await db.fetch('apparatus', { _id: id }); | |||||
return data?.[0] || null as Apparatus; | |||||
} | |||||
async find(filter: any, limit?: number, offset?: number): Promise<Apparatus[]> { | |||||
return db.fetch('apparatus', filter, limit, offset); | |||||
export class ApparatusService extends Service<Apparatus> { | |||||
constructor() { | |||||
super(); | |||||
this.collection = 'apparatus'; | |||||
} | } | ||||
async update(id: UUID, ops: any, filter: any, client: Client): Promise<Apparatus> { | |||||
return db.doOps('apparatus', id, ops, filter, client) | |||||
async create(client: Client): Promise<Apparatus> { | |||||
return null; | |||||
} | } | ||||
} | } |
import { Injectable } from '@nestjs/common'; | import { Injectable } from '@nestjs/common'; | ||||
import { db } from '../db'; | |||||
import { Event } from './models/Event'; | import { Event } from './models/Event'; | ||||
import { Client } from '../client'; | import { Client } from '../client'; | ||||
import { UUID } from '../global/scalars/UUID'; | import { UUID } from '../global/scalars/UUID'; | ||||
import { Date } from '../global/scalars/Date'; | |||||
import { Service } from '../global/service' | |||||
@Injectable() | @Injectable() | ||||
export class EventService { | |||||
async findOneById(id: UUID): Promise<Event> { | |||||
const data = await db.fetch('event', { _id: id }); | |||||
return data?.[0] || null as Event; | |||||
export class EventService extends Service<Event> { | |||||
constructor() { | |||||
super(); | |||||
this.collection = 'event'; | |||||
} | } | ||||
async find(filter: any, limit?: number, offset?: number): Promise<Event[]> { | |||||
return db.fetch('event', filter, limit, offset); | |||||
} | |||||
async create(client: Client, date: Date, organizer: UUID, name?: string): Promise<Event> { | |||||
const neu = { | |||||
name: name || null, | |||||
date, | |||||
_organizer: organizer, | |||||
} | |||||
async update(id: UUID, ops: any, filter: any, client: Client): Promise<Event> { | |||||
return db.doOps('event', id, ops, filter, client) | |||||
return super.insert(client, neu); | |||||
} | } | ||||
} | } |
@Field(() => UUID,{ nullable: false }) | @Field(() => UUID,{ nullable: false }) | ||||
_id: UUID | _id: UUID | ||||
@Field(() => String, { nullable: true }) | |||||
name?: string | |||||
@Field(() => Date, { nullable: false }) | @Field(() => Date, { nullable: false }) | ||||
date: Date | date: Date | ||||
timeslots: Timeslot[] | timeslots: Timeslot[] | ||||
@Field(() => UUID, { nullable: false }) | @Field(() => UUID, { nullable: false }) | ||||
_organizer: Organizer | |||||
_organizer: UUID | |||||
} | } |
import { Client } from '../../client'; | import { Client } from '../../client'; | ||||
import { EventService } from '../event.service'; | import { EventService } from '../event.service'; | ||||
import { HttpException } from '@nestjs/common'; | import { HttpException } from '@nestjs/common'; | ||||
import {Date} from '../../global/scalars/Date' | |||||
import {UUID} from '../../global/scalars/UUID' | |||||
import {OrganizerService} from '../../organizer/organizer.service' | |||||
@Resolver(() => Event) | @Resolver(() => Event) | ||||
export class EventResolverM { | export class EventResolverM { | ||||
constructor( | constructor( | ||||
private readonly service: EventService, | private readonly service: EventService, | ||||
) {} | ) {} | ||||
@Mutation(() => Event, { nullable: false }) | |||||
async EventCreate( | |||||
@Context('client') client: Client, | |||||
@Args('organizer') organizer: UUID, | |||||
@Args('date') date: Date, | |||||
@Args('name', { nullable: true }) name?: string, | |||||
): Promise<Event> { | |||||
if (!client.isMaster() && !client.isOrganizer(organizer)) { | |||||
throw new HttpException('You\'re not allowed to create an Event for this organizer', 403); | |||||
} | |||||
const organizerService = new OrganizerService(); | |||||
const o = await organizerService.findOneById(organizer); | |||||
if (!o) { | |||||
throw new HttpException('Organizer-ID not found!', 404); | |||||
} | |||||
return this.service.create(client, date, organizer, name); | |||||
} | |||||
} | } |
import { UUID } from '../../global/scalars/UUID'; | import { UUID } from '../../global/scalars/UUID'; | ||||
import {Date} from '../../global/scalars/Date' | import {Date} from '../../global/scalars/Date' | ||||
import {Timeslot} from '../models/Timeslot' | import {Timeslot} from '../models/Timeslot' | ||||
import {Organizer} from '../../organizer/models/Organizer' | |||||
import {OrganizerService} from '../../organizer/organizer.service' | |||||
@Resolver(() => Event) | @Resolver(() => Event) | ||||
export class EventResolver { | export class EventResolver { | ||||
return parent._id as UUID; | return parent._id as UUID; | ||||
} | } | ||||
@ResolveField(() => String, { nullable: true }) | |||||
async name( | |||||
@Context('client') client: Client, | |||||
@Parent() parent: Event | |||||
): Promise<string> { | |||||
return parent.name; | |||||
} | |||||
@ResolveField(() => Date, { nullable: false }) | @ResolveField(() => Date, { nullable: false }) | ||||
async date( | async date( | ||||
@Context('client') client: Client, | @Context('client') client: Client, | ||||
): Promise<Timeslot[]> { | ): Promise<Timeslot[]> { | ||||
return parent.timeslots; | return parent.timeslots; | ||||
} | } | ||||
@ResolveField(() => UUID, { nullable: false }) | |||||
async _organizer( | |||||
@Context('client') client: Client, | |||||
@Parent() parent: Event | |||||
): Promise<UUID> { | |||||
return parent._organizer; | |||||
} | |||||
@ResolveField(() => Organizer, { nullable: false }) | |||||
async organizer( | |||||
@Context('client') client: Client, | |||||
@Parent() parent: Event | |||||
): Promise<Organizer> { | |||||
const organizerService = new OrganizerService(); | |||||
return organizerService.findOneById(parent._organizer); | |||||
} | |||||
} | } |
import { db } from '../db'; | |||||
import { Client } from '../client'; | |||||
import { UUID } from '../global/scalars/UUID'; | |||||
import { v4 as uuid } from 'uuid'; | |||||
export abstract class Service<E> { | |||||
protected collection: string = ''; | |||||
public async findOneById(id: UUID): Promise<E> { | |||||
const data = await db.fetch(this.collection, { _id: id }); | |||||
return data?.[0] || null as E; | |||||
} | |||||
public async find(filter: any, limit?: number, offset?: number): Promise<E[]> { | |||||
return db.fetch(this.collection, filter, limit, offset); | |||||
} | |||||
public async update(client: Client, id: UUID, ops: any, filter?: any): Promise<E> { | |||||
return db.doOps(this.collection, id, ops, filter, client); | |||||
} | |||||
protected async insert(client: Client, doc: any): Promise<E> { | |||||
doc._id = uuid(); | |||||
return db.insert(this.collection, doc, client); | |||||
} | |||||
} |
import { Injectable } from '@nestjs/common'; | import { Injectable } from '@nestjs/common'; | ||||
import { db } from '../db'; | |||||
import { Organizer } from './models/Organizer'; | import { Organizer } from './models/Organizer'; | ||||
import { Client } from '../client'; | import { Client } from '../client'; | ||||
import { UUID } from '../global/scalars/UUID'; | |||||
import { v4 as uuid } from 'uuid'; | |||||
import {Service} from '../global/service' | |||||
@Injectable() | @Injectable() | ||||
export class OrganizerService { | |||||
async findOneById(id: UUID): Promise<Organizer> { | |||||
const data = await db.fetch('organizer', { _id: id }); | |||||
return data?.[0] || null as Organizer; | |||||
} | |||||
async find(filter: any, limit?: number, offset?: number): Promise<Organizer[]> { | |||||
return db.fetch('organizer', filter, limit, offset); | |||||
} | |||||
async update(client: Client, id: UUID, ops: any, filter?: any): Promise<Organizer> { | |||||
return db.doOps('organizer', id, ops, filter, client); | |||||
export class OrganizerService extends Service<Organizer> { | |||||
constructor() { | |||||
super(); | |||||
this.collection = 'organizer'; | |||||
} | } | ||||
async create(client: Client, name: string, plz?: number, ort?: string): Promise<Organizer> { | async create(client: Client, name: string, plz?: number, ort?: string): Promise<Organizer> { | ||||
const neu = { | const neu = { | ||||
_id: uuid(), | |||||
name, | name, | ||||
plz: plz || null, | plz: plz || null, | ||||
ort: ort || null, | ort: ort || null, | ||||
} | } | ||||
return db.insert('organizer', neu, client); | |||||
return super.insert(client, neu); | |||||
} | } | ||||
} | } |
import { Injectable } from '@nestjs/common'; | import { Injectable } from '@nestjs/common'; | ||||
import { db } from '../db'; | |||||
import { Person } from './models/Person'; | import { Person } from './models/Person'; | ||||
import { Client } from '../client'; | import { Client } from '../client'; | ||||
import { UUID } from '../global/scalars/UUID'; | |||||
import { Organizer } from '../organizer/models/Organizer' | |||||
import { v4 as uuid } from 'uuid'; | import { v4 as uuid } from 'uuid'; | ||||
import {EmailAddress} from '../global/scalars/EmailAddress' | |||||
import {secureHash} from '../generate' | |||||
import { EmailAddress } from '../global/scalars/EmailAddress' | |||||
import { secureHash } from '../generate' | |||||
import { Service } from '../global/service' | |||||
@Injectable() | @Injectable() | ||||
export class PersonService { | |||||
async findOneById(id: UUID): Promise<Person> { | |||||
const data = await db.fetch('person', { _id: id }); | |||||
return data?.[0] || null as Person; | |||||
} | |||||
async find(filter: any, limit?: number, offset?: number): Promise<Person[]> { | |||||
return db.fetch('person', filter, limit, offset); | |||||
} | |||||
async update(client: Client, id: UUID, ops: any, filter?: any): Promise<Person> { | |||||
return db.doOps('person', id, ops, filter, client) | |||||
export class PersonService extends Service<Person> { | |||||
constructor() { | |||||
super(); | |||||
this.collection = 'person'; | |||||
} | } | ||||
async create(client: Client, givenName: string, familyName: string, email: EmailAddress, passwort: string): Promise<Person> { | async create(client: Client, givenName: string, familyName: string, email: EmailAddress, passwort: string): Promise<Person> { | ||||
const neu = { | const neu = { | ||||
_id: uuid(), | |||||
givenName, | givenName, | ||||
familyName, | familyName, | ||||
email, | email, | ||||
confirmCode: uuid(), | confirmCode: uuid(), | ||||
} | } | ||||
return db.insert('person', neu, client); | |||||
return super.insert(client, neu); | |||||
} | } | ||||
} | } |
private readonly service: PersonService, | private readonly service: PersonService, | ||||
) {} | ) {} | ||||
@Mutation(() => Person, { nullable: true }) | |||||
@Mutation(() => Person, { nullable: false }) | |||||
async login( | async login( | ||||
@Context('client') client: Client, | @Context('client') client: Client, | ||||
@Args('email', { nullable: true }) email?: string, | @Args('email', { nullable: true }) email?: string, | ||||
} | } | ||||
@Mutation(() => Person, { nullable: true }) | @Mutation(() => Person, { nullable: true }) | ||||
async ConfirmMail( | |||||
async PersonConfirmMail( | |||||
@Context('client') client: Client, | @Context('client') client: Client, | ||||
@Args('email') email: string, | @Args('email') email: string, | ||||
@Args('confirmCode') confirmCode: string, | @Args('confirmCode') confirmCode: string, |