1
- import { Context } from ' ../context'
2
- import { getAuthId } from ' ../utils/auth'
3
- import { processUpload } from ' ../utils/upload'
4
- import { unlink } from 'fs'
5
- import { promisify } from ' util'
1
+ import { Context } from " ../context" ;
2
+ import { getAuthId } from " ../utils/auth" ;
3
+ import { processUpload } from " ../utils/upload" ;
4
+ import { unlink } from "fs" ;
5
+ import { promisify } from " util" ;
6
6
7
7
export default {
8
8
Query : {
9
9
videos : async ( _parent : any , _args : any , ctx : Context ) => {
10
- return await ctx . prisma . videos . findMany ( )
10
+ return await ctx . prisma . videos . findMany ( ) ;
11
11
} ,
12
12
video : async ( _parent : any , args : any , ctx : Context ) => {
13
13
const video = await ctx . prisma . videos . findOne ( {
14
14
where : {
15
15
id : args . id ,
16
16
} ,
17
- } )
17
+ } ) ;
18
18
19
- if ( ! video ) throw new Error ( ' Video not found' )
19
+ if ( ! video ) throw new Error ( " Video not found" ) ;
20
20
21
- return video
21
+ return video ;
22
22
} ,
23
23
} ,
24
24
25
25
Mutation : {
26
26
createVideo : async ( _parent : any , args : any , ctx : Context ) => {
27
- const userId = getAuthId ( ctx . req )
27
+ const userId = getAuthId ( ctx . req ) ;
28
28
// const userId = '7734e503-a268-4afc-938b-178b5b59a23c'
29
29
30
- const url = await processUpload ( args . data . file )
30
+ const url = await processUpload ( args . data . file ) ;
31
31
32
32
const createdVideo = await ctx . prisma . videos . create ( {
33
33
data : {
@@ -40,54 +40,58 @@ export default {
40
40
} ,
41
41
} ,
42
42
} ,
43
- } )
43
+ } ) ;
44
44
45
- return createdVideo
45
+ return createdVideo ;
46
46
} ,
47
47
48
48
updateVideo : async ( _parent : any , args : any , ctx : Context ) => {
49
- const userId = getAuthId ( ctx . req )
49
+ const userId = getAuthId ( ctx . req ) ;
50
50
51
51
const video = await ctx . prisma . videos . findOne ( {
52
52
where : {
53
53
id : args . id ,
54
54
} ,
55
- } )
55
+ } ) ;
56
56
57
- if ( ! video || video . creator !== userId ) throw new Error ( 'Video not found' )
57
+ if ( ! video || video . creator !== userId ) {
58
+ throw new Error ( "Video not found" ) ;
59
+ }
58
60
59
61
const updatedVideo = await ctx . prisma . videos . update ( {
60
62
where : {
61
63
id : args . id ,
62
64
} ,
63
65
data : args . data ,
64
- } )
66
+ } ) ;
65
67
66
- return updatedVideo
68
+ return updatedVideo ;
67
69
} ,
68
70
69
71
deleteVideo : async ( _parent : any , args : any , ctx : Context ) => {
70
- const userId = getAuthId ( ctx . req )
72
+ const userId = getAuthId ( ctx . req ) ;
71
73
72
74
const video = await ctx . prisma . videos . findOne ( {
73
75
where : {
74
76
id : args . id ,
75
77
} ,
76
- } )
78
+ } ) ;
77
79
78
- if ( ! video || video . creator !== userId ) throw new Error ( 'Video not found' )
80
+ if ( ! video || video . creator !== userId ) {
81
+ throw new Error ( "Video not found" ) ;
82
+ }
79
83
80
- const fsunlink = promisify ( unlink )
84
+ const fsunlink = promisify ( unlink ) ;
81
85
82
86
const deletedVideo = await ctx . prisma . videos . delete ( {
83
87
where : {
84
88
id : args . id ,
85
89
} ,
86
- } )
90
+ } ) ;
87
91
88
- await fsunlink ( `videos/${ deletedVideo . url } ` )
92
+ await fsunlink ( `videos/${ deletedVideo . url } ` ) ;
89
93
90
- return deletedVideo
94
+ return deletedVideo ;
91
95
} ,
92
96
} ,
93
97
@@ -97,15 +101,23 @@ export default {
97
101
where : {
98
102
id : parent . creator ,
99
103
} ,
100
- } )
104
+ } ) ;
101
105
} ,
102
106
103
107
comments : async ( parent : any , args : any , ctx : Context ) => {
104
108
return await ctx . prisma . comments . findMany ( {
105
109
where : {
106
110
video : parent . id ,
107
111
} ,
108
- } )
112
+ } ) ;
113
+ } ,
114
+
115
+ reactions : async ( parent : any , args : any , ctx : Context ) => {
116
+ return await ctx . prisma . reactions . findMany ( {
117
+ where : {
118
+ video : parent . id ,
119
+ } ,
120
+ } ) ;
109
121
} ,
110
122
} ,
111
- }
123
+ } ;
0 commit comments