Add company to the verifyapiKey
diff --git a/api.go b/api.go
index 3d47d52..eb5b6b2 100644
--- a/api.go
+++ b/api.go
@@ -75,7 +75,6 @@
 // returns []byte to be written to client
 func verifyAPIKey(f url.Values) ([]byte, error) {
 
-
 	key := f.Get("key")
 	scopeuuid := f.Get("scopeuuid")
 	path := f.Get("uriPath")
@@ -105,16 +104,41 @@
 		return errorResponse(reason, errorCode)
 	}
 
-	log.Debug("Found tenant_id='", tenantId, "' with env='", env, "' for scopeuuid='", scopeuuid,"'")
+	log.Debug("Found tenant_id='", tenantId, "' with env='", env, "' for scopeuuid='", scopeuuid, "'")
 
-	sSql := "SELECT ap.api_resources, ap.environments, c.issued_at, c.status, a.callback_url, d.username, d.id " +
-		"FROM APP_CREDENTIAL AS c INNER JOIN APP AS a ON c.app_id = a.id " +
-		"INNER JOIN DEVELOPER AS d ON a.developer_id = d.id " +
-		"INNER JOIN APP_CREDENTIAL_APIPRODUCT_MAPPER as mp ON mp.appcred_id = c.id " +
-		"INNER JOIN API_PRODUCT as ap ON ap.id = mp.apiprdt_id " +
-		"WHERE (UPPER(d.status) = 'ACTIVE' AND mp.apiprdt_id = ap.id AND mp.app_id = a.id " +
-		"AND mp.appcred_id = c.id AND UPPER(mp.status) = 'APPROVED' AND UPPER(a.status) = 'APPROVED' " +
-		"AND c.id = $1 AND c.tenant_id = $2);"
+	sSql := `
+		WITH ALL_DEVELOPERS AS (
+			SELECT d.id, d.name, d.status
+			FROM DEVELOPER as d
+				INNER JOIN APP as a ON a.parent_id = d.id
+			UNION ALL
+			SELECT c.id, c.name, c.status
+			FROM COMPANY as c
+				INNER JOIN APP as a ON a.parent_id = c.id
+		)
+		SELECT 
+			ap.api_resources, 
+			ap.environments, 
+			c.issued_at,
+			c.status,
+			a.callback_url,
+			ad.name,
+			ad.id
+		FROM APP_CREDENTIAL AS c 
+			INNER JOIN APP AS a ON c.app_id = a.id
+			INNER JOIN ALL_DEVELOPERS AS ad 
+				ON (ad.id = a.company_id OR ad.id = a.developer_id)
+			INNER JOIN APP_CREDENTIAL_APIPRODUCT_MAPPER as mp 
+				ON mp.appcred_id = c.id 
+			INNER JOIN API_PRODUCT as ap ON ap.id = mp.apiprdt_id
+		WHERE (UPPER(ad.status) = 'ACTIVE' 
+			AND mp.apiprdt_id = ap.id 
+			AND mp.app_id = a.id
+			AND mp.appcred_id = c.id 
+			AND UPPER(mp.status) = 'APPROVED' 
+			AND UPPER(a.status) = 'APPROVED'
+			AND c.id = $1 
+			AND c.tenant_id = $2);`
 
 	var status, redirectionURIs, developerAppName, developerId, resName, resEnv string
 	var issuedAt int64
diff --git a/api_test.go b/api_test.go
index 87430a8..bc545e2 100644
--- a/api_test.go
+++ b/api_test.go
@@ -32,6 +32,7 @@
 				res := insertDevelopers([]common.Row{row}, txn)
 				Expect(res).Should(BeTrue())
 			}
+
 			// companies
 			for i := 0; i < 10; i++ {
 				row := generateTestCompany(i)
@@ -41,7 +42,7 @@
 
 			// company developers
 			for i := 0; i < 10; i++ {
-				row := generateTestCompanyDeveloper(i);
+				row := generateTestCompanyDeveloper(i)
 				res := insertCompanyDevelopers([]common.Row{row}, txn)
 				Expect(res).Should(BeTrue())
 			}
@@ -50,7 +51,7 @@
 			var j, k int
 			for i := 0; i < 10; i++ {
 				for j = k; j < 10+k; j++ {
-					row := generateTestApp(j, i);
+					row := generateTestApp(j, i)
 					res := insertApplications([]common.Row{row}, txn)
 					Expect(res).Should(BeTrue())
 				}
@@ -118,7 +119,7 @@
 			Expect(err).ShouldNot(HaveOccurred())
 
 			for i := 0; i < 10; i++ {
-				row := generateTestApiProductMapper(i);
+				row := generateTestApiProductMapper(i)
 				res := deleteAPIproductMapper(row, txn)
 				Expect(res).Should(BeTrue())
 			}
diff --git a/init.go b/init.go
index 823158f..555d848 100644
--- a/init.go
+++ b/init.go
@@ -73,6 +73,7 @@
     PRIMARY KEY (tenant_id, id));
 CREATE TABLE IF NOT EXISTS developer (
     id text,
+    name text,
     tenant_id text,
     username text,
     first_name text,
@@ -124,6 +125,7 @@
     status text,
     app_family text,
     company_id text,
+    parent_id text,
     developer_id text,
     type int,
     created_at int64,
@@ -155,6 +157,7 @@
     status text,
     PRIMARY KEY (appcred_id, app_id, apiprdt_id,tenant_id)
 );
+CREATE INDEX IF NOT EXISTS company_id ON company (id);
 CREATE INDEX IF NOT EXISTS developer_id ON developer (id);
 CREATE INDEX IF NOT EXISTS api_product_id ON api_product (id);
 CREATE INDEX IF NOT EXISTS app_id ON app (id);
diff --git a/listener.go b/listener.go
index 749160f..8ceb9bc 100644
--- a/listener.go
+++ b/listener.go
@@ -134,10 +134,10 @@
  */
 func insertApplications(rows []common.Row, txn *sql.Tx) bool {
 
-	var scope, EntityIdentifier, DeveloperId, CallbackUrl, Status, AppName, AppFamily, tenantId, CreatedBy, LastModifiedBy string
+	var scope, EntityIdentifier, DeveloperId, CompanyId, ParentId, CallbackUrl, Status, AppName, AppFamily, tenantId, CreatedBy, LastModifiedBy string
 	var CreatedAt, LastModifiedAt int64
 
-	prep, err := txn.Prepare("INSERT INTO APP (_change_selector, id, developer_id,callback_url,status, name, app_family, created_at, created_by,updated_at, updated_by,tenant_id) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12);")
+	prep, err := txn.Prepare("INSERT INTO APP (_change_selector, id, developer_id, company_id, parent_id, callback_url,status, name, app_family, created_at, created_by,updated_at, updated_by,tenant_id) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);")
 	if err != nil {
 		log.Error("INSERT APP Failed: ", err)
 		return false
@@ -149,6 +149,8 @@
 		ele.Get("_change_selector", &scope)
 		ele.Get("id", &EntityIdentifier)
 		ele.Get("developer_id", &DeveloperId)
+		ele.Get("company_id", &CompanyId)
+		ele.Get("parent_id", &ParentId)
 		ele.Get("callback_url", &CallbackUrl)
 		ele.Get("status", &Status)
 		ele.Get("name", &AppName)
@@ -168,6 +170,8 @@
 			scope,
 			EntityIdentifier,
 			DeveloperId,
+			CompanyId,
+			ParentId,
 			CallbackUrl,
 			Status,
 			AppName,
@@ -194,10 +198,10 @@
  */
 func insertDevelopers(rows []common.Row, txn *sql.Tx) bool {
 
-	var scope, EntityIdentifier, Email, Status, UserName, FirstName, LastName, tenantId, CreatedBy, LastModifiedBy, Username string
+	var scope, EntityIdentifier, Email, Status, UserName, FirstName, LastName, tenantId, CreatedBy, LastModifiedBy, Username, Name string
 	var CreatedAt, LastModifiedAt int64
 
-	prep, err := txn.Prepare("INSERT INTO DEVELOPER (_change_selector,email,id,tenant_id,status,username,first_name,last_name,created_at,created_by,updated_at,updated_by) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12);")
+	prep, err := txn.Prepare("INSERT INTO DEVELOPER (_change_selector,email,id,tenant_id,status,username,first_name,last_name,name,created_at,created_by,updated_at,updated_by) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13);")
 	if err != nil {
 		log.Error("INSERT DEVELOPER Failed: ", err)
 		return false
@@ -214,6 +218,7 @@
 		ele.Get("username", &Username)
 		ele.Get("first_name", &FirstName)
 		ele.Get("last_name", &LastName)
+		ele.Get("email", &Name)
 		ele.Get("created_at", &CreatedAt)
 		ele.Get("created_by", &CreatedBy)
 		ele.Get("updated_at", &LastModifiedAt)
@@ -233,6 +238,7 @@
 			UserName,
 			FirstName,
 			LastName,
+			Name,
 			CreatedAt,
 			CreatedBy,
 			LastModifiedAt,