import { Args , Query , Resolver } from '@nestjs/graphql' ; import { Event } from '@medium-stories/entities' ; import { EventService } from '../services/event.service' ; @ Resolver ( 'Event' ) export class EventResolver { constructor ( private readonly eventService ) { } @ Query ( 'events' ) async getEvents ( @ Args ( 'offset' ) offset ? , @ Args ( 'limit' ) limit ? , @ Args ( 'order' ) order ? , @ Args ( 'excludeFirst' ) excludeFirst ? , @ Args ( 'excludeLast' ) excludeLast ? ) { const result = await this . eventService . find ( { take : limit , skip : offset , order : order ? JSON . parse ( order ) : null } ) ; let finishResult = excludeFirst ? result . slice ( 1 , result . length ) : result ; finishResult = excludeLast ? finishResult . slice ( 0 , result . length - 1 ) : finishResult ; return finishResult ; } @ Query ( 'event' ) async getEvent ( @ Args ( 'id' ) id ) { return this . eventService . findOne ( id ) ; } @ Query ( 'eventLast' ) async getEventLAst ( ) { const result = await this . eventService . find ( { take : 1 , skip : 0 , order : JSON . parse ( '{"id":"DESC"}' ) } ) ; return result && result . length ? result [ 0 ] : null ; } }