(
service: any,
{ entities, connections: allConnections }: ProviderData,
initiatorServiceName: string,
afterNodeInsertion = false
)
| 42 | // in the main add mutation(batch mutation, that pushes fresh nodes and connections) |
| 43 | // or in the patch mutation(list of mutations that patches each node and its connections with others) |
| 44 | export function getConnectedEntity( |
| 45 | service: any, |
| 46 | { entities, connections: allConnections }: ProviderData, |
| 47 | initiatorServiceName: string, |
| 48 | afterNodeInsertion = false |
| 49 | ): Record<string, unknown> { |
| 50 | logger.debug( |
| 51 | `Getting connected entities for ${chalk.green( |
| 52 | initiatorServiceName |
| 53 | )} id = ${chalk.green(service.id)}` |
| 54 | ) |
| 55 | const connections: ServiceConnection[] = |
| 56 | filterConnectionsByPriorityOfInsertion(allConnections, afterNodeInsertion)[ |
| 57 | service.id |
| 58 | ] |
| 59 | const connectedEntity: any = { ...(afterNodeInsertion ? {} : service) } |
| 60 | let connectionsStatus = scanResult.pass |
| 61 | if (!isEmpty(connections)) { |
| 62 | for (const connection of connections) { |
| 63 | const entityData = entities.find( |
| 64 | ({ name }: { name: string }) => name === connection.resourceType |
| 65 | ) |
| 66 | if (entityData && entityData.data) { |
| 67 | const entityForConnection = entityData.data.find( |
| 68 | ({ id }: { id: string }) => connection.id === id |
| 69 | ) |
| 70 | if (!isEmpty(entityForConnection)) { |
| 71 | if (!connectedEntity[connection.field]) { |
| 72 | connectedEntity[connection.field] = [] |
| 73 | } |
| 74 | connectedEntity[connection.field].push(entityForConnection) |
| 75 | logger.debug( |
| 76 | `(${initiatorServiceName}) ${service.id} ${chalk.green( |
| 77 | '<----->' |
| 78 | )} ${connection.id} (${connection.resourceType})` |
| 79 | ) |
| 80 | } else { |
| 81 | connectionsStatus = scanResult.warn |
| 82 | const error = `Malformed connection found between ${chalk.red( |
| 83 | initiatorServiceName |
| 84 | )} && ${chalk.red(connection.resourceType)} services.` |
| 85 | logger.warn(error) |
| 86 | logger.warn( |
| 87 | `(${initiatorServiceName}) ${service.id} ${chalk.red('<-///->')} ${ |
| 88 | connection.id |
| 89 | } (${connection.resourceType})` |
| 90 | ) |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | scanReport.pushData({ |
| 96 | service: initiatorServiceName, |
| 97 | type: scanDataType.status, |
| 98 | result: connectionsStatus, |
| 99 | }) |
| 100 | return connectedEntity |
| 101 | } |
no test coverage detected