finished all Queries

pull/14/head
leonnicolas 4 years ago
parent 595f66f3dc
commit 813f41ec8e
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -187,6 +187,23 @@ export class CargoBikeAPI extends DataSource {
.getMany();
}
async bikeEvents (offset: number, limit: number) {
return await this.connection.getRepository(BikeEvent)
.createQueryBuilder('be')
.select()
.skip(offset)
.take(limit)
.getMany();
}
async findBikeEventTypeById (id: number) {
return await this.connection.getRepository(BikeEventType)
.createQueryBuilder('bet')
.select()
.where('id = :id', { id: id })
.getOne();
}
async responsibleByBikeEventId (id: number) {
return await this.connection.getRepository(BikeEvent)
.createQueryBuilder('be')
@ -223,7 +240,7 @@ export class CargoBikeAPI extends DataSource {
return await LockUtils.unlockEntity(this.connection, BikeEvent, 'be', id, userId);
}
async findEquipmentById (id: number) {
async equipmentById (id: number) {
return await this.connection.getRepository(Equipment)
.createQueryBuilder('equipment')
.select()
@ -271,7 +288,7 @@ export class CargoBikeAPI extends DataSource {
.of(equipment.id)
.set(equipment.cargoBikeId);
}
return this.findEquipmentById(inserts.identifiers[0].id);
return this.equipmentById(inserts.identifiers[0].id);
}
async cargoBikeByEquipmentId (id: number) {
@ -321,9 +338,9 @@ export class CargoBikeAPI extends DataSource {
.of(equipment.id)
.set(cargoBikeId);
!keepLock && LockUtils.unlockEntity(this.connection, Equipment, 'e', equipment.id, userId);
return this.findEquipmentById(equipment.id);
return this.equipmentById(equipment.id);
}
return this.findEquipmentById(equipment.id);
return this.equipmentById(equipment.id);
}
async getEquipment (offset: number, limit: number) {
@ -355,8 +372,17 @@ export class CargoBikeAPI extends DataSource {
.getOne();
}
async eqiupmentTypes (offset: number, limit: number) {
return await this.connection.getRepository(EquipmentType)
.createQueryBuilder('et')
.select()
.skip(offset)
.take(limit)
.getMany();
}
async equipmentTypeByCargoBikeId (id: number) {
return this.connection.getRepository(CargoBike)
return await this.connection.getRepository(CargoBike)
.createQueryBuilder('cargobike')
.relation(CargoBike, 'equipmentTypeIds')
.of(id)

@ -1,7 +1,6 @@
import { DataSource } from 'apollo-datasource';
import { Connection, getConnection } from 'typeorm';
import { ContactInformation } from '../../model/ContactInformation';
import { LendingStation } from '../../model/LendingStation';
import { Person } from '../../model/Person';
export class ContactInformationAPI extends DataSource {
@ -33,21 +32,12 @@ export class ContactInformationAPI extends DataSource {
async contactInformationById (id: number) {
return await this.connection.getRepository(ContactInformation)
.createQueryBuilder('contactInformation')
.createQueryBuilder('ci')
.select()
.where('"contactInformation".id = :id', { id: id })
.where('id = :id', { id: id })
.getOne();
}
// TODO change to contactinformation
async contactPersonsByLendingStationId (id: number) {
return await this.connection
.createQueryBuilder()
.relation(LendingStation, 'contactPersons')
.of(id)
.loadMany();
}
async createPerson (person: any) {
const inserts = await this.connection.getRepository(Person)
.createQueryBuilder('person')
@ -59,18 +49,6 @@ export class ContactInformationAPI extends DataSource {
return inserts.generatedMaps[0];
}
/**
* Return person by ID
* @param id
*/
async personById (id: number) {
return await this.connection.getRepository(Person)
.createQueryBuilder('person')
.select()
.where('person.id = :id', { id: id })
.getOne();
}
async persons (offset: number, limit: number) {
return await this.connection.getRepository(Person)
.createQueryBuilder('person')
@ -80,6 +58,14 @@ export class ContactInformationAPI extends DataSource {
.execute();
}
async personById (id: number) {
return await this.connection.getRepository(Person)
.createQueryBuilder('p')
.select()
.where('id = :id', { id: id })
.getOne();
}
async personByContactInformationId (id: number) {
return await this.connection.getRepository(ContactInformation)
.createQueryBuilder('ci')

@ -69,6 +69,15 @@ export class ParticipantAPI extends DataSource {
.getMany();
}
async engagements (offset: number, limit: number) {
return await this.connection.getRepository(Engagement)
.createQueryBuilder('e')
.select()
.skip(offset)
.take(limit)
.getMany();
}
async engagementById (id: number) {
return await this.connection.getRepository(Engagement)
.createQueryBuilder('engagement')
@ -77,6 +86,23 @@ export class ParticipantAPI extends DataSource {
.getOne();
}
async engagementTypeById (id: number) {
return await this.connection.getRepository(EngagementType)
.createQueryBuilder('et')
.select()
.where('id = :id', { id: id })
.getOne();
}
async engagementTypes (offset: number, limit: number) {
return await this.connection.getRepository(EngagementType)
.createQueryBuilder('et')
.select()
.skip(offset)
.take(limit)
.getMany();
}
async engagementTypeByEngagementId (id: number) {
return await this.connection.getRepository(Engagement)
.createQueryBuilder('engagement')

@ -53,6 +53,23 @@ export class ProviderAPI extends DataSource {
.loadOne();
}
async organisations (offset: number, limit: number) {
return await this.connection.getRepository(Organisation)
.createQueryBuilder('o')
.select()
.skip(offset)
.limit(limit)
.getMany();
}
async organisationById (id: number) {
return await this.connection.getRepository(Organisation)
.createQueryBuilder('o')
.select()
.where('id = :id', { id: id })
.getOne();
}
async contactInformationByOrganisationId (id: number) {
return await this.connection.getRepository(Organisation)
.createQueryBuilder('o')

@ -31,6 +31,14 @@ export class WorkshopAPI extends DataSource {
return inserts.generatedMaps[0];
}
async workshopTypeById (id: number) {
return await this.connection.getRepository(WorkshopType)
.createQueryBuilder('wt')
.select()
.where('id = :id', { id: id })
.getOne();
}
async workshopTypes (offset: number, limit: number) {
return await this.connection.getRepository(WorkshopType)
.createQueryBuilder('w')
@ -40,6 +48,14 @@ export class WorkshopAPI extends DataSource {
.getMany();
}
async workshopById (id: number) {
return await this.connection.getRepository(Workshop)
.createQueryBuilder('w')
.select()
.where('id = :id', { id: id })
.getOne();
}
/**
* finds workshops with pagination
* @param offset

@ -18,6 +18,13 @@ export default {
return new GraphQLError('Insufficiant Permissions');
}
},
bikeEvents: (_:any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.cargoBikeAPI.bikeEvents(offset, limit);
} else {
return new GraphQLError('Insufficiant Permissions');
}
},
bikeEventById: (_:any, { id }: { id: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.cargoBikeAPI.findBikeEventById(id);
@ -25,6 +32,13 @@ export default {
return new GraphQLError('Insufficiant Permissions');
}
},
bikeEventTypeByd: (_:any, { id }: { id: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.cargoBikeAPI.findBikeEventTypeById(id);
} else {
return new GraphQLError('Insufficiant Permissions');
}
},
equipment: (_:any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.cargoBikeAPI.getEquipment(offset, limit);
@ -34,7 +48,21 @@ export default {
},
equipmentById: (_:any, { id }: { id: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.cargoBikeAPI.findEquipmentJoinBikeById(id);
return dataSources.cargoBikeAPI.equipmentById(id);
} else {
return new GraphQLError('Insufficiant Permissions');
}
},
equipmentTypes: (_:any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.cargoBikeAPI.equipmentTypes(offset, limit);
} else {
return new GraphQLError('Insufficiant Permissions');
}
},
equipmentTypeById: (_:any, { id }: { id: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.cargoBikeAPI.equipmentTypeById(id);
} else {
return new GraphQLError('Insufficiant Permissions');
}

@ -12,6 +12,20 @@ export default {
return new GraphQLError('Insufficient Permissions');
}
},
contactInformationById: (_: any, { id }: { id: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadPerson)) {
return dataSources.contactInformationAPI.contactInformationById(id);
} else {
return new GraphQLError('Insufficient Permissions');
}
},
personById: (_: any, { id }: { id: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadPerson)) {
return dataSources.contactInformationAPI.personById(id);
} else {
return new GraphQLError('Insufficient Permissions');
}
},
persons: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadPerson)) {
return dataSources.contactInformationAPI.persons(offset, limit);

@ -19,6 +19,13 @@ export default {
return new GraphQLError('Insufficient Permissions');
}
},
timeFrameById: (_: any, { id }: { id: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.lendingStationAPI.timeFrameById(id);
} else {
return new GraphQLError('Insufficient Permissions');
}
},
timeframes: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.lendingStationAPI.timeFrames(offset, limit);

@ -18,6 +18,34 @@ export default {
} else {
return new GraphQLError('Insufficient Permissions');
}
},
engagementById: (_: any, { id }: { id: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.participantAPI.engagementById(id);
} else {
return new GraphQLError('Insufficient Permissions');
}
},
engagements: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.participantAPI.engagements(offset, limit);
} else {
return new GraphQLError('Insufficient Permissions');
}
},
engagementTypeById: (_: any, { id }: { id: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.participantAPI.engagementTypeById(id);
} else {
return new GraphQLError('Insufficient Permissions');
}
},
engagementTypes: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.participantAPI.engagementTypes(offset, limit);
} else {
return new GraphQLError('Insufficient Permissions');
}
}
},
Participant: {

@ -17,6 +17,20 @@ export default {
} else {
return new GraphQLError('Insufficient Permissions');
}
},
organisations: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.providerAPI.organisations(offset, limit);
} else {
return new GraphQLError('Insufficient Permissions');
}
},
organisationById: (_: any, { id }: { id: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.providerAPI.organisationById(id);
} else {
return new GraphQLError('Insufficient Permissions');
}
}
},
Provider: {

@ -4,6 +4,13 @@ import { isLocked } from '../datasources/db/utils';
export default {
Query: {
workshopTypeById: (_: any, { id }: { id: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.workshopAPI.workshopTypeById(id);
} else {
return new GraphQLError('Insufficient Permissions');
}
},
workshopTypes: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.workshopAPI.workshopTypes(offset, limit);
@ -11,6 +18,13 @@ export default {
return new GraphQLError('Insufficient Permissions');
}
},
workshopById: (_: any, { id }: { id: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.workshopAPI.workshopById(id);
} else {
return new GraphQLError('Insufficient Permissions');
}
},
workshops: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.workshopAPI.workshops(offset, limit);

@ -813,26 +813,39 @@ type Query {
cargoBikeById(id:ID!): CargoBike
"returns cargoBikes ordered by name ascending, relations are not loaded, use cargoBikeById instead"
cargoBikes(offset: Int!, limit: Int!): [CargoBike]!
engagementById(id: ID!): Engagement
engagements(offset: Int!, limit: Int!): [Engagement]!
engagementTypeById(id: ID!): EngagementType
engagementTypes(offset: Int!, limit: Int!): [EngagementType]!
"equipment by id, will return null if id not found"
equipmentById(id: ID!): Equipment
equipment(offset: Int!, limit: Int!): [Equipment]!
equipmentTypeById(id: ID!): EquipmentType
equipmentTypes(offset: Int!, limit: Int!): [EquipmentType]!
"return null if id not found"
providerById(id:ID!): Provider
"unique equipment with pagination, contains relation to bike (with no further joins), so if you wanna know more about the bike, use cargoBikeById"
equipment(offset: Int!, limit: Int!): [Equipment]!
"equipment by id, will return null if id not found"
equipmentById(id: ID!): Equipment
providers(offset: Int!, limit: Int!): [Provider]!
"participant by id"
participantById(id:ID!): Participant
"p"
participants(offset: Int!, limit: Int!): [ Participant]!
workshopTypes(offset: Int!, limit: Int!): [WorkshopType]
workshops(offset: Int!, limit: Int!): [Workshop]
workshopTypeById(id: ID!): WorkshopType
workshopTypes(offset: Int!, limit: Int!): [WorkshopType]!
workshopById(id: ID!): Workshop
workshops(offset: Int!, limit: Int!): [Workshop]!
lendingStationById(id:ID!): LendingStation
lendingStations(offset: Int!, limit: Int!): [LendingStation]!
organisationById(id: ID!): Organisation
organisations(offset: Int!, limit: Int!): [Organisation]!
timeFrameById(id: ID!): TimeFrame
timeframes(offset: Int!, limit: Int!): [TimeFrame]!
contactInformationById(id: ID!): ContactInformation
contactInformation(offset: Int!, limit: Int!): [ContactInformation]!
personById(id: ID!): Person
persons(offset: Int!, limit: Int!): [Person]
bikeEventTypes(offset: Int!, limit: Int!): [BikeEventType]
"returns BikeEvent with CargoBike"
bikeEventTypeByd(id: ID!): BikeEventType
bikeEvents(offset: Int!, limit: Int!): [BikeEvent]!
bikeEventById(id:ID!): BikeEvent!
}
@ -879,7 +892,9 @@ type Mutation {
createBikeEvent(bikeEvent: BikeEventCreateInput!): BikeEvent!
lockBikeEventById(id: ID!): BikeEvent
unlockBikeEventById(id: ID!): Boolean!
"create participant"
"""
PARTICIPANTS
"""
createParticipant(participant: ParticipantCreateInput!): Participant!
createWorkshopType(workshopType: WorkshopTypeCreateInput!): WorkshopType!
createWorkshop(workshop: WorkshopCreateInput!): Workshop!

Loading…
Cancel
Save