Skip to content

Commit

Permalink
Merge pull request #33 from threefoldtech/fix_pubips
Browse files Browse the repository at this point in the history
fix: sync pub ips when farm is updated
  • Loading branch information
DylanVerstraete authored Jun 1, 2022
2 parents 5e5d267 + 920d2eb commit 5488e15
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/mappings/farms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,25 @@ export async function farmUpdated(ctx: EventHandlerContext) {
await farmUpdatedEventParsed.publicIps.forEach(async ip => {
const savedIP = await ctx.store.get(PublicIp, { where: { ip: ip.ip.toString() }})
// ip is already there in storage, don't save it again
if (savedIP) return
if (savedIP) {
savedIP.ip = ip.ip.toString()
savedIP.contractId = ip.contractId
savedIP.gateway = ip.gateway.toString()
await ctx.store.save<PublicIp>(savedIP)
} else {
const newIP = new PublicIp()
newIP.id = ctx.event.id
newIP.ip = ip.ip.toString()
newIP.gateway = ip.gateway.toString()
newIP.contractId = ip.contractId
newIP.farm = savedFarm

const newIP = new PublicIp()
newIP.id = ctx.event.id
newIP.ip = ip.ip.toString()
newIP.gateway = ip.gateway.toString()
newIP.contractId = ip.contractId
newIP.farm = savedFarm

await ctx.store.save<PublicIp>(newIP)
if (!savedFarm.publicIPs) {
savedFarm.publicIPs = []
await ctx.store.save<PublicIp>(newIP)
if (!savedFarm.publicIPs) {
savedFarm.publicIPs = []
}
savedFarm.publicIPs.push(newIP)
}
savedFarm.publicIPs.push(newIP)
})

await ctx.store.save<Farm>(savedFarm)
Expand Down

0 comments on commit 5488e15

Please sign in to comment.