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,
|
"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,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
|
||||||
1
main.go
1
main.go
|
|
@ -231,6 +231,7 @@ func main() {
|
||||||
if config.Debug {
|
if config.Debug {
|
||||||
app.Get("/debug/fake-members/:number<int;min(1)>", controllers.DebugFakeMembers)
|
app.Get("/debug/fake-members/:number<int;min(1)>", controllers.DebugFakeMembers)
|
||||||
app.Get("/debug/fake-contacts/:number<int;min(1)>", controllers.DebugFakeContacts)
|
app.Get("/debug/fake-contacts/:number<int;min(1)>", controllers.DebugFakeContacts)
|
||||||
|
app.Get("/debug/fix-fields-order", controllers.DebugFixFieldsOrder)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info(
|
log.Info(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue