🐛 Fix activating badges
This commit is contained in:
parent
bc31a94c98
commit
53d856c7a7
@ -3,6 +3,7 @@ package grpc
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
localCache "git.solsynth.dev/hypernet/passport/pkg/internal/cache"
|
||||
@ -46,7 +47,7 @@ func (v *App) GetUser(ctx context.Context, request *proto.GetUserRequest) (*prot
|
||||
if err := tx.
|
||||
Preload("Profile").
|
||||
Preload("Badges", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("badges.type DESC")
|
||||
return db.Order("badges.is_active DESC, badges.type DESC")
|
||||
}).
|
||||
First(&account).Error; err != nil {
|
||||
return nil, status.Errorf(codes.NotFound, fmt.Sprintf("requested user with id %d was not found", request.GetUserId()))
|
||||
|
@ -18,11 +18,11 @@ func ActiveBadge(badge models.Badge) error {
|
||||
accountId := badge.AccountID
|
||||
tx := database.C.Begin()
|
||||
|
||||
if err := tx.Model(&badge).Where("account_id = ?", accountId).Update("is_active", false).Error; err != nil {
|
||||
if err := tx.Model(&models.Badge{}).Where("account_id = ?", accountId).Update("is_active", false).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
if err := tx.Model(&badge).Where("id = ?", badge.ID).Update("is_active", true).Error; err != nil {
|
||||
if err := tx.Model(&models.Badge{}).Where("id = ?", badge.ID).Update("is_active", true).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func getUserInBatch(c *fiber.Ctx) error {
|
||||
if err := tx.
|
||||
Preload("Profile").
|
||||
Preload("Badges", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("badges.type DESC")
|
||||
return db.Order("badges.is_active DESC, badges.type DESC")
|
||||
}).
|
||||
Find(&accounts).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
@ -148,7 +148,7 @@ func updateUserinfo(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
var links = make(map[string]any)
|
||||
links := make(map[string]any)
|
||||
for k, v := range data.Links {
|
||||
links[k] = v
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ func getOtherUserinfo(c *fiber.Ctx) error {
|
||||
if err := tx.
|
||||
Preload("Profile").
|
||||
Preload("Badges", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("badges.type DESC")
|
||||
return db.Order("badges.is_active DESC, badges.type DESC")
|
||||
}).
|
||||
First(&account).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
|
Loading…
x
Reference in New Issue
Block a user