diff --git a/db/config.go b/db/config.go index c2b4b7363..29aeb2c1a 100644 --- a/db/config.go +++ b/db/config.go @@ -460,7 +460,8 @@ func (db database) UserHasManageBountyRoles(pubKeyFromAuth string, uuid string) func (db database) ProcessUpdateTicketsWithoutGroup() { // get all tickets without group - tickets, err := DB.GetTicketsWithoutGroup() + tickets, err := db.GetTicketsWithoutGroup() + if err != nil { log.Printf("Error getting tickets without group: %v", err) return @@ -468,7 +469,8 @@ func (db database) ProcessUpdateTicketsWithoutGroup() { // update each ticket with group uuid for _, ticket := range tickets { - err := DB.UpdateTicketsWithoutGroup(ticket) + fmt.Println("ticket from process", ticket) + err := db.UpdateTicketsWithoutGroup(ticket) if err != nil { log.Printf("Error updating ticket: %v", err) } diff --git a/db/config_test.go b/db/config_test.go index a5644ac80..cf69243ba 100644 --- a/db/config_test.go +++ b/db/config_test.go @@ -1,6 +1,7 @@ package db import ( + "fmt" "testing" "time" @@ -225,31 +226,25 @@ func TestProcessUpdateTicketsWithoutGroup(t *testing.T) { // create ticket TestDB.CreateOrEditTicket(&ticket) - // get tickets without group and assert that there is 1 - tickets, err := TestDB.GetTicketsWithoutGroup() - assert.NoError(t, err) - assert.Equal(t, 1, len(tickets)) - // process update tickets without group TestDB.ProcessUpdateTicketsWithoutGroup() // get tickets without group and assert that there is 0 - tickets, err = TestDB.GetTicketsWithoutGroup() + tickets, err := TestDB.GetTicketsWithoutGroup() assert.NoError(t, err) assert.Equal(t, 0, len(tickets)) // get ticket and assert that the ticket group is the same as the ticket uuid ticket, err = TestDB.GetTicket(ticket.UUID.String()) - assert.NoError(t, err) - assert.Equal(t, ticket.TicketGroup, ticket.UUID) - // get ticket and assert that the author id is 12345 - ticket, err = TestDB.GetTicket(ticket.UUID.String()) - assert.NoError(t, err) - assert.Equal(t, ticket.AuthorID, "12345") + fmt.Println("tickets", tickets) + + ticketUuid := ticket.UUID + ticketAuthorID := "12345" + ticketAuthor := Author("HUMAN") - // get ticket and assert that the author is HUMAN - ticket, err = TestDB.GetTicket(ticket.UUID.String()) assert.NoError(t, err) - assert.Equal(t, ticket.Author, "HUMAN") + assert.Equal(t, ticket.TicketGroup, &ticketUuid) + assert.Equal(t, ticket.AuthorID, &ticketAuthorID) + assert.Equal(t, ticket.Author, &ticketAuthor) } diff --git a/db/tickets.go b/db/tickets.go index 31566d04c..b67197520 100644 --- a/db/tickets.go +++ b/db/tickets.go @@ -169,24 +169,20 @@ func (db database) GetTicketsWithoutGroup() ([]Tickets, error) { } func (db database) UpdateTicketsWithoutGroup(ticket Tickets) error { - data := []map[string]interface{}{} + data := map[string]interface{}{} - data = append(data, map[string]interface{}{ - "ticket_group": ticket.UUID, - }) + data["ticket_group"] = ticket.UUID if ticket.AuthorID == nil { - data = append(data, map[string]interface{}{ - "author_id": "12345", - }) + data["author_id"] = "12345" } if ticket.Author == nil { - data = append(data, map[string]interface{}{ - "author": "HUMAN", - }) + data["author"] = "HUMAN" } + fmt.Println("data ===", data) + result := db.db.Model(&Tickets{}).Where("uuid = ?", ticket.UUID).Updates(data) if result.Error != nil {