Init repo

This commit is contained in:
LeoMortari
2025-08-21 03:29:16 -03:00
commit 44a1625631
26 changed files with 6405 additions and 0 deletions

View File

@@ -0,0 +1,110 @@
import { Injectable } from '@nestjs/common';
import dayjs from 'dayjs';
import { Prisma, videos, EVideoSituation } from 'generated/prisma';
import { PrismaService } from '../prisma/prisma.service';
import { VideoResponseDto } from './dto/video-response.dto';
import { PaginatedResponse } from './dto/paginated.dto';
@Injectable()
export class VideosService {
constructor(private readonly prisma: PrismaService) {}
async list(): Promise<VideoResponseDto[]> {
const data = await this.prisma.videos.findMany({ orderBy: { id: 'desc' } });
return data.map((video) => ({
id: video.id,
title: video.title,
url: video.url,
situation: video.situation,
clips_quantity: video.clips_quantity ?? 0,
videoid: video.videoid!,
filename: video.filename || '',
datetime_download: video.datetime_download
? dayjs(video.datetime_download).format('DD/MM/YYYY HH:mm:ss')
: '',
}));
}
async listPaginated(
page: number,
perPage: number,
situation?: EVideoSituation,
): Promise<PaginatedResponse<VideoResponseDto>> {
const skip = (page - 1) * perPage;
const where = situation ? { situation } : undefined;
const [rows, total] = await Promise.all([
this.prisma.videos.findMany({
where,
orderBy: { id: 'asc' },
skip,
take: Number(perPage),
select: {
id: true,
title: true,
url: true,
situation: true,
clips_quantity: true,
videoid: true,
filename: true,
datetime_download: true,
},
}),
this.prisma.videos.count({ where }),
]);
const content: VideoResponseDto[] = rows.map((row) => ({
id: row.id,
title: row.title ?? null,
url: row.url,
situation: row.situation,
clips_quantity: row.clips_quantity ?? 0,
videoid: row.videoid ?? '',
filename: row.filename ?? '',
datetime_download: row.datetime_download ?? '',
}));
const totalPages = Math.max(1, Math.ceil(total / perPage));
return {
content,
pagination: {
page,
perPage,
total,
totalPages,
hasNext: page < totalPages,
hasPrev: page > 1,
},
};
}
async get(id: number): Promise<videos | null> {
return this.prisma.videos.findUnique({
where: { id },
});
}
async update(id: number, data: Prisma.videosUpdateInput): Promise<videos> {
return this.prisma.videos.update({
where: { id },
data,
});
}
async delete(id: number): Promise<videos> {
return this.prisma.videos.delete({
where: { id },
});
}
async listBySituation(situation: EVideoSituation): Promise<videos[]> {
return this.prisma.videos.findMany({
where: { situation },
orderBy: { id: 'desc' },
});
}
}