Implementations for the various routes and their respective endpoints are described below:
Some common res
res: {
locals: {
moment: require('moment')
}
}
app.use(async function(req, res, next){
res.locals.currentUser = req.user;
if(req.user) {
try {
let user = await User.findById(req.user._id).populate('notifs', null, { isRead: false }).exec();
res.locals.notifications = user.notifs.reverse();
} catch(err) {
console.log(err.message);
}
}
res.locals.success = req.flash('success');
res.locals.error = req.flash('error');
next();
});// login user
Algo:// register new user
Algo:// get logged user
Algo:
res: {
user: UserObject <UserSchema>
}Basic Steps:
- Check for auth
- Find the user
- Update the fields
- Save it
// update user profile
Algo:
req: {
body: {
should contain new data
}
files: {
should contain files
}
}Basic Steps:
- Check for auth
- Delete it
// delete user profile (sensitive operation)
Algo:Basic Steps:
- Check for auth
- Find the user
- Populate all notification of user
- Send all the notifs data
Algo:
res: {
Notifs: [...notification]
}Basic Steps:
- Search for req items if search specified in query else send all items
// get all items
Algo:
req: {
query: {
page: Number,
search: String
}
res: {
items: ItemsObject,
current: Number,
pages: Math.ceil(count / perPage),
noMatch: String,
search: String
}
}Basic Steps:
- Check for auth
- Calls create item fn for new item
- Notify all the user who has wishlist for item in particular category
// post new item
Algo:
req: {
body: {
body of Item
}
files: {
contains the files
}
}
res: {
message: String
}Basic Steps:
- Check for auth
- Find the item
- Update the item
- Notify all the users that have chatted about this item
// edit item details (includes any edit operation update, sold, etc)
Algo:
req: {
body: {
body of Item
}
files: {
contains the files
}
}
res: {
message: String
}Basic Steps:
- Find the item
- If the user === seller then send all chats related to the item
- Else if the chats.user2 === current user then send only that chat
// send item details
Algo:
res: {
item: Founditem,
chats: [chatObject]
}Basic Steps:
- Check for auth
- Send notif to all the users who are chatting about this item
- Deleting the item
// post new item
Algo:Basic Steps:
- Check for auth
- Find the item
- Check for validity of buyer
- Change the status of item to 'INPROCESS'
- Send the confirmation notice to buyer and freeze all the chats regarding the item
// Initialize selling procedure
Algo:
req: {
body: {
email: String,
id: String
}
}Basic Steps:
- Check for auth
- Find the item
- If he/she accepts, Change the status of item to 'SOLD'
- If he/she rejects, Change the status to 'UNSOLD' and send the notice to seller about rejection and unfreeze the chat
// Initialize selling procedure
Algo:
req: {
body: {
accept: Boolean,
id: String
}
}Basic Steps:
- Check for auth
- Find the item
- Report it
- Save the item
// Report the item
Algo:Basic Steps:
- Check for auth
- Find the item
- Create a chat obj and start with initial message
- Push chat ref to item
- Save the item
// Starts the new chat
req: {
body: {
user1: id,
user2: id,
item: id
}
}
Algo:Basic Steps:
- Check for auth
- Find the chat
- Check for valid user
- Send the chat
// Report the item
Algo:
res: {
chat: chat
}Basic Steps:
- Check for auth
- Find the chat
- Check for valid user
- Push the message in chat
- Save the chat
// Sends new message
req: {
body: {
message:message
}
}
Algo:Basic Steps:
- Check for auth
- Find the user associated
- Create a new review
- Notify the user about the review
// post review for a user
Algo:
req: {
body: Content of review
}Basic Steps:
- Check for auth
- Find the user associated
- Update the review
- Notify the user about the review
// edit any review
Algo:
req: {
body: new Content of review
}Basic Steps:
- Check for auth
- Find the user associated
- Delete the review
- Notify the user about the review
// delete any review
Algo:Basic Steps:
- Check for auth
- Find the review
- Upvote it
- Save the review
// Upvotes the review
Algo:
res: {
vote: Current votes
}Basic Steps:
- Check for auth
- Find the review
- Doownvote it
- Save the review
// Downvotes the review
Algo:
res: {
vote: Current votes
}Basic Steps:
- Check for auth
- Find the review
- Report it
- Save the review
// Report the review
Algo:// figure out how to manage chats in db after any chat session