@@ -5,9 +5,14 @@ import { User } from "../models/user.model.js";
5
5
import { uploadOnCloudinary } from "../utils/fileUploadsCloudinary.js" ;
6
6
import { ApiResponse } from "../utils/ApiResponse.js" ;
7
7
import jwt from "jsonwebtoken" ;
8
+ import mongoose from "mongoose" ;
8
9
import { toBeDeletedAvatar } from "../utils/toBeDeletedAvatar.js" ;
9
10
import { deleteCoverImage } from "../utils/deleteCoverImage.js" ;
10
11
12
+ const testFunc = asyncHandler ( async ( req , res ) => {
13
+ return res . status ( 200 ) . json ( new ApiResponse ( 201 , { } , "success full tested" ) ) ;
14
+ } ) ;
15
+
11
16
const options = {
12
17
httpOnly : true ,
13
18
secure : true ,
@@ -173,6 +178,7 @@ const loginUser = asyncHandler(async (req, res) => {
173
178
const loggedOutUser = asyncHandler ( async ( req , res ) => {
174
179
// steps to logout user
175
180
// 1. get user details from postman (as detals are mentioned in user model file)
181
+
176
182
await User . findByIdAndUpdate (
177
183
req . user . _id ,
178
184
{
@@ -191,7 +197,7 @@ const loggedOutUser = asyncHandler(async (req, res) => {
191
197
} ) ;
192
198
193
199
// another controller for user end point for frontend side to refresh the access token to get login again
194
- const refreshAccessToken = asyncHandler ( async ( req , res , next ) => {
200
+ const refreshAccessToken = asyncHandler ( async ( req , res ) => {
195
201
// 1. get user details from postman (as detals are mentioned in user model file)
196
202
// usually we get details from req.body or req.url so
197
203
const incomingRefreshToken =
@@ -233,9 +239,10 @@ const refreshAccessToken = asyncHandler(async (req, res, next) => {
233
239
}
234
240
} ) ;
235
241
236
- const changeCurrentUserPassword = asyncHandler ( async ( req , res , next ) => {
242
+ const changeCurrentUserPassword = asyncHandler ( async ( req , res ) => {
237
243
// take all required field from user (req.body)
238
244
const { oldPassword, newPassword } = req . body ;
245
+ // console.log({ oldPassword });
239
246
240
247
// bcoz user is loggedin, means midddleware had run then (req.user = user) so find the user from user._id
241
248
const user = await User . findById ( req . user . _id ) ;
@@ -248,7 +255,7 @@ const changeCurrentUserPassword = asyncHandler(async (req, res, next) => {
248
255
// change password
249
256
user . password = newPassword ;
250
257
await user . save ( { validateBeforeSave : false } ) ;
251
-
258
+ console . log ( "password changed" ) ;
252
259
return res
253
260
. status ( 200 )
254
261
. json ( new ApiResponse ( 200 , { } , "Password Changed SuccessFully !!!" ) ) ;
@@ -269,10 +276,10 @@ const getCurrentUser = asyncHandler(async (req, res, next) => {
269
276
const updateAccountDetails = asyncHandler ( async ( req , res ) => {
270
277
// take all required field from user (req.body)
271
278
const { fullName, userName, email } = req . body ;
272
- if ( ! ( userName || fullName || email ) )
279
+ if ( ! ( userName && fullName && email ) )
273
280
throw new ApiError ( 400 , "All fields are required " ) ; // 99 90 83 74 27
274
281
275
- const user = User . findByIdAndUpdate (
282
+ const user = await User . findByIdAndUpdate (
276
283
req . user . _id ,
277
284
{
278
285
$set : {
@@ -289,13 +296,14 @@ const updateAccountDetails = asyncHandler(async (req, res) => {
289
296
return res
290
297
. status ( 200 )
291
298
. json (
292
- new ApiResponse ( 200 , { user } , "Account Details Updated SuccessFully !!!" )
299
+ new ApiResponse ( 200 , user , "Account Details Updated SuccessFully !!!" )
293
300
) ;
294
301
} ) ;
295
302
296
303
const updateUserAvatar = asyncHandler ( async ( req , res ) => {
304
+ // console.log(req.file.path)
297
305
// take all required field from user (req.body)
298
- const avatarLocalpath = req . file ?. avatar ?. path ;
306
+ const avatarLocalpath = req . file ?. path ;
299
307
if ( ! avatarLocalpath ) throw new ApiError ( 404 , "Avatar file is required" ) ;
300
308
301
309
const avatar = await uploadOnCloudinary ( avatarLocalpath ) ;
@@ -312,7 +320,7 @@ const updateUserAvatar = asyncHandler(async (req, res) => {
312
320
{ new : true }
313
321
) . select ( "-password" ) ;
314
322
315
- toBeDeletedAvatar ( avatarLocalpath ) ;
323
+ // toBeDeletedAvatar(avatarLocalpath);
316
324
317
325
return res
318
326
. status ( 200 )
@@ -322,7 +330,7 @@ const updateUserAvatar = asyncHandler(async (req, res) => {
322
330
const updateCoverImage = asyncHandler ( async ( req , res ) => {
323
331
{
324
332
// take all required field from user (req.body)
325
- const coverImageLocalpath = req . file ?. coverImage ?. path ;
333
+ const coverImageLocalpath = req . file ?. path ;
326
334
if ( ! coverImageLocalpath )
327
335
throw new ApiError ( 404 , "cover Image file is missing" ) ;
328
336
@@ -339,7 +347,7 @@ const updateCoverImage = asyncHandler(async (req, res) => {
339
347
} ,
340
348
{ new : true }
341
349
) . select ( "-password" ) ;
342
- deleteCoverImage ( coverImageLocalpath ) ;
350
+ // deleteCoverImage(coverImageLocalpath);
343
351
return res
344
352
. status ( 200 )
345
353
. json ( new ApiResponse ( 200 , user , "cover Image Updated SuccessFully !!!" ) ) ;
@@ -487,6 +495,7 @@ const getUserWatchHistory = asyncHandler(async (req, res) => {
487
495
} ) ;
488
496
489
497
export {
498
+ testFunc ,
490
499
registerUser ,
491
500
loginUser ,
492
501
loggedOutUser ,
0 commit comments