Method to fix fields order
This commit is contained in:
parent
3b9ca37baa
commit
cc3eaa8c4f
2 changed files with 54 additions and 0 deletions
|
|
@ -101,3 +101,56 @@ func DebugFakeContacts(c *fiber.Ctx) error {
|
|||
"Created %d contact(s)", number,
|
||||
))
|
||||
}
|
||||
|
||||
func DebugFixFieldsOrder(c *fiber.Ctx) error {
|
||||
db, err := helpers.GetDatabase()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var memberFields []models.Field
|
||||
result := db.Order(
|
||||
"name collate nocase asc",
|
||||
).Find(
|
||||
&memberFields, "person_type = ?", "member",
|
||||
)
|
||||
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
|
||||
if result.RowsAffected > 0 {
|
||||
position := 1
|
||||
for _, field := range memberFields {
|
||||
field.Position = position
|
||||
db.Save(&field)
|
||||
position++
|
||||
}
|
||||
}
|
||||
|
||||
var contactFields []models.Field
|
||||
result2 := db.Order(
|
||||
"name collate nocase asc",
|
||||
).Find(
|
||||
&contactFields, "person_type = ?", "contact",
|
||||
)
|
||||
|
||||
if result2.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
|
||||
if result2.RowsAffected > 0 {
|
||||
position := 1
|
||||
for _, field := range contactFields {
|
||||
field.Position = position
|
||||
db.Save(&field)
|
||||
position++
|
||||
}
|
||||
}
|
||||
|
||||
return c.SendString(fmt.Sprintf(
|
||||
"Fixed fields -> members: %d, contacts: %d",
|
||||
result.RowsAffected,
|
||||
result2.RowsAffected,
|
||||
))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue