mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-08 21:10:12 +02:00
Add genres route
This commit is contained in:
@@ -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,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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user