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 }) {
if (cargoBike.id) {
// update bike with given id
@ -51,21 +56,30 @@ export class CargoBikeAPI extends DataSource {
await this.connection
.createQueryBuilder()
.update(CargoBike)
.set({ name: bike.name })
.set({ ...cargoBike })
.where('id = :id', { id: bike.id })
.execute();
return bike;
return await this.connection
.createQueryBuilder()
.select('cargoBike')
.from(CargoBike, 'cargoBike')
.where('cargoBike.id = :id', { id: bike.id })
.getOne();
} else {
return new GraphQLError('ID not in database');
}
} else {
// create new bike
await this.connection.manager.createQueryBuilder()
const inserts = await this.connection.manager
.createQueryBuilder()
.insert()
.into(CargoBike)
.values([cargoBike])
.returning('*')
.execute();
return cargoBike;
const newbike = inserts.generatedMaps[0];
newbike.id = inserts.identifiers[0].id;
return newbike;
}
}
}

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

@ -27,7 +27,7 @@ type CargoBike {
"""
Does not refere to an extra table in the database.
"""
dimensionsAndLoad: DimensionsAndLoad
dimensionsAndLoad: DimensionsAndLoad!
events: [BikeEvent]
equipment: [Equipment]
"Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2"
@ -327,23 +327,18 @@ type LendingStation {
loanPeriods: [LoanPeriod]!
}
"(dt. Ausleihzeiten)"
"""
(dt. Ausleihzeiten)
"""
type LoanTimes {
notes: String
mof: String
mot: String
tuf: String
tut: String
wef: String
wet: String
thf: String
tht: String
frf: String
frt: String
saf: String
sat: String
suf: String
sut: String
generalRemark: String
"notes for each day of the week, starting on Monday"
notes: [String]
"""
Loan times from and until for each day of the week.
Starting with Monday from, Monday to, Tuesday from, ..., Sunday to
"""
times: [String]
}
"(dt. Zeitscheibe)"

Loading…
Cancel
Save