From e61cc9ce030ae49a29a6fbf6e8f89ad14b6df2b8 Mon Sep 17 00:00:00 2001
From: jano3 <jano@uafrica.com>
Date: Tue, 27 Sep 2022 16:28:09 +0200
Subject: [PATCH] #32 Handled nested arrays in arrays of objects

---
 audit/audit.go | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/audit/audit.go b/audit/audit.go
index 39eb87f..8c80524 100644
--- a/audit/audit.go
+++ b/audit/audit.go
@@ -2,6 +2,7 @@ package audit
 
 import (
 	"encoding/json"
+	"fmt"
 	"gitlab.com/uafrica/go-utils/errors"
 	"reflect"
 	"regexp"
@@ -79,6 +80,11 @@ func GetChanges(original interface{}, new interface{}) (map[string]interface{},
 			index, _ := string_utils.StringToInt64(indexString)
 			field := ToSnakeCase(change.Path[2])
 
+			if len(change.Path) == 5 && string_utils.IsNumericString(change.Path[3]) {
+				// The field is actually an array of objects.
+				field += fmt.Sprintf("[%s] (%s)", change.Path[3], ToSnakeCase(change.Path[4]))
+			}
+
 			arrayObject, present := changes[objectKey]
 			if present {
 				if arrayOfObjects, ok := arrayObject.([]map[string]interface{}); ok {
-- 
GitLab