Shows: populate genre field

This commit is contained in:
Toast 2025-02-20 19:28:50 +01:00
parent d8a3227f57
commit 0758b1ae3d

View file

@ -17,9 +17,13 @@ export class ShowsService {
let shows; let shows;
if (showsPerPage !== undefined) { if (showsPerPage !== undefined) {
const skip = (page - 1) * showsPerPage; const skip = (page - 1) * showsPerPage;
shows = await this.showModel.find().skip(skip).limit(showsPerPage); shows = await this.showModel
.find()
.skip(skip)
.limit(showsPerPage)
.populate('genres');
} else { } else {
shows = await this.showModel.find(); shows = await this.showModel.find().populate('genres');
} }
const total = await this.showModel.countDocuments(); const total = await this.showModel.countDocuments();
return { return {
@ -29,7 +33,7 @@ export class ShowsService {
} }
async findId(id: string): Promise<any> { async findId(id: string): Promise<any> {
return this.showModel.findById(id); return this.showModel.findById(id).populate('genres');
} }
async search(name: string, page: number, showsPerPage: number) { async search(name: string, page: number, showsPerPage: number) {
@ -41,9 +45,13 @@ export class ShowsService {
if (showsPerPage !== undefined) { if (showsPerPage !== undefined) {
const skip = (page - 1) * showsPerPage; const skip = (page - 1) * showsPerPage;
shows = await this.showModel.find(filter).skip(skip).limit(showsPerPage); shows = await this.showModel
.find(filter)
.skip(skip)
.limit(showsPerPage)
.populate('genres');
} else { } else {
shows = await this.showModel.find(filter); shows = await this.showModel.find(filter).populate('genres');
} }
return { return {
shows: shows, shows: shows,