Merge branch 'main' of github.com:flotte-meets-hwr-db/apollo-server into main

pull/20/head
leonnicolas 4 years ago
commit 1545cce614

@ -26,7 +26,7 @@ import { Equipment } from '../../model/Equipment';
import { Engagement } from '../../model/Engagement'; import { Engagement } from '../../model/Engagement';
import { Provider } from '../../model/Provider'; import { Provider } from '../../model/Provider';
import { TimeFrame } from '../../model/TimeFrame'; import { TimeFrame } from '../../model/TimeFrame';
import { ActionLogger, deleteEntity, LockUtils } from './utils'; import { ActionLogger, deleteEntity, getAllEntity, LockUtils } from './utils';
import { EquipmentType } from '../../model/EquipmentType'; import { EquipmentType } from '../../model/EquipmentType';
import { BikeEventType } from '../../model/BikeEventType'; import { BikeEventType } from '../../model/BikeEventType';
import { UserInputError } from 'apollo-server-express'; import { UserInputError } from 'apollo-server-express';
@ -42,14 +42,8 @@ export class CargoBikeAPI extends DataSource {
this.connection = getConnection(); this.connection = getConnection();
} }
async getCargoBikes (offset: number, limit: number) { async getCargoBikes (offset?: number, limit?: number) {
return await this.connection.createQueryBuilder() return await getAllEntity(this.connection, CargoBike, 'cb', offset, limit);
.select('cargoBike')
.from(CargoBike, 'cargoBike')
.orderBy('name', 'ASC')
.offset(offset)
.limit(limit)
.getMany();
} }
/** /**
@ -221,14 +215,22 @@ export class CargoBikeAPI extends DataSource {
.loadOne(); .loadOne();
} }
async bikeEventsByCargoBikeId (id: number, offset: number = 0, limit:number = 100) { async bikeEventsByCargoBikeId (id: number, offset?: number, limit?: number) {
return await this.connection.getRepository(CargoBike) if (offset === null || limit === null) {
.createQueryBuilder('cb') return await this.connection.getRepository(CargoBike)
.skip(offset) .createQueryBuilder('cb')
.take(limit) .relation(CargoBike, 'bikeEvents')
.relation(CargoBike, 'bikeEvents') .of(id)
.of(id) .loadMany();
.loadMany(); } else {
return await this.connection.getRepository(CargoBike)
.createQueryBuilder('cb')
.skip(offset)
.take(limit)
.relation(CargoBike, 'bikeEvents')
.of(id)
.loadMany();
}
} }
async createBikeEventType (bikeEventType: any) { async createBikeEventType (bikeEventType: any) {
@ -267,22 +269,12 @@ export class CargoBikeAPI extends DataSource {
return await this.bikeEventTypeById(bikeEventType.id); return await this.bikeEventTypeById(bikeEventType.id);
} }
async bikeEventTypes (offset: number, limit: number) { async bikeEventTypes (offset?: number, limit?: number) {
return await this.connection.getRepository(BikeEventType) return await getAllEntity(this.connection, BikeEventType, 'bet', offset, limit);
.createQueryBuilder('bet')
.select()
.skip(offset)
.take(limit)
.getMany();
} }
async bikeEvents (offset: number, limit: number) { async bikeEvents (offset?: number, limit?: number) {
return await this.connection.getRepository(BikeEvent) return await getAllEntity(this.connection, BikeEvent, 'be', offset, limit);
.createQueryBuilder('be')
.select()
.skip(offset)
.take(limit)
.getMany();
} }
async bikeEventTypeById (id: number) { async bikeEventTypeById (id: number) {
@ -343,12 +335,22 @@ export class CargoBikeAPI extends DataSource {
* @param limit * @param limit
* @param id * @param id
*/ */
async equipmentByCargoBikeId (offset: number, limit: number, id: number) { async equipmentByCargoBikeId (id: number, offset?: number, limit?: number) {
return await this.connection.getRepository(Equipment) if (offset == null || limit === null) {
.createQueryBuilder('equipment') return await this.connection.getRepository(Equipment)
.select() .createQueryBuilder('equipment')
.where('equipment."cargoBikeId" = :id', { id: id }) .select()
.getMany(); .where('equipment."cargoBikeId" = :id', { id: id })
.getMany();
} else {
return await this.connection.getRepository(Equipment)
.createQueryBuilder('equipment')
.select()
.where('equipment."cargoBikeId" = :id', { id: id })
.skip(offset)
.take(limit)
.getMany();
}
} }
async createEquipment ({ equipment }: { equipment: any }) { async createEquipment ({ equipment }: { equipment: any }) {

@ -21,7 +21,7 @@ import { DataSource } from 'apollo-datasource';
import { Connection, EntityManager, getConnection } from 'typeorm'; import { Connection, EntityManager, getConnection } from 'typeorm';
import { ContactInformation } from '../../model/ContactInformation'; import { ContactInformation } from '../../model/ContactInformation';
import { Person } from '../../model/Person'; import { Person } from '../../model/Person';
import { ActionLogger, deleteEntity, LockUtils } from './utils'; import { ActionLogger, deleteEntity, getAllEntity, LockUtils } from './utils';
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
import { LendingStation } from '../../model/LendingStation'; import { LendingStation } from '../../model/LendingStation';
@ -32,13 +32,8 @@ export class ContactInformationAPI extends DataSource {
this.connection = getConnection(); this.connection = getConnection();
} }
async contactInformation (offset: number, limit: number) { async contactInformation (offset?: number, limit?: number) {
return await this.connection.getRepository(ContactInformation) return await getAllEntity(this.connection, ContactInformation, 'ci', offset, limit);
.createQueryBuilder('ci')
.select()
.offset(offset)
.limit(limit)
.getMany();
} }
async contactInformationById (id: number) { async contactInformationById (id: number) {
@ -91,13 +86,8 @@ export class ContactInformationAPI extends DataSource {
return await deleteEntity(this.connection, Person, 'p', id, userId); return await deleteEntity(this.connection, Person, 'p', id, userId);
} }
async persons (offset: number, limit: number) { async persons (offset?: number, limit?: number) {
return await this.connection.getRepository(Person) return await getAllEntity(this.connection, Person, 'p', offset, limit);
.createQueryBuilder('person')
.select()
.skip(offset)
.take(limit)
.getMany();
} }
async personById (id: number) { async personById (id: number) {

@ -24,7 +24,7 @@ import { Connection, EntityManager, getConnection } from 'typeorm';
import { CargoBike } from '../../model/CargoBike'; import { CargoBike } from '../../model/CargoBike';
import { LendingStation } from '../../model/LendingStation'; import { LendingStation } from '../../model/LendingStation';
import { TimeFrame } from '../../model/TimeFrame'; import { TimeFrame } from '../../model/TimeFrame';
import { ActionLogger, deleteEntity, genDateRange, LockUtils } from './utils'; import { ActionLogger, deleteEntity, genDateRange, getAllEntity, LockUtils } from './utils';
export class LendingStationAPI extends DataSource { export class LendingStationAPI extends DataSource {
connection : Connection connection : Connection
@ -44,14 +44,8 @@ export class LendingStationAPI extends DataSource {
/** /**
* get all lendingStations * get all lendingStations
*/ */
async lendingStations (offset: number, limit: number) { async lendingStations (offset?: number, limit?: number) {
return await this.connection.getRepository(LendingStation) return await getAllEntity(this.connection, LendingStation, 'ls', offset, limit);
.createQueryBuilder('lendingStation')
.select()
.offset(offset)
.limit(limit)
.orderBy('name', 'ASC')
.getMany() || new GraphQLError('Internal Server Error: could not query data from table lendingStation');
} }
/** /**
@ -79,13 +73,8 @@ export class LendingStationAPI extends DataSource {
.loadOne(); .loadOne();
} }
async timeFrames (offset: number, limit: number) { async timeFrames (offset?: number, limit?: number) {
return await this.connection.getRepository(TimeFrame) return await getAllEntity(this.connection, TimeFrame, 'tf', offset, limit);
.createQueryBuilder('timeframe')
.select()
.offset(offset)
.limit(limit)
.getMany() || [];
} }
async timeFramesByCargoBikeId (id: number) { async timeFramesByCargoBikeId (id: number) {

@ -23,7 +23,7 @@ import { ContactInformation } from '../../model/ContactInformation';
import { Engagement } from '../../model/Engagement'; import { Engagement } from '../../model/Engagement';
import { Participant } from '../../model/Participant'; import { Participant } from '../../model/Participant';
import { EngagementType } from '../../model/EngagementType'; import { EngagementType } from '../../model/EngagementType';
import { ActionLogger, deleteEntity, genDateRange, LockUtils } from './utils'; import { ActionLogger, deleteEntity, genDateRange, getAllEntity, LockUtils } from './utils';
import { UserInputError } from 'apollo-server-express'; import { UserInputError } from 'apollo-server-express';
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
@ -42,13 +42,8 @@ export class ParticipantAPI extends DataSource {
.getOne(); .getOne();
} }
async getParticipants (offset: number, limit: number) { async getParticipants (offset?: number, limit?: number) {
return await this.connection.getRepository(Participant) return await getAllEntity(this.connection, Participant, 'p', offset, limit);
.createQueryBuilder('participant')
.select()
.offset(offset)
.limit(limit)
.getMany();
} }
async participantByEngagementId (id: number) { async participantByEngagementId (id: number) {
@ -84,17 +79,24 @@ export class ParticipantAPI extends DataSource {
.getMany(); .getMany();
} }
async engagementByCargoBikeId (offset: number, limit: number, id: number) { async engagementByCargoBikeId (id: number, offset?: number, limit?: number) {
return await this.connection.getRepository(Engagement) if (limit === null || offset === null) {
.createQueryBuilder('engagement') return await this.connection.getRepository(Engagement)
.select() .createQueryBuilder('engagement')
.where('engagement."cargoBikeId" = :id', { .select()
id: id .where('engagement."cargoBikeId" = :id', { id: id })
}) .orderBy('engagement."dateRange"', 'DESC')
.skip(offset) .getMany();
.take(limit) } else {
.orderBy('engagement."dateRange"', 'DESC') return await this.connection.getRepository(Engagement)
.getMany(); .createQueryBuilder('engagement')
.select()
.where('engagement."cargoBikeId" = :id', { id: id })
.skip(offset)
.take(limit)
.orderBy('engagement."dateRange"', 'DESC')
.getMany();
}
} }
async currentEngagementByCargoBikeId (id: number) { async currentEngagementByCargoBikeId (id: number) {
@ -107,13 +109,8 @@ export class ParticipantAPI extends DataSource {
.getMany(); .getMany();
} }
async engagements (offset: number, limit: number) { async engagements (offset?: number, limit?: number) {
return await this.connection.getRepository(Engagement) return await getAllEntity(this.connection, Engagement, 'e', offset, limit);
.createQueryBuilder('e')
.select()
.skip(offset)
.take(limit)
.getMany();
} }
async engagementById (id: number) { async engagementById (id: number) {
@ -132,13 +129,8 @@ export class ParticipantAPI extends DataSource {
.getOne(); .getOne();
} }
async engagementTypes (offset: number, limit: number) { async engagementTypes (offset?: number, limit?: number) {
return await this.connection.getRepository(EngagementType) return await getAllEntity(this.connection, Engagement, 'e', offset, limit);
.createQueryBuilder('et')
.select()
.skip(offset)
.take(limit)
.getMany();
} }
async engagementTypeByEngagementId (id: number) { async engagementTypeByEngagementId (id: number) {

@ -24,7 +24,7 @@ import { Organisation } from '../../model/Organisation';
import { UserInputError } from 'apollo-server-express'; import { UserInputError } from 'apollo-server-express';
import { CargoBike } from '../../model/CargoBike'; import { CargoBike } from '../../model/CargoBike';
import { LendingStation } from '../../model/LendingStation'; import { LendingStation } from '../../model/LendingStation';
import { ActionLogger, deleteEntity, LockUtils } from './utils'; import { ActionLogger, deleteEntity, getAllEntity, LockUtils } from './utils';
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
export class ProviderAPI extends DataSource { export class ProviderAPI extends DataSource {
@ -42,13 +42,8 @@ export class ProviderAPI extends DataSource {
.getOne(); .getOne();
} }
async provider (offset: number, limit: number) { async provider (offset?: number, limit?: number) {
return await this.connection.getRepository(Provider) return await getAllEntity(this.connection, Provider, 'p', offset, limit);
.createQueryBuilder('provider')
.select()
.skip(offset)
.take(limit)
.getMany();
} }
async providerByOrganisationId (id: number) { async providerByOrganisationId (id: number) {
@ -75,13 +70,8 @@ export class ProviderAPI extends DataSource {
.loadOne(); .loadOne();
} }
async organisations (offset: number, limit: number) { async organisations (offset?: number, limit?: number) {
return await this.connection.getRepository(Organisation) return await getAllEntity(this.connection, Organisation, 'o', offset, limit);
.createQueryBuilder('o')
.select()
.skip(offset)
.limit(limit)
.getMany();
} }
async organisationById (id: number) { async organisationById (id: number) {

@ -64,6 +64,22 @@ export async function deleteEntity (connection: Connection, target: ObjectType<L
}); });
} }
export async function getAllEntity (connection: Connection, target: ObjectType<any>, alias: string, offset?: number, limit?: number) {
if (offset === null || limit === null) {
return await connection.getRepository(target)
.createQueryBuilder(alias)
.select()
.getMany();
} else {
return await connection.getRepository(target)
.createQueryBuilder(alias)
.select()
.skip(offset)
.take(limit)
.getMany();
}
}
export class LockUtils { export class LockUtils {
static async findById (connection: Connection, target: ObjectType<Lockable>, alias: string, id: number): Promise<Lockable> { static async findById (connection: Connection, target: ObjectType<Lockable>, alias: string, id: number): Promise<Lockable> {
return await connection.getRepository(target) return await connection.getRepository(target)

@ -21,7 +21,7 @@ import { DataSource } from 'apollo-datasource';
import { Connection, EntityManager, getConnection } from 'typeorm'; import { Connection, EntityManager, getConnection } from 'typeorm';
import { WorkshopType } from '../../model/WorkshopType'; import { WorkshopType } from '../../model/WorkshopType';
import { Workshop } from '../../model/Workshop'; import { Workshop } from '../../model/Workshop';
import { ActionLogger, deleteEntity, LockUtils } from './utils'; import { ActionLogger, deleteEntity, getAllEntity, LockUtils } from './utils';
import { UserInputError } from 'apollo-server-express'; import { UserInputError } from 'apollo-server-express';
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
import { Participant } from '../../model/Participant'; import { Participant } from '../../model/Participant';
@ -126,13 +126,8 @@ export class WorkshopAPI extends DataSource {
.getOne(); .getOne();
} }
async workshopTypes (offset: number, limit: number) { async workshopTypes (offset?: number, limit?: number) {
return await this.connection.getRepository(WorkshopType) return getAllEntity(this.connection, WorkshopType, 'wt', offset, limit);
.createQueryBuilder('w')
.select()
.skip(offset)
.take(limit)
.getMany();
} }
async workshopById (id: number) { async workshopById (id: number) {
@ -148,13 +143,8 @@ export class WorkshopAPI extends DataSource {
* @param offset * @param offset
* @param limit * @param limit
*/ */
async workshops (offset: number, limit: number) { async workshops (offset?: number, limit?: number) {
return await this.connection.getRepository(Workshop) return await getAllEntity(this.connection, Workshop, 'w', offset, limit);
.createQueryBuilder('w')
.select()
.skip(offset)
.take(limit)
.getMany();
} }
async trainer1ByWorkshopId (id: number) { async trainer1ByWorkshopId (id: number) {

@ -30,14 +30,14 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
cargoBikes: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { cargoBikes: (_: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) { if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.cargoBikeAPI.getCargoBikes(offset, limit); return dataSources.cargoBikeAPI.getCargoBikes(offset, limit);
} else { } else {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
bikeEvents: (_:any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { bikeEvents: (_:any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBikeEvent)) { if (req.permissions.includes(Permission.ReadBikeEvent)) {
return dataSources.cargoBikeAPI.bikeEvents(offset, limit); return dataSources.cargoBikeAPI.bikeEvents(offset, limit);
} else { } else {
@ -58,14 +58,14 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
bikeEventTypes: (_:any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { bikeEventTypes: (_:any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBikeEvent)) { if (req.permissions.includes(Permission.ReadBikeEvent)) {
return dataSources.cargoBikeAPI.bikeEventTypes(offset, limit); return dataSources.cargoBikeAPI.bikeEventTypes(offset, limit);
} else { } else {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
equipment: (_:any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { equipment: (_:any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadEquipment)) { if (req.permissions.includes(Permission.ReadEquipment)) {
return dataSources.cargoBikeAPI.getEquipment(offset, limit); return dataSources.cargoBikeAPI.getEquipment(offset, limit);
} else { } else {
@ -79,7 +79,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
equipmentTypes: (_:any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { equipmentTypes: (_:any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadEquipment)) { if (req.permissions.includes(Permission.ReadEquipment)) {
return dataSources.cargoBikeAPI.equipmentTypes(offset, limit); return dataSources.cargoBikeAPI.equipmentTypes(offset, limit);
} else { } else {
@ -102,23 +102,23 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
engagement (parent: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) { engagement (parent: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) {
if (req.permissions.includes(Permission.ReadEngagement)) { if (req.permissions.includes(Permission.ReadEngagement)) {
return dataSources.participantAPI.engagementByCargoBikeId(offset, limit, parent.id); return dataSources.participantAPI.engagementByCargoBikeId(parent.id, offset, limit);
} else { } else {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
participants (parent: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) { // TODO should be done with engagements participants (parent: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) { // TODO should be done with engagements
if (req.permissions.includes(Permission.ReadParticipant)) { if (req.permissions.includes(Permission.ReadParticipant)) {
return dataSources.participantAPI.participantsByCargoBikeId(parent.id); return dataSources.participantAPI.participantsByCargoBikeId(parent.id);
} else { } else {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
equipment (parent: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) { equipment (parent: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) {
if (req.permissions.includes(Permission.ReadEquipment)) { if (req.permissions.includes(Permission.ReadEquipment)) {
return dataSources.cargoBikeAPI.equipmentByCargoBikeId(offset, limit, parent.id); return dataSources.cargoBikeAPI.equipmentByCargoBikeId(parent.id, offset, limit);
} else { } else {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
@ -130,7 +130,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
bikeEvents (parent: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) { bikeEvents (parent: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) {
if (req.permissions.includes(Permission.ReadBikeEvent)) { if (req.permissions.includes(Permission.ReadBikeEvent)) {
return dataSources.cargoBikeAPI.bikeEventsByCargoBikeId(parent.id, offset, limit); return dataSources.cargoBikeAPI.bikeEventsByCargoBikeId(parent.id, offset, limit);
} else { } else {
@ -173,6 +173,10 @@ export default {
isLockedByMe: (parent: any, __: any, { req }: { req: any }) => isLockedByMe(parent, { req }), isLockedByMe: (parent: any, __: any, { req }: { req: any }) => isLockedByMe(parent, { req }),
isLocked: (parent: any, __: any, { req }: { req: any }) => isLocked(parent, { req }) isLocked: (parent: any, __: any, { req }: { req: any }) => isLocked(parent, { req })
}, },
EquipmentType: {
isLockedByMe: (parent: any, __: any, { req }: { req: any }) => isLockedByMe(parent, { req }),
isLocked: (parent: any, __: any, { req }: { req: any }) => isLocked(parent, { req })
},
BikeEvent: { BikeEvent: {
cargoBike (parent: any, __: any, { dataSources, req }: { dataSources: any, req: any }) { cargoBike (parent: any, __: any, { dataSources, req }: { dataSources: any, req: any }) {
if (req.permissions.includes(Permission.ReadBike)) { if (req.permissions.includes(Permission.ReadBike)) {

@ -24,7 +24,7 @@ import { isLocked, isLockedByMe } from '../datasources/db/utils';
export default { export default {
Query: { Query: {
contactInformation: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { contactInformation: (_: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadPerson)) { if (req.permissions.includes(Permission.ReadPerson)) {
return dataSources.contactInformationAPI.contactInformation(offset, limit); return dataSources.contactInformationAPI.contactInformation(offset, limit);
} else { } else {
@ -45,7 +45,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
persons: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { persons: (_: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadPerson)) { if (req.permissions.includes(Permission.ReadPerson)) {
return dataSources.contactInformationAPI.persons(offset, limit); return dataSources.contactInformationAPI.persons(offset, limit);
} else { } else {

@ -31,7 +31,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
lendingStations: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { lendingStations: (_: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadLendingStation)) { if (req.permissions.includes(Permission.ReadLendingStation)) {
return dataSources.lendingStationAPI.lendingStations(offset, limit); return dataSources.lendingStationAPI.lendingStations(offset, limit);
} else { } else {
@ -45,7 +45,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
timeframes: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { timeFrames: (_: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadTimeFrame)) { if (req.permissions.includes(Permission.ReadTimeFrame)) {
return dataSources.lendingStationAPI.timeFrames(offset, limit); return dataSources.lendingStationAPI.timeFrames(offset, limit);
} else { } else {

@ -30,7 +30,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
participants: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { participants: (_: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadParticipant)) { if (req.permissions.includes(Permission.ReadParticipant)) {
return dataSources.participantAPI.getParticipants(offset, limit); return dataSources.participantAPI.getParticipants(offset, limit);
} else { } else {
@ -44,7 +44,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
engagements: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { engagements: (_: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadEngagement)) { if (req.permissions.includes(Permission.ReadEngagement)) {
return dataSources.participantAPI.engagements(offset, limit); return dataSources.participantAPI.engagements(offset, limit);
} else { } else {
@ -58,7 +58,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
engagementTypes: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { engagementTypes: (_: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadEngagement)) { if (req.permissions.includes(Permission.ReadEngagement)) {
return dataSources.participantAPI.engagementTypes(offset, limit); return dataSources.participantAPI.engagementTypes(offset, limit);
} else { } else {

@ -23,7 +23,7 @@ import { isLocked, isLockedByMe } from '../datasources/db/utils';
export default { export default {
Query: { Query: {
providers: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { providers: (_: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadProvider)) { if (req.permissions.includes(Permission.ReadProvider)) {
return dataSources.providerAPI.provider(offset, limit); return dataSources.providerAPI.provider(offset, limit);
} else { } else {
@ -37,7 +37,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
organisations: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { organisations: (_: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadOrganisation)) { if (req.permissions.includes(Permission.ReadOrganisation)) {
return dataSources.providerAPI.organisations(offset, limit); return dataSources.providerAPI.organisations(offset, limit);
} else { } else {

@ -31,7 +31,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
workshopTypes: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { workshopTypes: (_: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadWorkshop)) { if (req.permissions.includes(Permission.ReadWorkshop)) {
return dataSources.workshopAPI.workshopTypes(offset, limit); return dataSources.workshopAPI.workshopTypes(offset, limit);
} else { } else {
@ -45,7 +45,7 @@ export default {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
}, },
workshops: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => { workshops: (_: any, { offset, limit }: { offset?: number, limit?: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadWorkshop)) { if (req.permissions.includes(Permission.ReadWorkshop)) {
return dataSources.workshopAPI.workshops(offset, limit); return dataSources.workshopAPI.workshops(offset, limit);
} else { } else {

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save