File tree Expand file tree Collapse file tree 8 files changed +48
-41
lines changed Expand file tree Collapse file tree 8 files changed +48
-41
lines changed Original file line number Diff line number Diff line change @@ -84,9 +84,11 @@ class BookClass {
84
84
modifier . slug = await generateSlug ( this , name ) ;
85
85
}
86
86
87
- await this . updateOne ( { _id : id } , { $set : modifier } ) ;
88
-
89
- const editedBook = await this . findById ( id , 'slug' ) ;
87
+ const editedBook = await this . findOneAndUpdate (
88
+ { _id : id } ,
89
+ { $set : modifier } ,
90
+ { fields : 'slug' , new : true } ,
91
+ ) ;
90
92
91
93
return editedBook ;
92
94
}
Original file line number Diff line number Diff line change @@ -84,9 +84,11 @@ class BookClass {
84
84
modifier . slug = await generateSlug ( this , name ) ;
85
85
}
86
86
87
- await this . updateOne ( { _id : id } , { $set : modifier } ) ;
88
-
89
- const editedBook = await this . findById ( id , 'slug' ) ;
87
+ const editedBook = await this . findOneAndUpdate (
88
+ { _id : id } ,
89
+ { $set : modifier } ,
90
+ { fields : 'slug' , new : true } ,
91
+ ) ;
90
92
91
93
return editedBook ;
92
94
}
Original file line number Diff line number Diff line change @@ -84,9 +84,11 @@ class BookClass {
84
84
modifier . slug = await generateSlug ( this , name ) ;
85
85
}
86
86
87
- await this . updateOne ( { _id : id } , { $set : modifier } ) ;
88
-
89
- const editedBook = await this . findById ( id , 'slug' ) ;
87
+ const editedBook = await this . findOneAndUpdate (
88
+ { _id : id } ,
89
+ { $set : modifier } ,
90
+ { fields : 'slug' , new : true } ,
91
+ ) ;
90
92
91
93
return editedBook ;
92
94
}
Original file line number Diff line number Diff line change @@ -8,10 +8,7 @@ import notify from '../../lib/notifier';
8
8
9
9
import withLayout from '../../lib/withLayout' ;
10
10
import withAuth from '../../lib/withAuth' ;
11
- import {
12
- getBookList ,
13
- } from '../../lib/api/admin' ;
14
-
11
+ import { getBookList } from '../../lib/api/admin' ;
15
12
16
13
const Index = ( { books } ) => (
17
14
< div style = { { padding : '10px 45px' } } >
@@ -22,27 +19,26 @@ const Index = ({ books }) => (
22
19
</ Link >
23
20
< p />
24
21
< ul >
25
- { books . map ( b => (
22
+ { books . map ( ( b ) => (
26
23
< li key = { b . _id } >
27
- < Link
28
- as = { `/admin/book-detail/${ b . slug } ` }
29
- href = { `/admin/book-detail?slug=${ b . slug } ` }
30
- >
24
+ < Link as = { `/admin/book-detail/${ b . slug } ` } href = { `/admin/book-detail?slug=${ b . slug } ` } >
31
25
< a > { b . name } </ a >
32
26
</ Link >
33
27
</ li >
34
- ) ) }
28
+ ) ) }
35
29
</ ul >
36
30
< br />
37
31
</ div >
38
32
</ div >
39
33
) ;
40
34
41
35
Index . propTypes = {
42
- books : PropTypes . arrayOf ( PropTypes . shape ( {
43
- name : PropTypes . string . isRequired ,
44
- slug : PropTypes . string . isRequired ,
45
- } ) ) . isRequired ,
36
+ books : PropTypes . arrayOf (
37
+ PropTypes . shape ( {
38
+ name : PropTypes . string . isRequired ,
39
+ slug : PropTypes . string . isRequired ,
40
+ } ) ,
41
+ ) . isRequired ,
46
42
} ;
47
43
48
44
class IndexWithData extends React . Component {
@@ -60,11 +56,7 @@ class IndexWithData extends React.Component {
60
56
}
61
57
62
58
render ( ) {
63
- return (
64
- < Index
65
- { ...this . state }
66
- />
67
- ) ;
59
+ return < Index { ...this . state } /> ;
68
60
}
69
61
}
70
62
Original file line number Diff line number Diff line change @@ -9,10 +9,13 @@ import withAuth from '../../lib/withAuth';
9
9
10
10
class MyBooks extends React . Component {
11
11
static propTypes = {
12
- purchasedBooks : PropTypes . arrayOf ( PropTypes . shape ( {
13
- name : PropTypes . string . isRequired ,
14
- } ) ) ,
12
+ purchasedBooks : PropTypes . arrayOf (
13
+ PropTypes . shape ( {
14
+ name : PropTypes . string . isRequired ,
15
+ } ) ,
16
+ ) ,
15
17
} ;
18
+
16
19
static defaultProps = {
17
20
purchasedBooks : [ ] ,
18
21
} ;
@@ -45,7 +48,7 @@ class MyBooks extends React.Component {
45
48
< div >
46
49
< h3 > Your books</ h3 >
47
50
< ul >
48
- { purchasedBooks . map ( book => (
51
+ { purchasedBooks . map ( ( book ) => (
49
52
< li key = { book . _id } >
50
53
< Link
51
54
as = { `/books/${ book . slug } /introduction` }
Original file line number Diff line number Diff line change @@ -97,9 +97,11 @@ class BookClass {
97
97
modifier . slug = await generateSlug ( this , name ) ;
98
98
}
99
99
100
- await this . updateOne ( { _id : id } , { $set : modifier } ) ;
101
-
102
- const editedBook = await this . findById ( id , 'slug' ) ;
100
+ const editedBook = await this . findOneAndUpdate (
101
+ { _id : id } ,
102
+ { $set : modifier } ,
103
+ { fields : 'slug' , new : true } ,
104
+ ) ;
103
105
104
106
return editedBook ;
105
107
}
Original file line number Diff line number Diff line change @@ -84,9 +84,11 @@ class BookClass {
84
84
modifier . slug = await generateSlug ( this , name ) ;
85
85
}
86
86
87
- await this . updateOne ( { _id : id } , { $set : modifier } ) ;
88
-
89
- const editedBook = await this . findById ( id , 'slug' ) ;
87
+ const editedBook = await this . findOneAndUpdate (
88
+ { _id : id } ,
89
+ { $set : modifier } ,
90
+ { fields : 'slug' , new : true } ,
91
+ ) ;
90
92
91
93
return editedBook ;
92
94
}
Original file line number Diff line number Diff line change @@ -117,9 +117,11 @@ class BookClass {
117
117
modifier . slug = await generateSlug ( this , name ) ;
118
118
}
119
119
120
- await this . updateOne ( { _id : id } , { $set : modifier } ) ;
121
-
122
- const editedBook = await this . findById ( id , 'slug' ) ;
120
+ const editedBook = await this . findOneAndUpdate (
121
+ { _id : id } ,
122
+ { $set : modifier } ,
123
+ { fields : 'slug' , new : true } ,
124
+ ) ;
123
125
124
126
return editedBook ;
125
127
}
You can’t perform that action at this time.
0 commit comments