40 lines
981 B
TypeScript
40 lines
981 B
TypeScript
|
|
import { Injectable } from '@nestjs/common';
|
||
|
|
import { PrismaService } from '../../infrastructure/database/prisma.service';
|
||
|
|
|
||
|
|
@Injectable()
|
||
|
|
export class FilesRepository {
|
||
|
|
constructor(private readonly prisma: PrismaService) {}
|
||
|
|
|
||
|
|
async create(data: {
|
||
|
|
userId: string;
|
||
|
|
filename: string;
|
||
|
|
mimeType?: string;
|
||
|
|
storagePath: string;
|
||
|
|
objectKey: string;
|
||
|
|
bucket: string;
|
||
|
|
sizeBytes: number;
|
||
|
|
checksum?: string;
|
||
|
|
}) {
|
||
|
|
return this.prisma.uploadedFile.create({ data });
|
||
|
|
}
|
||
|
|
|
||
|
|
async findById(id: string) {
|
||
|
|
return this.prisma.uploadedFile.findUnique({ where: { id } });
|
||
|
|
}
|
||
|
|
|
||
|
|
async findByObjectKey(objectKey: string) {
|
||
|
|
return this.prisma.uploadedFile.findFirst({ where: { objectKey } });
|
||
|
|
}
|
||
|
|
|
||
|
|
async findByUserId(userId: string) {
|
||
|
|
return this.prisma.uploadedFile.findMany({
|
||
|
|
where: { userId },
|
||
|
|
orderBy: { createdAt: 'desc' },
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
async delete(id: string) {
|
||
|
|
return this.prisma.uploadedFile.delete({ where: { id } });
|
||
|
|
}
|
||
|
|
}
|