File tree 3 files changed +33
-2
lines changed
3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 1
- module . exports = {
1
+ const eslint = require ( '@eslint/js' ) ;
2
+ const tseslint = require ( 'typescript-eslint' ) ;
3
+
4
+ module . exports = tseslint . config ( {
2
5
parser : '@typescript-eslint/parser' ,
3
6
parserOptions : {
4
7
project : 'tsconfig.json' ,
@@ -22,4 +25,4 @@ module.exports = {
22
25
'@typescript-eslint/explicit-module-boundary-types' : 'off' ,
23
26
'@typescript-eslint/no-explicit-any' : 'off' ,
24
27
} ,
25
- } ;
28
+ } ) ;
Original file line number Diff line number Diff line change @@ -31,11 +31,21 @@ export class ProductsController {
31
31
return this . productsService . findById ( id ) ;
32
32
}
33
33
34
+ @Get ( ':id/related' )
35
+ getRelatedProducts ( @Param ( 'id' , ParseIntPipe ) id : number ) {
36
+ return this . productsService . getRelatedProducts ( id ) ;
37
+ }
38
+
34
39
@Get ( 'slug/:slug' )
35
40
getProductBySlug ( @Param ( 'slug' ) slug : string ) {
36
41
return this . productsService . findBySlug ( slug ) ;
37
42
}
38
43
44
+ @Get ( 'slug/:slug/related' )
45
+ getRelatedProductsBySlug ( @Param ( 'slug' ) slug : string ) {
46
+ return this . productsService . getRelatedProductsBySlug ( slug ) ;
47
+ }
48
+
39
49
@Post ( )
40
50
create ( @Body ( ) product : CreateProductDto ) {
41
51
return this . productsService . create ( product ) ;
Original file line number Diff line number Diff line change 7
7
FindManyOptions ,
8
8
Like ,
9
9
And ,
10
+ Not ,
10
11
} from 'typeorm' ;
11
12
12
13
import { Product } from '@db/entities/product.entity' ;
@@ -95,13 +96,30 @@ export class ProductsService {
95
96
} ) ;
96
97
}
97
98
99
+ async getRelatedProducts ( id : number ) {
100
+ const product = await this . findById ( id ) ;
101
+
102
+ return this . productsRepo . find ( {
103
+ relations : [ 'category' ] ,
104
+ where : {
105
+ category : { id : product . category . id } ,
106
+ id : Not ( id ) ,
107
+ } ,
108
+ } ) ;
109
+ }
110
+
98
111
findBySlug ( slug : string ) {
99
112
return this . productsRepo . findOneOrFail ( {
100
113
relations : [ 'category' ] ,
101
114
where : { slug } ,
102
115
} ) ;
103
116
}
104
117
118
+ async getRelatedProductsBySlug ( slug : string ) {
119
+ const product = await this . findBySlug ( slug ) ;
120
+ return this . getRelatedProducts ( product . id ) ;
121
+ }
122
+
105
123
async update ( id : Product [ 'id' ] , changes : UpdateProductDto ) {
106
124
const product = await this . findById ( id ) ;
107
125
const images = changes . images . join ( ',' ) || product . images ;
You can’t perform that action at this time.
0 commit comments