Skip to content

Commit

Permalink
feat: order comments by latest
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoEscaleira committed Mar 19, 2024
1 parent a47fe51 commit 36501b8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/models/comment.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { User } from './user.model';
@index({ quiz: 1 })
export class Comment {
_id: Types.ObjectId;
createdAt: Date;

@prop({ required: true })
text: string;
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/comment.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class CommentResolver {
async quizComments(@Arg('quizId') quiz: string) {
try {
const comments = await CommentModel.find({ quiz }).populate('user').exec();
return comments;
return comments.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
} catch (error) {
errorHandler(error);
}
Expand Down

0 comments on commit 36501b8

Please sign in to comment.