Skip to content

Commit 3171bda

Browse files
andersryancjneto
authored andcommitted
Fix update widgets api to actually save to session
1 parent 38e99f0 commit 3171bda

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

api/actions/widget/update.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ export default function update(req) {
77
if (Math.random() < 0.2) {
88
reject('Oh no! Widget save fails 20% of the time. Try again.');
99
} 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+
});
2124
}
2225
}, 1500); // simulate async db write
2326
});

0 commit comments

Comments
 (0)