@@ -64,10 +64,8 @@ const post_user = async (req = request, res = response) => {
64
64
image,
65
65
google
66
66
} ) ;
67
-
68
67
// encrypyt password
69
68
new_user . password = encrypt_pass ( password ) ;
70
-
71
69
// save db
72
70
await new_user . save ( ) ;
73
71
@@ -129,6 +127,34 @@ const put_user = async (req = request, res = response) => {
129
127
} ) ;
130
128
}
131
129
130
+ }
131
+ /**
132
+ * Handles a PATCH request for updating a user
133
+ * and returns a JSON response with a success message and an empty data object.
134
+ * @param [req] - The `req` parameter represents the request object, which contains information about
135
+ * the incoming HTTP request such as headers, query parameters, and request body.
136
+ * @param [res] - The `res` parameter is the response object that is used to send a response back to
137
+ * the client. It contains methods and properties that allow you to control the response, such as
138
+ * `json()` which is used to send a JSON response.
139
+ */
140
+ const patch_user = async ( req = reques , res = response ) => {
141
+ try {
142
+ const { _uid, ...user } = req . body ;
143
+ const user_db = await user_model . findByIdAndUpdate ( { id : _uid } , user ) ;
144
+
145
+ log ( user , user_db ) ;
146
+ res . json ( {
147
+ message : '[SUCCESS] - PATCH USER SUCCESS' ,
148
+ data : user_db
149
+ } ) ;
150
+ } catch ( error ) {
151
+ log ( error ) ;
152
+ res . status ( 500 ) . json ( {
153
+ message : '[ERROR] - PATCH USER ERROR' ,
154
+ error
155
+ } ) ;
156
+ }
157
+
132
158
}
133
159
/**
134
160
* Handles a DELETE request for deleting a
@@ -158,21 +184,6 @@ const delete_user = async (req = request, res = response) => {
158
184
} ) ;
159
185
}
160
186
}
161
- /**
162
- * Handles a PATCH request for updating a user
163
- * and returns a JSON response with a success message and an empty data object.
164
- * @param [req] - The `req` parameter represents the request object, which contains information about
165
- * the incoming HTTP request such as headers, query parameters, and request body.
166
- * @param [res] - The `res` parameter is the response object that is used to send a response back to
167
- * the client. It contains methods and properties that allow you to control the response, such as
168
- * `json()` which is used to send a JSON response.
169
- */
170
- const patch_user = ( req = reques , res = response ) => {
171
- res . json ( {
172
- message : 'PATCH - USER SUCCESS' ,
173
- data : { }
174
- } ) ;
175
- }
176
187
177
188
module . exports = {
178
189
get_users,
0 commit comments