File tree Expand file tree Collapse file tree 1 file changed +26
-4
lines changed Expand file tree Collapse file tree 1 file changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -12,11 +12,24 @@ export class UsersService {
1212  } 
1313
1414  async  findAll ( )  { 
15-     return  this . prisma . user . findMany ( {  where : {  deletedAt : null  }  } ) ; 
15+     return  this . prisma . user . findMany ( { 
16+       where : {  deletedAt : null  } , 
17+       select : { 
18+         name : true , 
19+         function : true , 
20+       } , 
21+     } ) ; 
1622  } 
1723
1824  async  findOne ( id : number )  { 
19-     const  user  =  await  this . prisma . user . findUnique ( {  where : {  id }  } ) ; 
25+     const  user  =  await  this . prisma . user . findUnique ( { 
26+       where : {  id } , 
27+       select : { 
28+         name : true , 
29+         function : true , 
30+         posts : {  where : {  isPublished : true  } ,  select : {  title : true  }  } , 
31+       } , 
32+     } ) ; 
2033
2134    if  ( ! user )  { 
2235      throw  new  NotFoundException ( 'User not found' ) ; 
@@ -26,12 +39,21 @@ export class UsersService {
2639  } 
2740
2841  async  update ( id : number ,  data : UpdateUserDto )  { 
29-     await  this . findOne ( id ) ; 
42+     const  findUser  =  await  this . findOne ( id ) ; 
43+ 
44+     if  ( ! findUser )  { 
45+       throw  new  NotFoundException ( 'User not found' ) ; 
46+     } 
47+ 
3048    return  this . prisma . user . update ( {  where : {  id } ,  data } ) ; 
3149  } 
3250
3351  async  remove ( id : number )  { 
34-     await  this . findOne ( id ) ; 
52+     const  findUser  =  await  this . findOne ( id ) ; 
53+ 
54+     if  ( ! findUser )  { 
55+       throw  new  NotFoundException ( 'User not found' ) ; 
56+     } 
3557
3658    await  this . prisma . user . delete ( {  where : {  id }  } ) ; 
3759
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments