34 lines
887 B
Go
34 lines
887 B
Go
package user
|
|
|
|
import (
|
|
"janex/admin-dashboard-backend/modules/database"
|
|
"janex/admin-dashboard-backend/modules/structs"
|
|
"janex/admin-dashboard-backend/socketclients"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func SignOutSession(c *fiber.Ctx) error {
|
|
var params structs.UserSignOutSessionRequest
|
|
|
|
if err := c.ParamsParser(¶ms); err != nil {
|
|
log.Error().Msg("Failed to parse params, err: " + err.Error())
|
|
return c.SendStatus(fiber.StatusBadRequest)
|
|
}
|
|
|
|
var userSession structs.UserSession
|
|
|
|
database.DB.First(&userSession, "id_for_deletion = ?", params.IdForDeletion)
|
|
|
|
if userSession.Id != "" {
|
|
database.DB.Delete(&structs.UserSession{}, "id = ?", userSession.Id)
|
|
|
|
socketclients.CloseAllUserSessionConnections(userSession.Id)
|
|
|
|
socketclients.UpdateUserSessionsForUser(userSession.UserId, userSession.Id)
|
|
}
|
|
|
|
return c.SendStatus(fiber.StatusOK)
|
|
}
|