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(); .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) { async responsibleByBikeEventId (id: number) {
return await this.connection.getRepository(BikeEvent) return await this.connection.getRepository(BikeEvent)
.createQueryBuilder('be') .createQueryBuilder('be')
@ -223,7 +240,7 @@ export class CargoBikeAPI extends DataSource {
return await LockUtils.unlockEntity(this.connection, BikeEvent, 'be', id, userId); return await LockUtils.unlockEntity(this.connection, BikeEvent, 'be', id, userId);
} }
async findEquipmentById (id: number) { async equipmentById (id: number) {
return await this.connection.getRepository(Equipment) return await this.connection.getRepository(Equipment)
.createQueryBuilder('equipment') .createQueryBuilder('equipment')
.select() .select()
@ -271,7 +288,7 @@ export class CargoBikeAPI extends DataSource {
.of(equipment.id) .of(equipment.id)
.set(equipment.cargoBikeId); .set(equipment.cargoBikeId);
} }
return this.findEquipmentById(inserts.identifiers[0].id); return this.equipmentById(inserts.identifiers[0].id);
} }
async cargoBikeByEquipmentId (id: number) { async cargoBikeByEquipmentId (id: number) {
@ -321,9 +338,9 @@ export class CargoBikeAPI extends DataSource {
.of(equipment.id) .of(equipment.id)
.set(cargoBikeId); .set(cargoBikeId);
!keepLock && LockUtils.unlockEntity(this.connection, Equipment, 'e', equipment.id, userId); !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) { async getEquipment (offset: number, limit: number) {
@ -355,8 +372,17 @@ export class CargoBikeAPI extends DataSource {
.getOne(); .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) { async equipmentTypeByCargoBikeId (id: number) {
return this.connection.getRepository(CargoBike) return await this.connection.getRepository(CargoBike)
.createQueryBuilder('cargobike') .createQueryBuilder('cargobike')
.relation(CargoBike, 'equipmentTypeIds') .relation(CargoBike, 'equipmentTypeIds')
.of(id) .of(id)

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

@ -69,6 +69,15 @@ export class ParticipantAPI extends DataSource {
.getMany(); .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) { async engagementById (id: number) {
return await this.connection.getRepository(Engagement) return await this.connection.getRepository(Engagement)
.createQueryBuilder('engagement') .createQueryBuilder('engagement')
@ -77,6 +86,23 @@ export class ParticipantAPI extends DataSource {
.getOne(); .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) { async engagementTypeByEngagementId (id: number) {
return await this.connection.getRepository(Engagement) return await this.connection.getRepository(Engagement)
.createQueryBuilder('engagement') .createQueryBuilder('engagement')

@ -53,6 +53,23 @@ export class ProviderAPI extends DataSource {
.loadOne(); .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) { async contactInformationByOrganisationId (id: number) {
return await this.connection.getRepository(Organisation) return await this.connection.getRepository(Organisation)
.createQueryBuilder('o') .createQueryBuilder('o')

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

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

@ -12,6 +12,20 @@ export default {
return new GraphQLError('Insufficient Permissions'); 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 }) => { 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);

@ -19,6 +19,13 @@ export default {
return new GraphQLError('Insufficient Permissions'); 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 }) => { timeframes: (_: 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.lendingStationAPI.timeFrames(offset, limit); return dataSources.lendingStationAPI.timeFrames(offset, limit);

@ -18,6 +18,34 @@ export default {
} else { } else {
return new GraphQLError('Insufficient Permissions'); 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: { Participant: {

@ -17,6 +17,20 @@ export default {
} else { } else {
return new GraphQLError('Insufficient Permissions'); 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: { Provider: {

@ -4,6 +4,13 @@ import { isLocked } from '../datasources/db/utils';
export default { export default {
Query: { 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 }) => { workshopTypes: (_: 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.workshopAPI.workshopTypes(offset, limit); return dataSources.workshopAPI.workshopTypes(offset, limit);
@ -11,6 +18,13 @@ export default {
return new GraphQLError('Insufficient Permissions'); 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 }) => { workshops: (_: 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.workshopAPI.workshops(offset, limit); return dataSources.workshopAPI.workshops(offset, limit);

@ -813,26 +813,39 @@ type Query {
cargoBikeById(id:ID!): CargoBike cargoBikeById(id:ID!): CargoBike
"returns cargoBikes ordered by name ascending, relations are not loaded, use cargoBikeById instead" "returns cargoBikes ordered by name ascending, relations are not loaded, use cargoBikeById instead"
cargoBikes(offset: Int!, limit: Int!): [CargoBike]! 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" "return null if id not found"
providerById(id:ID!): Provider 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" "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]! providers(offset: Int!, limit: Int!): [Provider]!
"participant by id" "participant by id"
participantById(id:ID!): Participant participantById(id:ID!): Participant
"p"
participants(offset: Int!, limit: Int!): [ Participant]! participants(offset: Int!, limit: Int!): [ Participant]!
workshopTypes(offset: Int!, limit: Int!): [WorkshopType] workshopTypeById(id: ID!): WorkshopType
workshops(offset: Int!, limit: Int!): [Workshop] workshopTypes(offset: Int!, limit: Int!): [WorkshopType]!
workshopById(id: ID!): Workshop
workshops(offset: Int!, limit: Int!): [Workshop]!
lendingStationById(id:ID!): LendingStation lendingStationById(id:ID!): LendingStation
lendingStations(offset: Int!, limit: Int!): [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]! timeframes(offset: Int!, limit: Int!): [TimeFrame]!
contactInformationById(id: ID!): ContactInformation
contactInformation(offset: Int!, limit: Int!): [ContactInformation]! contactInformation(offset: Int!, limit: Int!): [ContactInformation]!
personById(id: ID!): Person
persons(offset: Int!, limit: Int!): [Person] persons(offset: Int!, limit: Int!): [Person]
bikeEventTypes(offset: Int!, limit: Int!): [BikeEventType] bikeEventTypes(offset: Int!, limit: Int!): [BikeEventType]
"returns BikeEvent with CargoBike" bikeEventTypeByd(id: ID!): BikeEventType
bikeEvents(offset: Int!, limit: Int!): [BikeEvent]!
bikeEventById(id:ID!): BikeEvent! bikeEventById(id:ID!): BikeEvent!
} }
@ -879,7 +892,9 @@ type Mutation {
createBikeEvent(bikeEvent: BikeEventCreateInput!): BikeEvent! createBikeEvent(bikeEvent: BikeEventCreateInput!): BikeEvent!
lockBikeEventById(id: ID!): BikeEvent lockBikeEventById(id: ID!): BikeEvent
unlockBikeEventById(id: ID!): Boolean! unlockBikeEventById(id: ID!): Boolean!
"create participant" """
PARTICIPANTS
"""
createParticipant(participant: ParticipantCreateInput!): Participant! createParticipant(participant: ParticipantCreateInput!): Participant!
createWorkshopType(workshopType: WorkshopTypeCreateInput!): WorkshopType! createWorkshopType(workshopType: WorkshopTypeCreateInput!): WorkshopType!
createWorkshop(workshop: WorkshopCreateInput!): Workshop! createWorkshop(workshop: WorkshopCreateInput!): Workshop!

Loading…
Cancel
Save