@@ -74,12 +74,14 @@ func (r *UserRepo) AdminByName(ctx context.Context, username string) (*db.Admin,
7474}
7575
7676func (r * UserRepo ) GetByName (ctx context.Context , username string ) (* db.User , error ) {
77- return r .db .User .Query ().Where (
78- user .Or (
79- user .Username (username ),
80- user .Email (username ),
81- ),
82- ).Only (ctx )
77+ return r .db .User .Query ().
78+ Where (
79+ user .Or (
80+ user .Username (username ),
81+ user .Email (username ),
82+ ),
83+ ).
84+ Only (ctx )
8385}
8486
8587func (r * UserRepo ) ValidateInviteCode (ctx context.Context , code string ) (* db.InviteCode , error ) {
@@ -167,12 +169,12 @@ func (r *UserRepo) CreateInviteCode(ctx context.Context, userID string, code str
167169}
168170
169171func (r * UserRepo ) AdminList (ctx context.Context , page * web.Pagination ) ([]* db.Admin , * db.PageInfo , error ) {
170- q := r .db .Admin .Query ()
172+ q := r .db .Admin .Query (). Order ( admin . ByCreatedAt ( sql . OrderDesc ()))
171173 return q .Page (ctx , page .Page , page .Size )
172174}
173175
174176func (r * UserRepo ) List (ctx context.Context , page * web.Pagination ) ([]* db.User , * db.PageInfo , error ) {
175- q := r .db .User .Query ()
177+ q := r .db .User .Query (). Order ( user . ByCreatedAt ( sql . OrderDesc ()))
176178 return q .Page (ctx , page .Page , page .Size )
177179}
178180
@@ -241,7 +243,7 @@ func (r *UserRepo) UpdateSetting(ctx context.Context, fn func(*db.Setting, *db.S
241243 return res , err
242244}
243245
244- func (r * UserRepo ) Update (ctx context.Context , id string , fn func (* db.User , * db.UserUpdateOne ) error ) (* db.User , error ) {
246+ func (r * UserRepo ) Update (ctx context.Context , id string , fn func (* db.Tx , * db. User , * db.UserUpdateOne ) error ) (* db.User , error ) {
245247 uid , err := uuid .Parse (id )
246248 if err != nil {
247249 return nil , err
@@ -254,7 +256,7 @@ func (r *UserRepo) Update(ctx context.Context, id string, fn func(*db.User, *db.
254256 return err
255257 }
256258 up := tx .User .UpdateOneID (u .ID )
257- if err = fn (u , up ); err != nil {
259+ if err = fn (tx , u , up ); err != nil {
258260 return err
259261 }
260262 return up .Exec (ctx )
@@ -372,6 +374,9 @@ func (r *UserRepo) OAuthLogin(ctx context.Context, platform consts.UserPlatform,
372374 if err != nil {
373375 return nil , errcode .ErrNotInvited .Wrap (err )
374376 }
377+ if ui .Edges .User .Status != consts .UserStatusActive {
378+ return nil , errcode .ErrUserLock
379+ }
375380 if ui .AvatarURL != req .AvatarURL {
376381 if err = entx .WithTx (ctx , r .db , func (tx * db.Tx ) error {
377382 return r .updateAvatar (ctx , tx , ui , req .AvatarURL )
@@ -409,6 +414,9 @@ func (r *UserRepo) SignUpOrIn(ctx context.Context, platform consts.UserPlatform,
409414 First (ctx )
410415 if err == nil {
411416 u = ui .Edges .User
417+ if u .Status != consts .UserStatusActive {
418+ return errcode .ErrUserLock
419+ }
412420 if ui .AvatarURL != req .AvatarURL {
413421 if err = r .updateAvatar (ctx , tx , ui , req .AvatarURL ); err != nil {
414422 return err
0 commit comments