Skip to content

Commit 7576b45

Browse files
committed
Store customised vehicles in the database
1 parent b6f290c commit 7576b45

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

javascript/features/houses/house_database.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,21 @@ const CREATE_HOUSE_VISITOR_LOG = `
155155
const CREATE_VEHICLE_QUERY = `
156156
INSERT INTO
157157
houses_vehicles
158-
(house_parking_lot_id, house_id, model_id, vehicle_created)
158+
(house_parking_lot_id, house_id, model_id, primary_color, secondary_color, paintjob,
159+
components, vehicle_created)
159160
VALUES
160-
(?, ?, ?, NOW())`;
161+
(?, ?, ?, ?, ?, ?, ?, NOW())`;
161162

162163
// Query for updating a vehicle in the database.
163164
const UPDATE_VEHICLE_QUERY = `
164165
UPDATE
165166
houses_vehicles
166167
SET
167-
houses_vehicles.model_id = ?
168+
houses_vehicles.model_id = ?,
169+
houses_vehicles.primary_color = ?,
170+
houses_vehicles.secondary_color = ?,
171+
houses_vehicles.paintjob = ?,
172+
houses_vehicles.components = ?
168173
WHERE
169174
houses_vehicles.house_vehicle_id = ?`;
170175

@@ -499,8 +504,12 @@ class HouseDatabase {
499504
// Creates a vehicle with |vehicleInfo| in the |parkingLot| associated with the house at
500505
// |location|. The |vehicleInfo| must be an object having {modelId}.
501506
async createVehicle(location, parkingLot, vehicleInfo) {
507+
const components = vehicleInfo.components.length ? vehicleInfo.components.join(',')
508+
: [];
509+
502510
const data = await server.database.query(
503-
CREATE_VEHICLE_QUERY, parkingLot.id, location.settings.id, vehicleInfo.modelId);
511+
CREATE_VEHICLE_QUERY, parkingLot.id, location.settings.id, vehicleInfo.modelId,
512+
vehicleInfo.primaryColor, vehicleInfo.secondaryColor, vehicleInfo.paintjob, components);
504513

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

559568
// Updates the |vehicle| in the database with the given |vehicleInfo|.
560569
async updateVehicle(vehicle, vehicleInfo) {
561-
await server.database.query(UPDATE_VEHICLE_QUERY, vehicleInfo.modelId, vehicle.id);
570+
const components = vehicleInfo.components.length ? vehicleInfo.components.join(',')
571+
: [];
572+
573+
await server.database.query(
574+
UPDATE_VEHICLE_QUERY, vehicleInfo.modelId, vehicleInfo.primaryColor,
575+
vehicleInfo.secondaryColor, vehicleInfo.paintjob, components, vehicle.id);
562576
}
563577

564578
// Removes the |location| from the database.

0 commit comments

Comments
 (0)