controllers and pipelines

Table of contents

controllers

from today we writing the blogs

today i learn the controllers with hitesh chaudhari sir. hitesh sir start a backend series on you tube and today we learn the end of the series and controllers. and i completed the this series

we created a const variable and just got into a asynchandler method and write get request and response on it and started a arrow function and write content into it like below

const getWatchHistory = asyncHandler (async (req, res) => {

// this is the type we write controllers

})

in this above method we write the method for writing

const user = await User.aggregate ([

{

$match: {

_id: new mongoose.Types.

ObjectId(req.user._id)

},

$lookup: {

from : "videos",

localField : "WatchHistory",

foreignField: "_id",

as: "watchHistory",

}

]

)

this is the method for the lookup to the is that available in database or not

then send the response in the write in the last

return res

.status(200)

.json(

new ApiResponse(

200,

user[0].watchHistory,

"watch history fetched successfully "

)

)

this is the response and the ApiResponse is the method that we declare in utils and we practicing the content of the controllers