forked from dbroqua/MusicTopus
Added filter and sort on my collection
This commit is contained in:
parent
68fa736a91
commit
99d2507248
3 changed files with 94 additions and 8 deletions
|
@ -83,23 +83,48 @@ class Albums extends Pages {
|
|||
return album.save();
|
||||
}
|
||||
|
||||
static async getMyArtists(req) {
|
||||
const artists = await AlbumsModel.find(
|
||||
{
|
||||
user: req.user._id,
|
||||
},
|
||||
[],
|
||||
{
|
||||
sort: {
|
||||
artists_sort: 1,
|
||||
},
|
||||
}
|
||||
).distinct("artists_sort");
|
||||
|
||||
return artists;
|
||||
}
|
||||
|
||||
async getAll() {
|
||||
const {
|
||||
page = 1,
|
||||
limit = 4,
|
||||
sort = "artists_sort",
|
||||
order = "asc",
|
||||
artists_sort,
|
||||
} = this.req.query;
|
||||
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const where = {};
|
||||
|
||||
if (artists_sort) {
|
||||
where.artists_sort = artists_sort;
|
||||
}
|
||||
|
||||
const count = await AlbumsModel.count({
|
||||
user: this.req.user._id,
|
||||
...where,
|
||||
});
|
||||
|
||||
const rows = await AlbumsModel.find(
|
||||
{
|
||||
user: this.req.user._id,
|
||||
...where,
|
||||
},
|
||||
[],
|
||||
{
|
||||
|
@ -116,6 +141,12 @@ class Albums extends Pages {
|
|||
count,
|
||||
};
|
||||
}
|
||||
|
||||
async loadMyCollection() {
|
||||
const artists = await Albums.getMyArtists(this.req);
|
||||
|
||||
this.setPageContent("artists", artists);
|
||||
}
|
||||
}
|
||||
|
||||
export default Albums;
|
||||
|
|
|
@ -4,6 +4,7 @@ import { ensureLoggedIn } from "connect-ensure-login";
|
|||
|
||||
import Pages from "../middleware/Pages";
|
||||
import Auth from "../middleware/Auth";
|
||||
import Albums from "../middleware/Albums";
|
||||
|
||||
import render from "../libs/format";
|
||||
|
||||
|
@ -76,7 +77,9 @@ router
|
|||
.route("/ma-collection")
|
||||
.get(ensureLoggedIn("/connexion"), async (req, res, next) => {
|
||||
try {
|
||||
const page = new Pages(req, "mon-compte/ma-collection");
|
||||
const page = new Albums(req, "mon-compte/ma-collection");
|
||||
|
||||
await page.loadMyCollection();
|
||||
|
||||
render(res, page);
|
||||
} catch (err) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue