Skip to content

Commit e9d08b0

Browse files
committed
Remove the unnecessary async handler (in Expr5)
1 parent 77cef6f commit e9d08b0

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

controllers/genreController.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ const Genre = require("../models/genre");
22
const Book = require("../models/book");
33

44
const { body, validationResult } = require("express-validator");
5-
const asyncHandler = require("express-async-handler");
65

76
// Display list of all Genre.
8-
exports.genre_list = asyncHandler(async (req, res, next) => {
7+
exports.genre_list = async (req, res, next) => {
98
const allGenres = await Genre.find().sort({ name: 1 }).exec();
109
res.render("genre_list", {
1110
title: "Genre List",
1211
list_genres: allGenres,
1312
});
14-
});
13+
};
1514

1615
// Display detail page for a specific Genre.
17-
exports.genre_detail = asyncHandler(async (req, res, next) => {
16+
exports.genre_detail = async (req, res, next) => {
1817
// Get details of genre and all associated books (in parallel)
1918
const [genre, booksInGenre] = await Promise.all([
2019
Genre.findById(req.params.id).exec(),
@@ -32,7 +31,7 @@ exports.genre_detail = asyncHandler(async (req, res, next) => {
3231
genre,
3332
genre_books: booksInGenre,
3433
});
35-
});
34+
};
3635

3736
// Display Genre create form on GET.
3837
exports.genre_create_get = (req, res, next) => {
@@ -48,7 +47,7 @@ exports.genre_create_post = [
4847
.escape(),
4948

5049
// Process request after validation and sanitization.
51-
asyncHandler(async (req, res, next) => {
50+
async (req, res, next) => {
5251
// Extract the validation errors from a request.
5352
const errors = validationResult(req);
5453

@@ -79,11 +78,11 @@ exports.genre_create_post = [
7978
// New genre. Save and redirect to its detail page.
8079
await genre.save();
8180
res.redirect(genre.url);
82-
}),
81+
},
8382
];
8483

8584
// Display Genre delete form on GET.
86-
exports.genre_delete_get = asyncHandler(async (req, res, next) => {
85+
exports.genre_delete_get = async (req, res, next) => {
8786
// Get details of genre and all associated books (in parallel)
8887
const [genre, booksInGenre] = await Promise.all([
8988
Genre.findById(req.params.id).exec(),
@@ -99,10 +98,10 @@ exports.genre_delete_get = asyncHandler(async (req, res, next) => {
9998
genre,
10099
genre_books: booksInGenre,
101100
});
102-
});
101+
};
103102

104103
// Handle Genre delete on POST.
105-
exports.genre_delete_post = asyncHandler(async (req, res, next) => {
104+
exports.genre_delete_post = async (req, res, next) => {
106105
// Get details of genre and all associated books (in parallel)
107106
const [genre, booksInGenre] = await Promise.all([
108107
Genre.findById(req.params.id).exec(),
@@ -122,10 +121,10 @@ exports.genre_delete_post = asyncHandler(async (req, res, next) => {
122121
// Genre has no books. Delete object and redirect to the list of genres.
123122
await Genre.findByIdAndDelete(req.body.id);
124123
res.redirect("/catalog/genres");
125-
});
124+
};
126125

127126
// Display Genre update form on GET.
128-
exports.genre_update_get = asyncHandler(async (req, res, next) => {
127+
exports.genre_update_get = async (req, res, next) => {
129128
const genre = await Genre.findById(req.params.id).exec();
130129

131130
if (genre === null) {
@@ -136,7 +135,7 @@ exports.genre_update_get = asyncHandler(async (req, res, next) => {
136135
}
137136

138137
res.render("genre_form", { title: "Update Genre", genre });
139-
});
138+
};
140139

141140
// Handle Genre update on POST.
142141
exports.genre_update_post = [
@@ -147,7 +146,7 @@ exports.genre_update_post = [
147146
.escape(),
148147

149148
// Process request after validation and sanitization.
150-
asyncHandler(async (req, res, next) => {
149+
async (req, res, next) => {
151150
// Extract the validation errors from a request .
152151
const errors = validationResult(req);
153152

@@ -170,5 +169,5 @@ exports.genre_update_post = [
170169
// Data from form is valid. Update the record.
171170
await Genre.findByIdAndUpdate(req.params.id, genre);
172171
res.redirect(genre.url);
173-
}),
172+
},
174173
];

0 commit comments

Comments
 (0)