Vehicles
Vehicles and their attached data will work pretty much as documented in the IronAPI documentation.
According to the client which is logged in, their universe will list the available options to list and change the data.
Many entites have and "owning_customer" as attributes - it is optional and will be set automatically, so best to never show it in forms and never send them. Exception: when creating or changing a vehicle, owning_customer is required and needs to be set by the user.
Some entities are only available to certain client agendas (e.g. vehicle_note). Sending a query joining this entity will result in an error, so do not do this.
Example
List all vehicles, filter by band "Renault", join internal notes, attached files and their type definitions:
# POST {{url}}/data/core/vehicle/query
{
"conds" : {"me.brand" : "Renault"},
"attrs" : {
"prefetch" : ["core__vehicle_note__vehicle", {"core__vehicle_file__vehicle" : "vehicle_document_type"}]
}
}
Note that this query will fail for clients without "admin" or "employee" agendas, as they have no access to "vehicle_note".
core__vehicle_file__vehicle.id can be used to show a download button for the file. The Link will looks something like this
{{url}}/data/core/file/3/download/file
Reowning a vehicle
To fulfil the requirement, that the data (vehicle_maintenance) stored should not be visible to the new owner of a vehicle, a new database entry with the same vin is created and the old entry gets the "reowned_id" set to the newly created entry.
To do this within one transaction, a plugin is provided:
POST https://garage.abocar.at/plugins/vehicle_reown
{
"vehicle_id" : 2,
"customer_id" : 5
}
Queries taking reowned vehicles into account
All Instances
To find all entries for a vin which the user has access to (so, the admin sees all existing ones, the owner(s) only one each).
POST https://garage.abocar.at/data/core/vehicle/query
{
"conds" : {"vin":"vin_megane"}
}
Current Instance
POST https://garage.abocar.at/data/core/vehicle/query
{
"conds" : {"vin":"vin_megane", "reowned_id" : null}
}
All Maintenances
The following query will give a list of all instances with a certain vin, regardless of ownership. As an admin will have access to all maintenances, they will see all of them. A customer will only find the instances which happened during their ownership.
POST https://garage.abocar.at/data/core/vehicle_maintenance/query
{
"conds" : {"vehicle.vin" : "vin_megane"},
"attrs" : {
"join" : ["vehicle"]
}
}