@@ -12,6 +12,7 @@ class VideoRepository implements Repository {
12
12
13
13
public async findById ( id : string ) : Promise < VideoEntity | null > {
14
14
const video = await this . videoModel . query ( ) . findById ( id ) . execute ( ) ;
15
+
15
16
return video ? VideoEntity . initialize ( video ) : null ;
16
17
}
17
18
@@ -20,28 +21,32 @@ class VideoRepository implements Repository {
20
21
. query ( )
21
22
. where ( 'userId' , userId )
22
23
. execute ( ) ;
24
+
23
25
return videos . map ( ( it ) => VideoEntity . initialize ( it ) ) ;
24
26
}
25
27
26
28
public async findAll ( ) : Promise < VideoEntity [ ] > {
27
29
const videos = await this . videoModel . query ( ) . execute ( ) ;
30
+
28
31
return videos . map ( ( it ) => VideoEntity . initialize ( it ) ) ;
29
32
}
30
33
31
34
public async create ( entity : VideoEntity ) : Promise < VideoEntity > {
32
35
const { userId, name, url, composition, previewUrl } =
33
36
entity . toNewObject ( ) ;
37
+
34
38
const item = await this . videoModel
35
39
. query ( )
36
40
. insert ( {
37
41
userId,
38
42
name,
39
- composition : composition ,
43
+ composition,
40
44
previewUrl,
41
45
url,
42
46
} )
43
47
. returning ( '*' )
44
48
. execute ( ) ;
49
+
45
50
return VideoEntity . initialize ( item ) ;
46
51
}
47
52
@@ -50,20 +55,25 @@ class VideoRepository implements Repository {
50
55
payload : UpdateVideoRequestDto ,
51
56
) : Promise < VideoEntity | null > {
52
57
const data : Partial < VideoModel > = { } ;
58
+
53
59
if ( payload . composition ) {
54
60
data . composition = payload . composition ;
55
61
data . previewUrl = payload . composition . scenes [ 0 ] ?. avatar ?. url ?? '' ;
56
62
}
63
+
57
64
if ( payload . name ) {
58
65
data . name = payload . name ;
59
66
}
67
+
60
68
if ( payload . url ) {
61
69
data . url = payload . url ;
62
70
}
71
+
63
72
const updatedItem = await this . videoModel
64
73
. query ( )
65
74
. patchAndFetchById ( id , data )
66
75
. execute ( ) ;
76
+
67
77
return updatedItem ? VideoEntity . initialize ( updatedItem ) : null ;
68
78
}
69
79
@@ -72,6 +82,7 @@ class VideoRepository implements Repository {
72
82
. query ( )
73
83
. deleteById ( id )
74
84
. execute ( ) ;
85
+
75
86
return Boolean ( numberOfDeletedRows ) ;
76
87
}
77
88
}
0 commit comments