func (i *SessionInter) scopeModel(session *domain.Session) error { session.CreatedAt = time.Time{} session.UpdatedAt = time.Time{} session.Account = domain.Account{} return nil }
func (r *SessionRepo) UpdateByID(id int, session *domain.Session, context usecases.QueryContext) (*domain.Session, error) { query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations) if err != nil { return nil, internalerrors.DatabaseError } dbName := utils.ToDBName("sessions") oldSession := &domain.Session{} err = query.Where(dbName+".id = ?", id).First(oldSession).Error if err != nil { if strings.Contains(err.Error(), "record not found") { return nil, internalerrors.NotFound } return nil, internalerrors.DatabaseError } session.ID = oldSession.ID session.CreatedAt = oldSession.CreatedAt err = r.store.GetDB().Save(&session).Error if err != nil { if strings.Contains(err.Error(), "constraint") { return nil, internalerrors.NewViolatedConstraint(err.Error()) } return nil, internalerrors.DatabaseError } return session, nil }