@@ -7,6 +7,7 @@ import { PublicConfig as V105PublicConfig } from '../types/v105'
7
7
8
8
import { Ctx } from '../processor'
9
9
import assert from "assert" ;
10
+ import { allowedNodeEnvironmentFlags } from "process" ;
10
11
11
12
export async function nodeStored (
12
13
ctx : Ctx ,
@@ -139,11 +140,9 @@ export async function nodeStored(
139
140
newInterface . mac = intf . mac . toString ( )
140
141
newInterface . ips = intf . ips . map ( ip => ip . toString ( ) ) . join ( ',' )
141
142
await ctx . store . save < Interfaces > ( newInterface )
142
- newNode . interfaces . push ( newInterface )
143
143
} )
144
144
145
145
await Promise . all ( interfacesPromisses )
146
- await ctx . store . save < Node > ( newNode )
147
146
}
148
147
149
148
export async function nodeUpdated (
@@ -319,31 +318,23 @@ export async function nodeUpdated(
319
318
}
320
319
}
321
320
322
- const interfacesPromisses = nodeEvent . interfaces . map ( async intf => {
323
- let newInterface
324
-
325
- if ( savedNode . interfaces ) {
326
- // if an interface with same name exists
327
- const found = savedNode . interfaces . findIndex ( interf => interf . name === intf . name . toString ( ) )
328
- if ( found > 0 ) {
329
- newInterface = savedNode . interfaces [ found ]
330
- } else {
331
- newInterface = new Interfaces ( )
332
- newInterface . id = item . event . id
333
- newInterface . node = savedNode
334
- }
335
- }
336
-
337
- if ( ! newInterface ) return
321
+ // First remove all ifs
322
+ const nodeIfs = await ctx . store . find ( Interfaces , { where : { node : { nodeID : savedNode . nodeID } } } )
323
+ await ctx . store . remove ( nodeIfs )
338
324
325
+ // Save ones from update event
326
+ await Promise . all ( nodeEvent . interfaces . map ( async intf => {
327
+ const newInterface = new Interfaces ( )
328
+ newInterface . id = item . event . id + intf . name . toString ( )
339
329
newInterface . name = intf . name . toString ( )
340
330
newInterface . mac = intf . mac . toString ( )
341
331
newInterface . ips = intf . ips . map ( ip => ip . toString ( ) ) . join ( ',' )
342
-
332
+ newInterface . node = savedNode
343
333
await ctx . store . save < Interfaces > ( newInterface )
334
+
344
335
savedNode . interfaces . push ( newInterface )
345
- } )
346
- await Promise . all ( interfacesPromisses )
336
+ } ) )
337
+
347
338
await ctx . store . save < Node > ( savedNode )
348
339
}
349
340
0 commit comments