Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

1.2 KB
Raw Blame
package dbEntities

import (
	"time"

	"github.com/getfider/fider/app/models/entity"
	"github.com/getfider/fider/app/models/enum"
	"github.com/getfider/fider/app/pkg/dbx"
)

type EmailVerification struct {
	ID         int                        `db:"id"`
	Name       string                     `db:"name"`
	Email      string                     `db:"email"`
	Key        string                     `db:"key"`
	Code       dbx.NullString             `db:"code"`
	Kind       enum.EmailVerificationKind `db:"kind"`
	UserID     dbx.NullInt                `db:"user_id"`
	CreatedAt  time.Time                  `db:"created_at"`
	ExpiresAt  time.Time                  `db:"expires_at"`
	VerifiedAt dbx.NullTime               `db:"verified_at"`
	Attempts   int                        `db:"attempts"`
}

func (t *EmailVerification) ToModel() *entity.EmailVerification {
	model := &entity.EmailVerification{
		Name:       t.Name,
		Email:      t.Email,
		Key:        t.Key,
		Code:       t.Code.String,
		Kind:       t.Kind,
		CreatedAt:  t.CreatedAt,
		ExpiresAt:  t.ExpiresAt,
		VerifiedAt: nil,
		Attempts:   t.Attempts,
	}

	if t.VerifiedAt.Valid {
		model.VerifiedAt = &t.VerifiedAt.Time
	}

	if t.UserID.Valid {
		model.UserID = int(t.UserID.Int64)
	}

	return model
}