@@ -2,12 +2,12 @@ import { HTTP_STATUS } from '../../shared/constants/http/http-status.js';
2
2
import { ITEM_CONSTANTS } from './person.constant.js' ;
3
3
import { validateItem } from './person.schema.js' ;
4
4
5
-
6
5
const validatePositiveInteger = ( value , fieldName = 'ID' ) => {
7
6
const parsed = parseInt ( value ) ;
8
7
if ( isNaN ( parsed ) || parsed <= 0 ) {
9
8
throw new Error ( `Invalid ${ fieldName } parameter. Must be a positive integer.` ) ;
10
9
}
10
+
11
11
return parsed ;
12
12
} ;
13
13
@@ -34,6 +34,7 @@ class Controller {
34
34
35
35
const result = await this . service . getItemById ( id ) ;
36
36
res . locals = { data : result , statusCode : HTTP_STATUS . OK } ;
37
+
37
38
return next ( ) ;
38
39
39
40
} catch ( error ) {
@@ -46,8 +47,8 @@ class Controller {
46
47
path : req . originalUrl ,
47
48
errorCode : HTTP_STATUS . BAD_REQUEST ,
48
49
timestamp : new Date ( ) . toISOString ( ) ,
49
- receivedId : req . params . id
50
- }
50
+ receivedId : req . params . id ,
51
+ } ,
51
52
} ) ;
52
53
}
53
54
@@ -73,6 +74,7 @@ class Controller {
73
74
validateItem ( req . body ) ;
74
75
const result = await this . service . createItem ( req . body ) ;
75
76
res . locals = { data : result , statusCode : HTTP_STATUS . CREATED } ;
77
+
76
78
return next ( ) ;
77
79
} catch ( error ) {
78
80
if ( error . message === ITEM_CONSTANTS . ALREADY_EXISTS ) {
@@ -81,6 +83,7 @@ class Controller {
81
83
if ( error . name === 'ValidationError' ) {
82
84
return next ( { statusCode : HTTP_STATUS . BAD_REQUEST , message : error . message } ) ;
83
85
}
86
+
84
87
return next ( error ) ;
85
88
}
86
89
} ;
@@ -92,6 +95,7 @@ class Controller {
92
95
validateItem ( req . body ) ;
93
96
const result = await this . service . updateItem ( id , req . body ) ;
94
97
res . locals = { data : result , statusCode : HTTP_STATUS . OK } ;
98
+
95
99
return next ( ) ;
96
100
97
101
} catch ( error ) {
@@ -104,8 +108,8 @@ class Controller {
104
108
path : req . originalUrl ,
105
109
errorCode : HTTP_STATUS . BAD_REQUEST ,
106
110
timestamp : new Date ( ) . toISOString ( ) ,
107
- receivedId : req . params . id
108
- }
111
+ receivedId : req . params . id ,
112
+ } ,
109
113
} ) ;
110
114
}
111
115
@@ -118,12 +122,13 @@ class Controller {
118
122
path : req . originalUrl ,
119
123
errorCode : HTTP_STATUS . NOT_FOUND ,
120
124
timestamp : new Date ( ) . toISOString ( ) ,
121
- }
125
+ } ,
122
126
} ) ;
123
127
}
124
128
if ( error . name === 'ValidationError' ) {
125
129
return next ( { statusCode : HTTP_STATUS . BAD_REQUEST , message : error . message } ) ;
126
130
}
131
+
127
132
return next ( error ) ;
128
133
}
129
134
} ;
@@ -134,6 +139,7 @@ class Controller {
134
139
135
140
const result = await this . service . deleteItem ( id ) ;
136
141
res . locals = { data : result , statusCode : HTTP_STATUS . OK } ;
142
+
137
143
return next ( ) ;
138
144
139
145
} catch ( error ) {
@@ -146,8 +152,8 @@ class Controller {
146
152
path : req . originalUrl ,
147
153
errorCode : HTTP_STATUS . BAD_REQUEST ,
148
154
timestamp : new Date ( ) . toISOString ( ) ,
149
- receivedId : req . params . id
150
- }
155
+ receivedId : req . params . id ,
156
+ } ,
151
157
} ) ;
152
158
}
153
159
@@ -160,9 +166,10 @@ class Controller {
160
166
path : req . originalUrl ,
161
167
errorCode : HTTP_STATUS . NOT_FOUND ,
162
168
timestamp : new Date ( ) . toISOString ( ) ,
163
- }
169
+ } ,
164
170
} ) ;
165
171
}
172
+
166
173
return next ( error ) ;
167
174
}
168
175
} ;
0 commit comments