src/resolvers/*: startet first resolver

pull/8/head
leonnicolas 4 years ago
parent 2499cc526f
commit 0bc8934560
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -1,4 +1,4 @@
FROM node FROM node AS builder
WORKDIR / WORKDIR /
COPY ./src /src COPY ./src /src
@ -6,7 +6,12 @@ COPY ./package*.json ./
RUN npm install RUN npm install
RUN npm install -g gulp RUN npm install -g gulp
RUN npm install gulp RUN npm install gulp
RUN gulp RUN gulp
FROM node
COPY --from=builder /dist .
COPY --from=builder ./package*.json ./
RUN npm install --production
EXPOSE 4000 EXPOSE 4000
CMD ["npm", "start"] CMD ["npm", "start"]

@ -30,10 +30,55 @@ export class CargoBikeAPI extends DataSource {
return { return {
success: true, success: true,
message: 'bla', message: 'bla',
bike: { cargoBike: {
id, id,
name name
} }
}; };
} }
async updateCargoBike ({ cargoBike }:{ cargoBike: any }) {
if (cargoBike.id) {
// update bike with given id
const bike = await this.connection.manager.createQueryBuilder()
.select('cargoBike')
.from(CargoBike, 'cargoBike')
.where('cargoBike.id = :id', { id: cargoBike.id })
.getOne();
if (bike) {
// bike exists
await this.connection
.createQueryBuilder()
.update(CargoBike)
.set({ name: bike.name })
.where('id = :id', { id: bike.id })
.execute();
return {
success: true
};
} else {
return {
success: false,
message: 'no bike with given id ' + cargoBike.id + ' found.'
};
}
} else {
// create new bike
await this.connection.manager.createQueryBuilder()
.insert()
.into(CargoBike)
.values([{
modelName: cargoBike.modelName,
numberOfWheels: cargoBike.numberOfWheels,
forCargo: cargoBike.forCargo,
forChildren: cargoBike.forChildren
}
])
.execute();
return {
success: true,
message: 'new entry'
};
}
}
} }

@ -1,14 +1,16 @@
import { Column } from 'typeorm'; import { Column } from 'typeorm';
export abstract class Bike { export abstract class Bike {
@Column() @Column({
nullable: true
})
description: string; description: string;
@Column() @Column()
modelName: string; modelName: string;
@Column() @Column()
numerOfWheels: number; numberOfWheels: number;
@Column() @Column()
forCargo: boolean; forCargo: boolean;
@ -60,12 +62,18 @@ export abstract class Bike {
@Column() @Column()
bikeLength: number; bikeLength: number;
@Column() @Column({
nullable: true
})
bikeWidth: number; bikeWidth: number;
@Column() @Column({
nullable: true
})
bikeHeight: number; bikeHeight: number;
@Column() @Column({
nullable: true
})
bikeWeight: number; bikeWeight: number;
} }

@ -11,14 +11,14 @@ import { Taxes } from './Taxes';
import { Equipment } from './Equipment'; import { Equipment } from './Equipment';
export enum Group { export enum Group {
KL, KL = 'KL',
LI, LI = 'LI',
SP, SP = 'SP',
FK, FK = 'FK',
MH, MH = 'MH',
SZ, SZ = 'SZ',
TS, TS = 'TS',
TK TK = 'TK'
} }
export enum StickerBikeNameState { export enum StickerBikeNameState {
@ -35,24 +35,25 @@ export class CargoBike extends Bike {
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
id: number; id: number;
@Column() @Column({
type: 'enum',
enum: Group
})
group: Group; group: Group;
@Column() @Column()
name: string; name: string;
@Column()
serialNo: string;
@OneToMany(type => Equipment, equipment => equipment.cargoBike, { @OneToMany(type => Equipment, equipment => equipment.cargoBike, {
nullable: true nullable: true
}) })
equipment: Equipment[]; equipment: Equipment[];
@Column({ @Column({
type: 'simple-array',
nullable: true nullable: true
}) })
otherEquipment: string; otherEquipment: string[];
@OneToMany(type => ChainSwap, chainSwap => chainSwap.cargoBike, { @OneToMany(type => ChainSwap, chainSwap => chainSwap.cargoBike, {
nullable: true nullable: true
@ -63,16 +64,24 @@ export class CargoBike extends Bike {
@Column() @Column()
frameNumber: string; frameNumber: string;
@Column() @Column({
nullable: true
})
keyNoFrameLock: string; keyNoFrameLock: string;
@Column() @Column({
nullable: true
})
keyNoAXAChain: string; keyNoAXAChain: string;
@Column() @Column({
nullable: true
})
policeCodeing: string; policeCodeing: string;
@Column() @Column({
nullable: true
})
adfsCoding: string; adfsCoding: string;
@Column({ @Column({
@ -89,7 +98,9 @@ export class CargoBike extends Bike {
}) })
provider: Provider; provider: Provider;
@ManyToOne(type => Participant, participant => participant.cargoBikes) @ManyToOne(type => Participant, participant => participant.cargoBikes, {
nullable: true
})
coordinator: Participant; coordinator: Participant;
@Column(type => InsuranceData) @Column(type => InsuranceData)

@ -3,7 +3,7 @@ import { GraphQLError } from 'graphql';
export default { export default {
Query: { Query: {
CargobikeById: (_: any, { id }:{id: any}, { dataSources, req }:{dataSources: any, req: any }) => { cargobikeById: (_: any, { id }:{id: any}, { dataSources, req }:{dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) { if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.cargoBikeAPI.findCargoBikeById({ id }); return dataSources.cargoBikeAPI.findCargoBikeById({ id });
} else { } else {
@ -18,6 +18,13 @@ export default {
} else { } else {
throw new GraphQLError('Insufficient Permissions'); throw new GraphQLError('Insufficient Permissions');
} }
},
cargoBike: (_: any, { cargoBike }: { cargoBike: any }, { dataSources, req }:{dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.WriteBike)) {
return dataSources.cargoBikeAPI.updateCargoBike({ cargoBike });
} else {
throw new GraphQLError('Insufficient Permissions');
}
} }
} }
}; };

@ -15,7 +15,6 @@ type CargoBike {
forCargo: Boolean forCargo: Boolean
forChildren: Boolean forChildren: Boolean
numberOfChildren: Int numberOfChildren: Int
serialNo: String
""" """
Safety is a custom type, that stores information about security features. Safety is a custom type, that stores information about security features.
TODO: Should this be calles Security? TODO: Should this be calles Security?
@ -32,7 +31,7 @@ type CargoBike {
events: [BikeEvent] events: [BikeEvent]
equipment: [Equipment] equipment: [Equipment]
"Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2" "Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2"
otherEquipment: String otherEquipment: [String]
chainSwaps: [ChainSwap] chainSwaps: [ChainSwap]
"Sticker State" "Sticker State"
stickerBikeNameState: StickerBikeNameState stickerBikeNameState: StickerBikeNameState
@ -181,18 +180,32 @@ enum BikeEventType {
WARTUNG WARTUNG
} }
"How are the dimensions and how much weight can handle a bike." "How are the dimensions and how much weight can handle a bike. This data is merged in the CargoBike table and the BikeModel table."
type DimensionsAndLoad { type DimensionsAndLoad {
id: ID! hasCoverBox: Boolean!
hasCoverBox: Boolean lockable: Boolean!
lockable: Boolean boxLenght: Float!
boxLenght: Float boxWidth: Float!
boxWidth: Float boxHeight: Float!
boxHeight: Float maxWeightBox: Float!
maxWeightBox: Float maxWeightLuggageRack: Float!
maxWeightLuggageRack: Float maxWeightTotal: Float!
maxWeightTotal: Float bikeLength: Float!
bikeLength: Float bikeWidth: Float
bikeHeight: Float
bikeWeight: Float
}
input DimensionsAndLoadInput {
hasCoverBox: Boolean!
lockable: Boolean!
boxLenght: Float!
boxWidth: Float!
boxHeight: Float!
maxWeightBox: Float!
maxWeightLuggageRack: Float!
maxWeightTotal: Float!
bikeLength: Float!
bikeWidth: Float bikeWidth: Float
bikeHeight: Float bikeHeight: Float
bikeWeight: Float bikeWeight: Float
@ -210,13 +223,20 @@ type TechnicalEquipment {
specialFeatures: String specialFeatures: String
} }
input TechnicalEquipmentInput {
bicycleShift: String
isEBike: Boolean
hasLightingSystem: Boolean
specialFeatures: String
}
""" """
The Security Info about the bike. The Security Info about the bike.
his should be 1-1 Relation with the CargoBike. his should be 1-1 Relation with the CargoBike.
So no id needed for mutation. One Mutation for the CargoBike will be enough. So no id needed for mutation. One Mutation for the CargoBike will be enough.
""" """
type Security { type Security {
frameNumber: String frameNumber: String!
keyNumberFrameLock: String keyNumberFrameLock: String
keyNumberAXAChain: String keyNumberAXAChain: String
policeCoding: String policeCoding: String
@ -319,62 +339,70 @@ type Address {
} }
type Query { type Query {
CargobikeById(id:ID!): CargoBike cargobikeById(id:ID!): CargoBike
Cargobikes(token:String!): [CargoBike]! cargobikes: [CargoBike]!
CargobikesByProvider(token:String!,providerId:ID!): [CargoBike]! cargobikesByProvider(providerId:ID!): [CargoBike]!
ProviderById(token:String!,id:ID!): Provider providerById(id:ID!): Provider
Providers(token:String!): [Provider]! providers: [Provider]!
ParticipantById(token:String!,id:ID!): Participant participantById(id:ID!): Participant
Participants(token:String!): [ Participant]! participants: [ Participant]!
lendingStationById(token:String!, id:ID!): LendingStation lendingStationById(id:ID!): LendingStation
lendingStations(token:String!): [LendingStation]! lendingStations: [LendingStation]!
contactInformation(token:String!): [ContactInformation]! contactInformation: [ContactInformation]!
} }
type UpdateBikeResponse { type UpdateBikeResponse {
success: Boolean success: Boolean!
message: String message: String
bike: CargoBike cargoBike: CargoBike
} }
input CargoBikeInput { input CargoBikeInput {
"if null, then new bike will be created, else old bike will be updated" "if null, then new bike will be created, else old bike will be updated."
id: ID id: ID
"see column A in info tabelle" "see column A in info tabelle"
group: Group group: Group!
name: String name: String!
modelName: String modelName: String!
numberOfWheels: Int numberOfWheels: Int!
forCargo: Boolean forCargo: Boolean!
forChildren: Boolean forChildren: Boolean!
numberOfChildren: Int numberOfChildren: Int!
serialno: String
""" """
Safety is a custom type, that stores information about security features. Safety is a custom type, that stores information about security features.
TODO: Should this be calles Security? TODO: Should this be calles Security?
""" """
security: String security: SecurityInput
""" """
Does not refere to an extra table in the database. Does not refere to an extra table in the database.
""" """
technicalEquipment: String technicalEquipment: TechnicalEquipmentInput
""" """
Does not refere to an extra table in the database. Does not refere to an extra table in the database.
""" """
dimensionsAndLoad: String dimensionsAndLoad: DimensionsAndLoadInput
"Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2" "Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2"
otherEquipment: String otherEquipment: [String]
"Sticker State" "Sticker State"
stickerBikeNameState: String stickerBikeNameState: StickerBikeNameState
note: String note: String
provider: String provider: String
insuranceData: String insuranceData: String
} }
input SecurityInput {
frameNumber: String!
keyNumberFrameLock: String
keyNumberAXAChain: String
policeCoding: String
adfcCoding: String
}
type Mutation { type Mutation {
"for testing" "for testing"
addBike(id: ID!, name: String): UpdateBikeResponse! addBike(id: ID!, name: String): UpdateBikeResponse!
"if id: null, then new bike will be created, else old bike will be updated" "if id: null, then new bike will be created, else old bike will be updated"
cargoBike(cargoBike: CargoBikeInput): UpdateBikeResponse! cargoBike(cargoBike: CargoBikeInput!): UpdateBikeResponse!
} }
`; `;

Loading…
Cancel
Save