src/datasources/db/cargoBikeAPI: added updateCargoBike

pull/8/head
leonnicolas 4 years ago
parent b923aa4c88
commit 91e0c8f9e9
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -38,6 +38,11 @@ export class CargoBikeAPI extends DataSource {
}; };
} }
/**
* Creates or Updates CargoBike
* Will create bike, if no id given, else it will update bike with given id.
* @param param0 cargoBike to be updated or created
*/
async updateCargoBike ({ cargoBike }:{ cargoBike: any }) { async updateCargoBike ({ cargoBike }:{ cargoBike: any }) {
if (cargoBike.id) { if (cargoBike.id) {
// update bike with given id // update bike with given id
@ -51,21 +56,30 @@ export class CargoBikeAPI extends DataSource {
await this.connection await this.connection
.createQueryBuilder() .createQueryBuilder()
.update(CargoBike) .update(CargoBike)
.set({ name: bike.name }) .set({ ...cargoBike })
.where('id = :id', { id: bike.id }) .where('id = :id', { id: bike.id })
.execute(); .execute();
return bike; return await this.connection
.createQueryBuilder()
.select('cargoBike')
.from(CargoBike, 'cargoBike')
.where('cargoBike.id = :id', { id: bike.id })
.getOne();
} else { } else {
return new GraphQLError('ID not in database'); return new GraphQLError('ID not in database');
} }
} else { } else {
// create new bike // create new bike
await this.connection.manager.createQueryBuilder() const inserts = await this.connection.manager
.createQueryBuilder()
.insert() .insert()
.into(CargoBike) .into(CargoBike)
.values([cargoBike]) .values([cargoBike])
.returning('*')
.execute(); .execute();
return cargoBike; const newbike = inserts.generatedMaps[0];
newbike.id = inserts.identifiers[0].id;
return newbike;
} }
} }
} }

@ -7,6 +7,9 @@ export class InsuranceData {
@Column() @Column()
benefactor: string; benefactor: string;
@Column()
billing: string;
@Column() @Column()
noPnP: string; noPnP: string;

@ -27,7 +27,7 @@ type CargoBike {
""" """
Does not refere to an extra table in the database. Does not refere to an extra table in the database.
""" """
dimensionsAndLoad: DimensionsAndLoad dimensionsAndLoad: DimensionsAndLoad!
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"
@ -327,23 +327,18 @@ type LendingStation {
loanPeriods: [LoanPeriod]! loanPeriods: [LoanPeriod]!
} }
"(dt. Ausleihzeiten)" """
(dt. Ausleihzeiten)
"""
type LoanTimes { type LoanTimes {
notes: String generalRemark: String
mof: String "notes for each day of the week, starting on Monday"
mot: String notes: [String]
tuf: String """
tut: String Loan times from and until for each day of the week.
wef: String Starting with Monday from, Monday to, Tuesday from, ..., Sunday to
wet: String """
thf: String times: [String]
tht: String
frf: String
frt: String
saf: String
sat: String
suf: String
sut: String
} }
"(dt. Zeitscheibe)" "(dt. Zeitscheibe)"

Loading…
Cancel
Save