# ------------------------------------------------------ | |||||
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY) | |||||
# ------------------------------------------------------ | |||||
type Person { | |||||
_id: UUID! | |||||
givenName: String! | |||||
familyName: String! | |||||
email: EmailAddress! | |||||
token: String | |||||
} | |||||
"""UUID""" | |||||
scalar UUID | |||||
""" | |||||
A field whose value conforms to the standard internet email address format as specified in RFC822: https://www.w3.org/Protocols/rfc822/. | |||||
""" | |||||
scalar EmailAddress | |||||
type Apparatus { | |||||
_id: UUID! | |||||
name: String! | |||||
logo: String | |||||
} | |||||
type Organizer { | |||||
_id: UUID! | |||||
name: String! | |||||
logo: String | |||||
_admins: [UUID!] | |||||
_organizers: [UUID!] | |||||
} | |||||
type Query { | |||||
Person(id: UUID!): Person | |||||
PersonFind(offset: Int, limit: Int, email: String, familyName: String, givenName: String): [Person!] | |||||
Apparatus(id: UUID!): Apparatus | |||||
ApparatusFind(offset: Int, limit: Int, name: String): [Apparatus!] | |||||
Organizer(id: UUID!): Organizer | |||||
OrganizerFind(offset: Int, limit: Int, name: String): [Organizer!] | |||||
} | |||||
type Mutation { | |||||
login(token: String, passwort: String, email: String): Person | |||||
} |
import { Test, TestingModule } from '@nestjs/testing'; | |||||
import { AppController } from './app.controller'; | |||||
import { AppService } from './app.service'; | |||||
describe('AppController', () => { | |||||
let appController: AppController; | |||||
beforeEach(async () => { | |||||
const app: TestingModule = await Test.createTestingModule({ | |||||
controllers: [AppController], | |||||
providers: [AppService], | |||||
}).compile(); | |||||
appController = app.get<AppController>(AppController); | |||||
}); | |||||
describe('root', () => { | |||||
it('should return "Hello World!"', () => { | |||||
expect(appController.getHello()).toBe('Hello World!'); | |||||
}); | |||||
}); | |||||
}); |
import { Controller, Get } from '@nestjs/common'; | |||||
import { AppService } from './app.service'; | |||||
@Controller() | |||||
export class AppController { | |||||
constructor(private readonly appService: AppService) {} | |||||
@Get() | |||||
getHello(): string { | |||||
return this.appService.getHello(); | |||||
} | |||||
} |
import { UUID } from './global/scalars/UUID'; | import { UUID } from './global/scalars/UUID'; | ||||
import { GlobalModule } from './global/global.module'; | import { GlobalModule } from './global/global.module'; | ||||
import {PersonModule} from './person/person.module' | |||||
import { PersonModule } from './person/person.module'; | |||||
import { ApparatusModule } from './apparatus/apparatus.module'; | |||||
import { OrganizerModule } from './organizer/organizer.module' | |||||
@Module({ | @Module({ | ||||
imports: [ | imports: [ | ||||
GlobalModule, | GlobalModule, | ||||
PersonModule, | PersonModule, | ||||
ApparatusModule, | |||||
OrganizerModule, | |||||
GraphQLModule.forRoot({ | GraphQLModule.forRoot({ | ||||
installSubscriptionHandlers: true, | installSubscriptionHandlers: true, | ||||
autoSchemaFile: 'schema.gql', | autoSchemaFile: 'schema.gql', |
import { Injectable } from '@nestjs/common'; | |||||
@Injectable() | |||||
export class AppService { | |||||
getHello(): string { | |||||
return 'Hello World!'; | |||||
} | |||||
} |
import { Module } from '@nestjs/common'; | |||||
import { ApparatusResolverQ } from './resolver/apparatus.query'; | |||||
import { ApparatusResolverM } from './resolver/apparatus.mutation'; | |||||
import { ApparatusService } from './apparatus.service'; | |||||
import { ApparatusResolver } from './resolver/apparatus'; | |||||
@Module({ | |||||
providers: [ | |||||
ApparatusResolverQ, ApparatusResolverM, | |||||
ApparatusService, | |||||
ApparatusResolver, | |||||
], | |||||
}) | |||||
export class ApparatusModule {} |
import { Injectable } from '@nestjs/common'; | |||||
import { db } from '../db'; | |||||
import { Apparatus } from './models/Apparatus'; | |||||
import { Client } from '../client'; | |||||
import { UUID } from '../global/scalars/UUID'; | |||||
@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); | |||||
} | |||||
async update(id: UUID, ops: any, filter: any, client: Client): Promise<Apparatus> { | |||||
return db.doOps('apparatus', id, ops, filter, client) | |||||
} | |||||
} |
import { Field, ObjectType } from '@nestjs/graphql'; | |||||
import { UUID } from '../../global/scalars/UUID'; | |||||
@ObjectType() | |||||
export class Apparatus { | |||||
@Field(() => UUID,{ nullable: false }) | |||||
_id: UUID | |||||
@Field(() => String, { nullable: false }) | |||||
name: string | |||||
@Field(() => String, { nullable: true }) | |||||
logo?: string | |||||
} |
import { Args, Context, Mutation, Resolver } from '@nestjs/graphql'; | |||||
import { Apparatus } from '../models/Apparatus'; | |||||
import { Client } from '../../client'; | |||||
import { ApparatusService } from '../apparatus.service'; | |||||
import { HttpException } from '@nestjs/common'; | |||||
@Resolver(() => Apparatus) | |||||
export class ApparatusResolverM { | |||||
constructor( | |||||
private readonly service: ApparatusService, | |||||
) {} | |||||
} |
import { Args, Context, Int, Query, Resolver } from '@nestjs/graphql'; | |||||
import { Apparatus } from '../models/Apparatus'; | |||||
import { ApparatusService } from '../apparatus.service'; | |||||
import { Client } from '../../client'; | |||||
import { HttpException } from '@nestjs/common'; | |||||
import { UUID } from '../../global/scalars/UUID'; | |||||
@Resolver(() => Apparatus) | |||||
export class ApparatusResolverQ { | |||||
constructor( | |||||
private readonly service: ApparatusService, | |||||
) {} | |||||
@Query(() => Apparatus, { nullable: true }) | |||||
async Apparatus( | |||||
@Context('client') client: Client, | |||||
@Args('id') id: UUID, | |||||
): Promise<Apparatus> { | |||||
return await this.service.findOneById(id) as Apparatus; | |||||
} | |||||
@Query(() => [Apparatus], { nullable: true }) | |||||
async ApparatusFind( | |||||
@Context('client') client: Client, | |||||
@Args('name', { nullable: true }) name?: string, | |||||
@Args('limit', { type: () => Int, nullable: true }) limit?: number, | |||||
@Args('offset', { type: () => Int, nullable: true }) offset?: number, | |||||
): Promise<Apparatus[]> { | |||||
const filter: any = {} | |||||
if (name) filter.name = name; | |||||
let tmp = await this.service.find(filter, limit, offset); | |||||
if (tmp.length > 1000) throw new HttpException('too many results', 413); | |||||
return tmp | |||||
} | |||||
} |
import { Context, Parent, ResolveField, Resolver } from '@nestjs/graphql'; | |||||
import { Apparatus } from '../models/Apparatus'; | |||||
import { Client } from '../../client'; | |||||
import { UUID } from '../../global/scalars/UUID'; | |||||
@Resolver(() => Apparatus) | |||||
export class ApparatusResolver { | |||||
@ResolveField(() => UUID, { nullable: false }) | |||||
async _id( | |||||
@Context('client') client: Client, | |||||
@Parent() parent: Apparatus | |||||
): Promise<UUID> { | |||||
return parent._id as UUID; | |||||
} | |||||
@ResolveField(() => String, { nullable: false }) | |||||
async name( | |||||
@Context('client') client: Client, | |||||
@Parent() parent: Apparatus | |||||
): Promise<string> { | |||||
return parent.name; | |||||
} | |||||
@ResolveField(() => String, { nullable: true }) | |||||
async logo( | |||||
@Context('client') client: Client, | |||||
@Parent() parent: Apparatus | |||||
): Promise<string> { | |||||
return parent.logo; | |||||
} | |||||
} |
console.log('initialisiere Datenbank...'); | console.log('initialisiere Datenbank...'); | ||||
const ed = db.getDB(); | const ed = db.getDB(); | ||||
const colls = ['person','organizer','event']; | |||||
const colls = ['person','organizer','event','apparatus']; | |||||
if (reset) { | if (reset) { | ||||
const test = await pr('Wirklich löschen? Bitte mit "JA!" bestätigen!'); | const test = await pr('Wirklich löschen? Bitte mit "JA!" bestätigen!'); |
import { Field, ObjectType } from '@nestjs/graphql'; | |||||
import { UUID } from '../../global/scalars/UUID'; | |||||
@ObjectType() | |||||
export class Organizer { | |||||
@Field(() => UUID,{ nullable: false }) | |||||
_id: UUID | |||||
@Field(() => String, { nullable: false }) | |||||
name: string | |||||
@Field(() => String, { nullable: true }) | |||||
logo?: string | |||||
@Field(() => [UUID], { nullable: true }) | |||||
_admins?: UUID[] | |||||
@Field(() => [UUID], { nullable: true }) | |||||
_organizers?: UUID[] | |||||
} |
import { Module } from '@nestjs/common'; | |||||
import { OrganizerResolverQ } from './resolver/organizer.query'; | |||||
import { OrganizerResolverM } from './resolver/organizer.mutation'; | |||||
import { OrganizerService } from './organizer.service'; | |||||
import { OrganizerResolver } from './resolver/organizer'; | |||||
@Module({ | |||||
providers: [ | |||||
OrganizerResolverQ, OrganizerResolverM, | |||||
OrganizerService, | |||||
OrganizerResolver, | |||||
], | |||||
}) | |||||
export class OrganizerModule {} |
import { Injectable } from '@nestjs/common'; | |||||
import { db } from '../db'; | |||||
import { Organizer } from './models/Organizer'; | |||||
import { Client } from '../client'; | |||||
import { UUID } from '../global/scalars/UUID'; | |||||
@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(id: UUID, ops: any, filter: any, client: Client): Promise<Organizer> { | |||||
return db.doOps('organizer', id, ops, filter, client) | |||||
} | |||||
} |
import { Args, Context, Mutation, Resolver } from '@nestjs/graphql'; | |||||
import { Organizer } from '../models/Organizer'; | |||||
import { Client } from '../../client'; | |||||
import { OrganizerService } from '../organizer.service'; | |||||
import { HttpException } from '@nestjs/common'; | |||||
@Resolver(() => Organizer) | |||||
export class OrganizerResolverM { | |||||
constructor( | |||||
private readonly service: OrganizerService, | |||||
) {} | |||||
} |
import { Args, Context, Int, Query, Resolver } from '@nestjs/graphql'; | |||||
import { Organizer } from '../models/Organizer'; | |||||
import { OrganizerService } from '../organizer.service'; | |||||
import { Client } from '../../client'; | |||||
import { HttpException } from '@nestjs/common'; | |||||
import { UUID } from '../../global/scalars/UUID'; | |||||
@Resolver(() => Organizer) | |||||
export class OrganizerResolverQ { | |||||
constructor( | |||||
private readonly service: OrganizerService, | |||||
) {} | |||||
@Query(() => Organizer, { nullable: true }) | |||||
async Organizer( | |||||
@Context('client') client: Client, | |||||
@Args('id') id: UUID, | |||||
): Promise<Organizer> { | |||||
return await this.service.findOneById(id) as Organizer; | |||||
} | |||||
@Query(() => [Organizer], { nullable: true }) | |||||
async OrganizerFind( | |||||
@Context('client') client: Client, | |||||
@Args('name', { nullable: true }) name?: string, | |||||
@Args('limit', { type: () => Int, nullable: true }) limit?: number, | |||||
@Args('offset', { type: () => Int, nullable: true }) offset?: number, | |||||
): Promise<Organizer[]> { | |||||
const filter: any = {} | |||||
if (name) filter.name = name; | |||||
let tmp = await this.service.find(filter, limit, offset); | |||||
if (tmp.length > 1000) throw new HttpException('too many results', 413); | |||||
return tmp | |||||
} | |||||
} |
import { Context, Parent, ResolveField, Resolver } from '@nestjs/graphql'; | |||||
import { Organizer } from '../models/Organizer'; | |||||
import { Client } from '../../client'; | |||||
import { UUID } from '../../global/scalars/UUID'; | |||||
@Resolver(() => Organizer) | |||||
export class OrganizerResolver { | |||||
@ResolveField(() => UUID, { nullable: false }) | |||||
async _id( | |||||
@Context('client') client: Client, | |||||
@Parent() parent: Organizer | |||||
): Promise<UUID> { | |||||
return parent._id as UUID; | |||||
} | |||||
@ResolveField(() => String, { nullable: false }) | |||||
async name( | |||||
@Context('client') client: Client, | |||||
@Parent() parent: Organizer | |||||
): Promise<string> { | |||||
return parent.name; | |||||
} | |||||
@ResolveField(() => String, { nullable: true }) | |||||
async logo( | |||||
@Context('client') client: Client, | |||||
@Parent() parent: Organizer | |||||
): Promise<string> { | |||||
return parent.logo; | |||||
} | |||||
@ResolveField(() => [UUID], { nullable: true }) | |||||
async _admins( | |||||
@Context('client') client: Client, | |||||
@Parent() parent: Organizer | |||||
): Promise<UUID[]> { | |||||
if (!client.isMaster()) return null; | |||||
return parent._admins; | |||||
} | |||||
@ResolveField(() => [UUID], { nullable: true }) | |||||
async _organizers( | |||||
@Context('client') client: Client, | |||||
@Parent() parent: Organizer | |||||
): Promise<UUID[]> { | |||||
if (!client.isMaster()) return null; | |||||
return parent._organizers; | |||||
} | |||||
} |
@Context('client') client: Client, | @Context('client') client: Client, | ||||
@Args('id') id: UUID, | @Args('id') id: UUID, | ||||
): Promise<Person> { | ): Promise<Person> { | ||||
if (!client.isMaster()) return null; | |||||
return await this.service.findOneById(id) as Person; | return await this.service.findOneById(id) as Person; | ||||
} | } | ||||