File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -7,17 +7,20 @@ export default function update(req) {
7
7
if ( Math . random ( ) < 0.2 ) {
8
8
reject ( 'Oh no! Widget save fails 20% of the time. Try again.' ) ;
9
9
} else {
10
- const widgets = load ( req ) ;
11
- const widget = req . body ;
12
- if ( widget . color === 'Green' ) {
13
- reject ( {
14
- color : 'We do not accept green widgets' // example server-side validation error
15
- } ) ;
16
- }
17
- if ( widget . id ) {
18
- widgets [ widget . id - 1 ] = widget ; // id is 1-based. please don't code like this in production! :-)
19
- }
20
- resolve ( widget ) ;
10
+ load ( req ) . then ( data => {
11
+ const widgets = data ;
12
+ const widget = req . body ;
13
+ if ( widget . color === 'Green' ) {
14
+ reject ( {
15
+ color : 'We do not accept green widgets' // example server-side validation error
16
+ } ) ;
17
+ }
18
+ if ( widget . id ) {
19
+ widgets [ widget . id - 1 ] = widget ; // id is 1-based. please don't code like this in production! :-)
20
+ req . session . widgets = widgets ;
21
+ }
22
+ resolve ( widget ) ;
23
+ } ) ;
21
24
}
22
25
} , 1500 ) ; // simulate async db write
23
26
} ) ;
You can’t perform that action at this time.
0 commit comments