File tree Expand file tree Collapse file tree 1 file changed +37
-3
lines changed Expand file tree Collapse file tree 1 file changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ export class CompanyService {
16
16
@InjectRepository ( User )
17
17
private userRepository : Repository < User > ,
18
18
) { }
19
-
19
+
20
20
findAll ( paginationDTO : PaginationDTO ) : Promise < Company [ ] > {
21
21
return this . companyRepository . find ( {
22
22
relations : [ 'user' ] ,
@@ -25,12 +25,46 @@ export class CompanyService {
25
25
} ) ;
26
26
}
27
27
28
+ findAllByUser ( userId : number , paginationDTO : PaginationDTO ) : Promise < Company [ ] > {
29
+ return this . companyRepository . find ( {
30
+ where : { user : { id : userId } } ,
31
+ relations : [ 'user' ] ,
32
+ skip : paginationDTO . skip ,
33
+ take : paginationDTO . limit ?? DEFAULT_PAGE_SIZE ,
34
+ select : {
35
+ id : true ,
36
+ name : true ,
37
+ phoneNumber : true ,
38
+ cnpj : true ,
39
+ user : {
40
+ id : true ,
41
+ username : true ,
42
+ email : true ,
43
+ } ,
44
+ } ,
45
+ } ) ;
46
+ }
47
+
28
48
findOne ( id : number ) : Promise < Company > {
29
- return this . companyRepository . findOne ( { where : { id } , relations : [ 'user' ] } ) ;
49
+ return this . companyRepository . findOne ( {
50
+ where : { id } ,
51
+ relations : [ 'user' ] ,
52
+ select : {
53
+ id : true ,
54
+ name : true ,
55
+ user : {
56
+ id : true ,
57
+ username : true ,
58
+ }
59
+ } } ) ;
30
60
}
31
61
32
62
async create ( userId : number , body : CreateCompanyDto ) : Promise < Company > {
33
- const user = await this . userRepository . findOne ( { where : { id : userId } } ) ;
63
+ const user = await this . userRepository . findOne ( {
64
+ where :
65
+ { id : userId } ,
66
+ select : [ 'id' , 'username' , 'email' , 'role' ]
67
+ } ) ;
34
68
if ( ! user ) {
35
69
throw new NotFoundException ( `User with ID ${ userId } not found` ) ;
36
70
}
You can’t perform that action at this time.
0 commit comments