Skip to content
Snippets Groups Projects
Commit 1f26d15f authored by Embruch, Gerd's avatar Embruch, Gerd
Browse files

added default sort

parent 02870c96
No related branches found
No related tags found
No related merge requests found
......@@ -121,7 +121,9 @@ export const getChat = async (req, res, next) => {
*/
export const getChats = async (req, res, next) => {
try {
// TODO sort chats by createdAt
const chats = await findRecords(Chat, { createdBy: global.currentUserId });
// const chats = await Chat.find({ createdBy: global.currentUserId }).sort({ 'createdAt': 1 });
return res.json({ chats });
} catch (error) {
next(error);
......
......@@ -57,6 +57,13 @@ ChatSchema.pre('save', async function (next) {
// ################################# STATICS
// ################################# QUERY HELPERS
ChatSchema.pre('find', function (next) {
// set default sort
if (typeof this.options.sort === 'undefined') {
this.options.sort = { createdAt: 1 };
}
next();
});
// ################################# INSTANCE METHODS
/**
......
......@@ -107,6 +107,13 @@ UserSchema.pre('save', async function (next) {
// UserSchema.query.byMail = function(email){
// return this.where({email: new RegExp(email, "i")})
// }
UserSchema.pre('find', function (next) {
// set default sort
if (typeof this.options.sort === 'undefined') {
this.options.sort = { username: 1 };
}
next();
});
// ################################# INSTANCE METHODS
// example method
......
......@@ -91,7 +91,6 @@ router.post('/chat', verifyAccessToken, validate(chatSchema), checkRequestedMode
* @header {authorization} Bearer [required] access token
* @return {object} list of found conversations, ordered by updated
*/
// TODO sort chats by createdAt
router.get('/chats', verifyAccessToken, getChats);
export default router;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment