mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-18 13:14:56 +01:00
* Update Makefile * Optionally load test DB from env variable * Add option to soft-delete a user This allows users to be marked as deleted. An additional middleware checks if a user is deleted or deactivated and rejects requests for those as StatusUnauthorized. note: the middelware adds an additional DB query to load the user.
34 lines
830 B
Go
34 lines
830 B
Go
package models
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
// User : User Model
|
|
type User struct {
|
|
ID int64 `bun:",pk,autoincrement"`
|
|
Email sql.NullString `bun:",unique"`
|
|
Login string `bun:",unique,notnull"`
|
|
Password string `bun:",notnull"`
|
|
CreatedAt time.Time `bun:",nullzero,notnull,default:current_timestamp"`
|
|
UpdatedAt bun.NullTime
|
|
Invoices []*Invoice `bun:"rel:has-many,join:id=user_id"`
|
|
Accounts []*Account `bun:"rel:has-many,join:id=user_id"`
|
|
Deactivated bool
|
|
Deleted bool
|
|
}
|
|
|
|
func (u *User) BeforeAppendModel(ctx context.Context, query bun.Query) error {
|
|
switch query.(type) {
|
|
case *bun.UpdateQuery:
|
|
u.UpdatedAt = bun.NullTime{Time: time.Now()}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var _ bun.BeforeAppendModelHook = (*User)(nil)
|