Merge pull request #35 from fLotte-meets-HWR-DB/dev

Dev
main
leonnicolas 4 years ago committed by GitHub
commit 1dd4a703ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -41,7 +41,7 @@ The following environment variables can be used to configure the server:
```bash ```bash
RPC_HOST=host:port RPC_HOST=host:port
NODE_ENV=develop/production NODE_ENV=develop/production
POSTGRES_CONNECTION_URL=postgres://username:password@host:port/database_name DATABASE_URL=postgres://username:password@host:port/database_name
``` ```
- __RPC_HOST__ is used for the connection with the [flotte-user-management server](https://github.com/fLotte-meets-HWR-DB/flotte-user-management). - __RPC_HOST__ is used for the connection with the [flotte-user-management server](https://github.com/fLotte-meets-HWR-DB/flotte-user-management).
- __NODE_ENV__ will not check authentication if set to development - __NODE_ENV__ will not check authentication if set to development

@ -137,6 +137,8 @@ export async function getApp (connOptions: ConnectionOptions) {
await cargoBikeAPI.populateCopyConfig(); await cargoBikeAPI.populateCopyConfig();
} catch (err) { } catch (err) {
console.error(err); console.error(err);
// exit so docker can restart the container and reattempt
process.exit(1);
} }
const server = new ApolloServer({ const server = new ApolloServer({

@ -237,12 +237,13 @@ export class CargoBikeAPI extends DataSource {
} }
async createBikeEvent ({ bikeEvent }: { bikeEvent: any }) { async createBikeEvent ({ bikeEvent }: { bikeEvent: any }) {
return (await this.connection.getRepository(BikeEvent) const inserts = await this.connection.getRepository(BikeEvent)
.createQueryBuilder('be') .createQueryBuilder('be')
.insert() .insert()
.values([bikeEvent]) .values([bikeEvent])
.returning('*') .returning('*')
.execute()).generatedMaps[0]; .execute();
return await this.bikeEventById(inserts.identifiers[0].id);
} }
async updateBikeEvent (bikeEvent: any, userId: number) { async updateBikeEvent (bikeEvent: any, userId: number) {
@ -310,7 +311,7 @@ export class CargoBikeAPI extends DataSource {
return (await this.connection.getRepository(BikeEventType) return (await this.connection.getRepository(BikeEventType)
.createQueryBuilder('bet') .createQueryBuilder('bet')
.insert() .insert()
.values([{ name: bikeEventType }]) .values([bikeEventType])
.returning('*') .returning('*')
.execute())?.generatedMaps[0]; .execute())?.generatedMaps[0];
} }
@ -564,6 +565,7 @@ export class CargoBikeAPI extends DataSource {
delete cargoBike[value.key]; delete cargoBike[value.key];
} }
}); });
cargoBike.id = -1;
return cargoBike; return cargoBike;
} }

@ -25,7 +25,6 @@ import { Participant } from '../../model/Participant';
import { EngagementType } from '../../model/EngagementType'; import { EngagementType } from '../../model/EngagementType';
import { ActionLogger, DBUtils, genDateRange, LockUtils } from './utils'; import { ActionLogger, DBUtils, genDateRange, LockUtils } from './utils';
import { UserInputError } from 'apollo-server-express'; import { UserInputError } from 'apollo-server-express';
import { GraphQLError } from 'graphql';
import { ResourceLockedError } from '../../errors/ResourceLockedError'; import { ResourceLockedError } from '../../errors/ResourceLockedError';
export class ParticipantAPI extends DataSource { export class ParticipantAPI extends DataSource {
@ -230,7 +229,7 @@ export class ParticipantAPI extends DataSource {
.createQueryBuilder('w') .createQueryBuilder('w')
.relation(Participant, 'workshopIds') .relation(Participant, 'workshopIds')
.of(participant.id) .of(participant.id)
.add(workshops); .addAndRemove(workshops, await this.workshopsByParticipantId(participant.id));
}); });
!keepLock && await this.unlockParticipant(participant.id, userId); !keepLock && await this.unlockParticipant(participant.id, userId);
return await this.participantById(participant.id); return await this.participantById(participant.id);

@ -55,6 +55,8 @@ export class WorkshopAPI extends DataSource {
async updateWorkshop (workshop: any, userId: number) { async updateWorkshop (workshop: any, userId: number) {
const keepLock = workshop.keepLock; const keepLock = workshop.keepLock;
delete workshop.keepLock; delete workshop.keepLock;
const workshopTypeId = workshop.workshopTypeId;
delete workshop.workshopTypeId;
await this.connection.transaction(async (entityManger: EntityManager) => { await this.connection.transaction(async (entityManger: EntityManager) => {
if (await LockUtils.isLocked(entityManger, Workshop, 'w', workshop.id, userId)) { if (await LockUtils.isLocked(entityManger, Workshop, 'w', workshop.id, userId)) {
throw new ResourceLockedError('Workshop', 'Attempting to update locked resource'); throw new ResourceLockedError('Workshop', 'Attempting to update locked resource');
@ -71,6 +73,11 @@ export class WorkshopAPI extends DataSource {
throw new NotFoundError('Workshop', 'id', workshop.id); throw new NotFoundError('Workshop', 'id', workshop.id);
} }
}); });
workshopTypeId && await entityManger.getRepository(Workshop)
.createQueryBuilder('w')
.relation(Workshop, 'workshopTypeId')
.of(workshop.id)
.set(workshopTypeId);
}); });
!keepLock && await this.unlockWorkshop(workshop.id, userId); !keepLock && await this.unlockWorkshop(workshop.id, userId);
return await this.workshopById(workshop.id); return await this.workshopById(workshop.id);
@ -134,6 +141,14 @@ export class WorkshopAPI extends DataSource {
.getOne(); .getOne();
} }
async workshopTypeByWorkshopId (id: number) {
return await this.connection.getRepository(Workshop)
.createQueryBuilder('w')
.relation(Workshop, 'workshopTypeId')
.of(id)
.loadOne();
}
async workshopTypes (offset?: number, limit?: number) { async workshopTypes (offset?: number, limit?: number) {
return DBUtils.getAllEntity(this.connection, WorkshopType, 'wt', offset, limit); return DBUtils.getAllEntity(this.connection, WorkshopType, 'wt', offset, limit);
} }

@ -23,6 +23,10 @@ import { getApp, getConnectionOptions, userAPI } from './app';
app.listen(4000, async () => { app.listen(4000, async () => {
await userAPI.createDefinedPermissions().catch( await userAPI.createDefinedPermissions().catch(
err => console.log(err)); err => {
console.log(err);
// exit so docker can restart the container and reattempt
process.exit(1);
});
}); });
})(); })();

@ -40,6 +40,12 @@ export class LoanPeriod {
}) })
generalRemark: string; generalRemark: string;
@Column({
nullable: true,
type: 'text'
})
holidays: string;
/** /**
* validity for loanPeriods * validity for loanPeriods
*/ */
@ -120,6 +126,11 @@ export class LendingStation implements Lockable {
}) })
organisationId: number; organisationId: number;
@Column({
nullable: true
})
remark: string;
@Column({ @Column({
nullable: true, nullable: true,
type: 'timestamp' type: 'timestamp'

@ -60,7 +60,7 @@ export class Workshop implements Lockable {
@JoinColumn({ @JoinColumn({
name: 'trainer2Id' name: 'trainer2Id'
}) })
trainer2: Participant; trainer2Id: number;
@Column({ @Column({
nullable: true, nullable: true,

@ -220,6 +220,9 @@ export default {
throw new PermissionError(); throw new PermissionError();
} }
}, },
documents: (parent: any) => {
return (parent.documents) ? parent.documents : [];
},
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 })
}, },
@ -227,6 +230,11 @@ 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 })
}, },
InsuranceData: {
projectAllowance: (parent: any): any => {
return (parent.projectAllowance as string)?.replace(/€\$/, '');
}
},
Mutation: { Mutation: {
createCargoBike: (_: any, { cargoBike }: { cargoBike: any }, { dataSources, req }: { dataSources: any, req: any }) => { createCargoBike: (_: any, { cargoBike }: { cargoBike: any }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.WriteBike)) { if (req.permissions.includes(Permission.WriteBike)) {
@ -368,9 +376,9 @@ export default {
throw new PermissionError(); throw new PermissionError();
} }
}, },
createBikeEventType: (_: any, { name }: { name: any }, { dataSources, req }: { dataSources: any, req: any }) => { createBikeEventType: (_: any, { bikeEventType }: { bikeEventType: any }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.WriteEventType)) { if (req.permissions.includes(Permission.WriteEventType)) {
return dataSources.cargoBikeAPI.createBikeEventType(name); return dataSources.cargoBikeAPI.createBikeEventType(bikeEventType);
} else { } else {
throw new PermissionError(); throw new PermissionError();
} }

@ -75,6 +75,13 @@ export default {
throw new PermissionError(); throw new PermissionError();
} }
}, },
workshopType (parent: any, _: any, { dataSources, req }: { dataSources: any; req: any }) {
if (req.permissions.includes(Permission.ReadWorkshop)) {
return dataSources.workshopAPI.workshopTypeByWorkshopId(parent.id);
} else {
throw new PermissionError();
}
},
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 })
}, },

@ -723,6 +723,10 @@ export default gql`
keepLock: Boolean keepLock: Boolean
} }
input BikeEventTypeCreateInput {
name: String!
}
"(dt. Anbieter) bezieht sich auf die Beziehung einer Person oder Organisation zum Lastenrad" "(dt. Anbieter) bezieht sich auf die Beziehung einer Person oder Organisation zum Lastenrad"
type Provider { type Provider {
id: ID! id: ID!
@ -872,6 +876,7 @@ export default gql`
"Total amount of cargoBikes currently assigned to the lending station" "Total amount of cargoBikes currently assigned to the lending station"
numCargoBikes: Int! numCargoBikes: Int!
organisation: Organisation organisation: Organisation
remark: String
isLocked: Boolean! isLocked: Boolean!
isLockedByMe: Boolean! isLockedByMe: Boolean!
"null if not locked by other user" "null if not locked by other user"
@ -889,6 +894,7 @@ export default gql`
address: AddressCreateInput! address: AddressCreateInput!
loanPeriod: LoanPeriodInput loanPeriod: LoanPeriodInput
organisationId: ID organisationId: ID
remark: String
} }
""" """
@ -902,6 +908,7 @@ export default gql`
address: AddressUpdateInput address: AddressUpdateInput
loanPeriod: LoanPeriodInput loanPeriod: LoanPeriodInput
organisationId: ID organisationId: ID
remark: String
keepLock: Boolean keepLock: Boolean
} }
@ -910,6 +917,7 @@ export default gql`
""" """
type LoanPeriod { type LoanPeriod {
generalRemark: String generalRemark: String
holidays: String
mo: String mo: String
tu: String tu: String
we: String we: String
@ -924,6 +932,7 @@ export default gql`
""" """
input LoanPeriodInput { input LoanPeriodInput {
generalRemark: String generalRemark: String
holidays: String
mo: String mo: String
tu: String tu: String
we: String we: String
@ -983,18 +992,21 @@ export default gql`
street: String! street: String!
number: String! number: String!
zip: String! zip: String!
city: String
} }
input AddressCreateInput { input AddressCreateInput {
street: String! street: String!
number: String! number: String!
zip: String! zip: String!
city: String
} }
input AddressUpdateInput { input AddressUpdateInput {
street: String street: String
number: String number: String
zip: String zip: String
city: String
} }
type ActionLog { type ActionLog {
@ -1123,7 +1135,7 @@ export default gql`
""" """
BIKEEVENT BIKEEVENT
""" """
createBikeEventType(name: String!): BikeEventType! createBikeEventType(bikeEventType: BikeEventTypeCreateInput!): BikeEventType!
lockBikeEventType(id: ID!): BikeEventType! lockBikeEventType(id: ID!): BikeEventType!
unlockBikeEventType(id:ID!): BikeEventType! unlockBikeEventType(id:ID!): BikeEventType!
updateBikeEventType(bikeEventType: BikeEventTypeUpdateInput!): BikeEventType! updateBikeEventType(bikeEventType: BikeEventTypeUpdateInput!): BikeEventType!

Loading…
Cancel
Save