Add genres route

This commit is contained in:
jeffvli
2022-11-01 11:30:40 -07:00
parent 97486b23ee
commit 73fff64a75
9 changed files with 136 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
import { prisma } from '@lib/prisma';
import { ApiError } from '@utils/api-error';
const findManyByServer = async (options: { serverId: string }) => {
const { serverId } = options;
const genres = await prisma.genre.findMany({
include: {
_count: {
select: {
albumArtists: { where: { serverId } },
albums: { where: { serverId } },
artists: { where: { serverId } },
songs: { where: { serverId } },
},
},
},
where: {
OR: [
{ albumArtists: { some: { serverId } } },
{ albums: { some: { serverId } } },
{ artists: { some: { serverId } } },
{ songs: { some: { serverId } } },
],
},
});
if (!genres) {
throw ApiError.notFound('');
}
return genres;
};
const findMany = async () => {
const genres = await prisma.genre.findMany({
include: {
_count: {
select: {
albumArtists: true,
albums: true,
artists: true,
songs: true,
},
},
},
});
if (!genres) {
throw ApiError.notFound('');
}
return genres;
};
export const genresService = {
findMany,
findManyByServer,
};
+2
View File
@@ -2,6 +2,7 @@ import { albumArtistsService } from './album-artists.service';
import { albumsService } from './albums.service';
import { artistsService } from './artists.service';
import { authService } from './auth.service';
import { genresService } from './genres.service';
import { serversService } from './servers.service';
import { usersService } from './users.service';
@@ -10,6 +11,7 @@ export const service = {
albums: albumsService,
artists: artistsService,
auth: authService,
genres: genresService,
servers: serversService,
users: usersService,
};