Some changes

This commit is contained in:
Damien Broqua 2022-02-16 15:42:02 +01:00
parent 99d2507248
commit a35c8899ac
27 changed files with 200 additions and 48 deletions

View file

@ -83,18 +83,18 @@ class Albums extends Pages {
return album.save();
}
static async getMyArtists(req) {
static async getAllDistincts(field, user) {
const artists = await AlbumsModel.find(
{
user: req.user._id,
user,
},
[],
{
sort: {
artists_sort: 1,
[field]: 1,
},
}
).distinct("artists_sort");
).distinct(field);
return artists;
}
@ -106,6 +106,7 @@ class Albums extends Pages {
sort = "artists_sort",
order = "asc",
artists_sort,
format,
} = this.req.query;
const skip = (page - 1) * limit;
@ -115,6 +116,9 @@ class Albums extends Pages {
if (artists_sort) {
where.artists_sort = artists_sort;
}
if (format) {
where["formats.name"] = format;
}
const count = await AlbumsModel.count({
user: this.req.user._id,
@ -143,9 +147,17 @@ class Albums extends Pages {
}
async loadMyCollection() {
const artists = await Albums.getMyArtists(this.req);
const artists = await Albums.getAllDistincts(
"artists_sort",
this.req.user._id
);
const formats = await Albums.getAllDistincts(
"formats.name",
this.req.user._id
);
this.setPageContent("artists", artists);
this.setPageContent("formats", formats);
}
}

View file

@ -11,11 +11,18 @@ import render from "../libs/format";
// eslint-disable-next-line new-cap
const router = express.Router();
router
.route("/")
.get(ensureLoggedIn("/connexion"), (req, res) =>
res.redirect("/ma-collection")
);
router.route("/").get((req, res, next) => {
if (req.user) {
return res.redirect("/ma-collection");
}
try {
const page = new Pages(req, "home");
return render(res, page);
} catch (err) {
return next(err);
}
});
router
.route("/connexion")