Skip to content

Commit 6a3bbab

Browse files
committed
improve bind on backend-javascript
1 parent 3b80a3f commit 6a3bbab

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

backend-javascript/src/modules/person/person.controller.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ import { validateItem } from './person.schema.js';
55
class Controller {
66
constructor(service) {
77
this.service = service;
8-
this.getItems = this.getItems.bind(this);
9-
this.getItemById = this.getItemById.bind(this);
10-
this.createItem = this.createItem.bind(this);
11-
this.updateItem = this.updateItem.bind(this);
12-
this.deleteItem = this.deleteItem.bind(this);
138
}
149

15-
async getItems(req, res, next) {
10+
getItems = async (req, res, next) => {
1611
try {
1712
const result = await this.service.getItems(req.query);
1813
res.locals = { data: result, statusCode: HTTP_STATUS.OK };
@@ -22,9 +17,9 @@ class Controller {
2217

2318
return next(error);
2419
}
25-
}
20+
};
2621

27-
async getItemById(req, res, next) {
22+
getItemById = async (req, res, next) => {
2823
try {
2924
const result = await this.service.getItemById(parseInt(req.params.id));
3025
res.locals = { data: result, statusCode: HTTP_STATUS.OK };
@@ -46,9 +41,9 @@ class Controller {
4641

4742
return next(error);
4843
}
49-
}
44+
};
5045

51-
async createItem(req, res, next) {
46+
createItem = async (req, res, next) => {
5247
try {
5348
validateItem(req.body);
5449
const result = await this.service.createItem(req.body);
@@ -65,9 +60,9 @@ class Controller {
6560

6661
return next(error);
6762
}
68-
}
63+
};
6964

70-
async updateItem(req, res, next) {
65+
updateItem = async (req, res, next) => {
7166
try {
7267
validateItem(req.body);
7368
const result = await this.service.updateItem(parseInt(req.params.id), req.body);
@@ -84,9 +79,9 @@ class Controller {
8479

8580
return next(error);
8681
}
87-
}
82+
};
8883

89-
async deleteItem(req, res, next) {
84+
deleteItem = async (req, res, next) => {
9085
try {
9186
const result = await this.service.deleteItem(parseInt(req.params.id));
9287
res.locals = { data: result, statusCode: HTTP_STATUS.OK };
@@ -99,7 +94,7 @@ class Controller {
9994

10095
return next(error);
10196
}
102-
}
97+
};
10398
}
10499

105100
export default Controller;

0 commit comments

Comments
 (0)