File tree Expand file tree Collapse file tree
routes/(portal)/portal/admin/soknader Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -125,6 +125,18 @@ export class UserService {
125125 return deletedUser ;
126126 }
127127
128+ async restoreUser ( userId : string ) {
129+ const restoredUser = await this . #db
130+ . update ( users )
131+ . set ( { isDeleted : false } )
132+ . where ( eq ( users . id , userId ) )
133+ . returning ( )
134+ . then ( ( rows ) => rows [ 0 ] ) ;
135+
136+ console . log ( `[UserService] ✅ User restored: ${ restoredUser . id } (${ restoredUser . email } )` ) ;
137+ return restoredUser ;
138+ }
139+
128140 async findByIdIncludeDeleted ( userId : string ) {
129141 const user = await this . #db
130142 . select ( )
Original file line number Diff line number Diff line change @@ -26,13 +26,18 @@ export const actions: Actions = {
2626 const email = data . get ( 'email' ) as string ;
2727 const feideId = data . get ( 'feideId' ) as string ;
2828
29- const userId = nanoid ( ) ;
30- await locals . userService . create ( {
31- id : userId ,
32- name,
33- email,
34- feideId
35- } ) ;
29+ const existingUser = await locals . userService . findByFeideId ( feideId ) ;
30+ if ( existingUser ) {
31+ await locals . userService . restoreUser ( existingUser . id ) ;
32+ } else {
33+ const userId = nanoid ( ) ;
34+ await locals . userService . create ( {
35+ id : userId ,
36+ name,
37+ email,
38+ feideId
39+ } ) ;
40+ }
3641
3742 await locals . pendingApplicationService . delete ( applicationId ) ;
3843
You can’t perform that action at this time.
0 commit comments