Skip to content

Commit

Permalink
Add sorting for GET
Browse files Browse the repository at this point in the history
  • Loading branch information
cowuake committed Oct 18, 2024
1 parent 6d40633 commit 7be37a6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/routes/mflix/movies/autohooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ const autoHooks = fp(
async listMovies(filter) {
const skip = (filter.page - 1) * filter.pageSize;
const mongoFilter = movieFiltertoMongoFilter(filter);
const docs = await movies.find(mongoFilter, { limit: filter.pageSize, skip }).toArray();
const docs = await movies
.find(mongoFilter, { limit: filter.pageSize, skip })
.sort(filter.year === undefined ? { title: 1 } : { year: 1, title: 1 })
.toArray();
const output = docs.map((doc) => ({ ...doc, id: doc._id.toString() }));
return output;
},
Expand Down

0 comments on commit 7be37a6

Please sign in to comment.