Skip to content

Commit

Permalink
Store customised vehicles in the database
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLVP committed Jul 14, 2020
1 parent b6f290c commit 7576b45
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions javascript/features/houses/house_database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ?`;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 7576b45

Please sign in to comment.