Skip to content

Instantly share code, notes, and snippets.

@blackjmxx
Last active November 29, 2020 15:12
Show Gist options
  • Save blackjmxx/5b64b2152b324adba77b4c445180ca7d to your computer and use it in GitHub Desktop.
Save blackjmxx/5b64b2152b324adba77b4c445180ca7d to your computer and use it in GitHub Desktop.
applyAsset(store) {
const errors = [];
const travel = store.account.getOrDefault(this.asset.travelId);
const driver = store.account.get(this.senderId)
const driverTravels = driver.asset.driverTravels || []
if (!travel.asset.pickUpDate) {
const driverTravel = {
carId:this.asset.carId,
travelId:this.asset.travelId,
senderId: this.senderId,
driverAdress: this.asset.driverAdress,
pickUpLocation: this.asset.pickUpLocation,
pickUpDate:this.asset.pickUpDate,
availableSeatCount: this.asset.availableSeatCount,
pricePerSeat:this.asset.pricePerSeat,
destination:this.asset.destination
}
driverTravels.push(driverTravel)
const updatedTravelAccount = {
...travel,
asset: {
carId:this.asset.carId,
travelId:this.asset.travelId,
senderId: this.senderId,
driverAdress: this.asset.driverAdress,
pickUpLocation: this.asset.pickUpLocation,
pickUpDate:this.asset.pickUpDate,
availableSeatCount: this.asset.availableSeatCount,
pricePerSeat:this.asset.pricePerSeat,
destination:this.asset.destination
}
};
const updatedDriverAccount = {
...driver,
asset: {
...driver.asset,
driverTravels:driverTravels,
}
};
store.account.set(travel.address, updatedTravelAccount);
store.account.set(this.senderId, updatedDriverAccount);
}else {
errors.push(
new TransactionError(
'travel has already been registered',
producer.asset.name
)
);
}
return errors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment