2022-07-26 04:40:16 +02:00
|
|
|
import { Request, Response } from 'express';
|
2022-10-25 06:41:47 +02:00
|
|
|
import { ApiSuccess, getSuccessResponse } from '@/utils';
|
|
|
|
import { service } from '@services/index';
|
|
|
|
import { validation, TypedRequest } from '@validations/index';
|
2022-07-26 04:40:16 +02:00
|
|
|
|
2022-10-25 06:41:47 +02:00
|
|
|
const getList = async (req: Request, res: Response) => {
|
2022-07-31 00:28:30 +02:00
|
|
|
const { take, skip, serverFolderIds } = req.query;
|
2022-10-25 06:41:47 +02:00
|
|
|
const albumArtists = await service.albumArtists.findMany(req, {
|
2022-07-26 04:40:16 +02:00
|
|
|
serverFolderIds: String(serverFolderIds),
|
2022-07-31 00:28:30 +02:00
|
|
|
skip: Number(skip),
|
|
|
|
take: Number(take),
|
2022-10-25 06:41:47 +02:00
|
|
|
user: req.authUser,
|
2022-07-26 04:40:16 +02:00
|
|
|
});
|
|
|
|
|
2022-10-25 06:41:47 +02:00
|
|
|
const success = ApiSuccess.ok({
|
|
|
|
data: albumArtists.data,
|
|
|
|
paginationItems: {
|
|
|
|
skip: Number(skip),
|
|
|
|
take: Number(take),
|
|
|
|
totalEntries: albumArtists.totalEntries,
|
|
|
|
url: req.originalUrl,
|
|
|
|
},
|
|
|
|
});
|
2022-07-26 04:40:16 +02:00
|
|
|
|
2022-10-25 06:41:47 +02:00
|
|
|
return res.status(success.statusCode).json(getSuccessResponse(success));
|
|
|
|
};
|
2022-07-26 04:40:16 +02:00
|
|
|
|
2022-10-25 06:41:47 +02:00
|
|
|
const getDetail = async (
|
|
|
|
req: TypedRequest<typeof validation.albumArtists.detail>,
|
|
|
|
res: Response
|
|
|
|
) => {
|
2022-07-26 04:40:16 +02:00
|
|
|
const { id } = req.params;
|
2022-10-25 06:41:47 +02:00
|
|
|
const albumArtist = await service.albumArtists.findById({
|
|
|
|
id,
|
|
|
|
user: req.authUser,
|
2022-07-26 04:40:16 +02:00
|
|
|
});
|
2022-10-25 06:41:47 +02:00
|
|
|
|
|
|
|
const success = ApiSuccess.ok({ data: albumArtist });
|
|
|
|
return res.status(success.statusCode).json(getSuccessResponse(success));
|
2022-07-26 04:40:16 +02:00
|
|
|
};
|
|
|
|
|
2022-10-25 06:41:47 +02:00
|
|
|
export const albumArtistsController = {
|
|
|
|
getDetail,
|
|
|
|
getList,
|
|
|
|
};
|