@@ -38,14 +38,25 @@ func (d *PersonalAccessToken) TableName() string {
38
38
func GetPersonalAccessTokenForUser (ctx context.Context , conn * gorm.DB , tokenID uuid.UUID , userID uuid.UUID ) (PersonalAccessToken , error ) {
39
39
var token PersonalAccessToken
40
40
41
- db := conn .WithContext (ctx )
41
+ if tokenID == uuid .Nil {
42
+ return PersonalAccessToken {}, fmt .Errorf ("Token ID is a required argument to get personal access token for user" )
43
+ }
42
44
43
- db = db .Where ("id = ?" , tokenID ).Where ("userId = ?" , userID ).Where ("deleted = ?" , 0 ).First (& token )
44
- if db .Error != nil {
45
- if errors .Is (db .Error , gorm .ErrRecordNotFound ) {
45
+ if userID == uuid .Nil {
46
+ return PersonalAccessToken {}, fmt .Errorf ("User ID is a required argument to get personal access token for user" )
47
+ }
48
+
49
+ tx := conn .
50
+ WithContext (ctx ).
51
+ Where ("id = ?" , tokenID ).
52
+ Where ("userId = ?" , userID ).
53
+ Where ("deleted = ?" , 0 ).
54
+ First (& token )
55
+ if tx .Error != nil {
56
+ if errors .Is (tx .Error , gorm .ErrRecordNotFound ) {
46
57
return PersonalAccessToken {}, fmt .Errorf ("Token with ID %s does not exist: %w" , tokenID , ErrorNotFound )
47
58
}
48
- return PersonalAccessToken {}, fmt .Errorf ("Failed to retrieve token: %v" , db .Error )
59
+ return PersonalAccessToken {}, fmt .Errorf ("Failed to retrieve token: %v" , tx .Error )
49
60
}
50
61
51
62
return token , nil
0 commit comments