Skip to content
Permalink
Browse files
Store customised vehicles in the database
  • Loading branch information
RussellLVP committed Jul 14, 2020
1 parent b6f290c commit 7576b45f06e6d9cb870cd7c8092c1b4a912e8c25
Showing 1 changed file with 19 additions and 5 deletions.
@@ -155,16 +155,21 @@ const CREATE_HOUSE_VISITOR_LOG = `
const CREATE_VEHICLE_QUERY = `
INSERT INTO
houses_vehicles
(house_parking_lot_id, house_id, model_id, vehicle_created)
(house_parking_lot_id, house_id, model_id, primary_color, secondary_color, paintjob,
components, vehicle_created)
VALUES
(?, ?, ?, NOW())`;
(?, ?, ?, ?, ?, ?, ?, NOW())`;

// Query for updating a vehicle in the database.
const UPDATE_VEHICLE_QUERY = `
UPDATE
houses_vehicles
SET
houses_vehicles.model_id = ?
houses_vehicles.model_id = ?,
houses_vehicles.primary_color = ?,
houses_vehicles.secondary_color = ?,
houses_vehicles.paintjob = ?,
houses_vehicles.components = ?
WHERE
houses_vehicles.house_vehicle_id = ?`;

@@ -499,8 +504,12 @@ class HouseDatabase {
// Creates a vehicle with |vehicleInfo| in the |parkingLot| associated with the house at
// |location|. The |vehicleInfo| must be an object having {modelId}.
async createVehicle(location, parkingLot, vehicleInfo) {
const components = vehicleInfo.components.length ? vehicleInfo.components.join(',')
: [];

const data = await server.database.query(
CREATE_VEHICLE_QUERY, parkingLot.id, location.settings.id, vehicleInfo.modelId);
CREATE_VEHICLE_QUERY, parkingLot.id, location.settings.id, vehicleInfo.modelId,
vehicleInfo.primaryColor, vehicleInfo.secondaryColor, vehicleInfo.paintjob, components);

return data.insertId;
}
@@ -558,7 +567,12 @@ class HouseDatabase {

// Updates the |vehicle| in the database with the given |vehicleInfo|.
async updateVehicle(vehicle, vehicleInfo) {
await server.database.query(UPDATE_VEHICLE_QUERY, vehicleInfo.modelId, vehicle.id);
const components = vehicleInfo.components.length ? vehicleInfo.components.join(',')
: [];

await server.database.query(
UPDATE_VEHICLE_QUERY, vehicleInfo.modelId, vehicleInfo.primaryColor,
vehicleInfo.secondaryColor, vehicleInfo.paintjob, components, vehicle.id);
}

// Removes the |location| from the database.

0 comments on commit 7576b45

Please sign in to comment.