admin panel redisign
This commit is contained in:
1 parent
8cbdde39c1
commit
1804bdbb99
7 files changed
+476
-210
No files matched your search
@@ -46,4 +46,6 @@ model Notification {
|
||||
userId Int
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
createdAt DateTime @default(now())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { S3Service } from '../s3/s3.service';
|
||||
import { CreateDocumentDto } from '../dto/create-document.dto';
|
||||
@@ -85,7 +85,6 @@ export class AdminService {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async getAllDocuments() {
|
||||
return this.prisma.document.findMany();
|
||||
}
|
||||
@@ -172,22 +171,91 @@ export class AdminService {
|
||||
});
|
||||
}
|
||||
|
||||
// async uploadDocument(
|
||||
// file: Express.Multer.File,
|
||||
// title: string,
|
||||
// userId: number,
|
||||
// ) {
|
||||
// try {
|
||||
// // First create document with pending status
|
||||
// const document = await this.prisma.document.create({
|
||||
// data: {
|
||||
// title,
|
||||
// authorId: userId,
|
||||
// status: 'pending',
|
||||
// s3Key: '', // Temporary empty key
|
||||
// },
|
||||
// });
|
||||
|
||||
// // Update status to uploading
|
||||
// await this.prisma.document.update({
|
||||
// where: { id: document.id },
|
||||
// data: { status: 'uploading' },
|
||||
// });
|
||||
|
||||
// // Upload to S3
|
||||
// const s3Key = await this.s3Service.uploadFile(file, 'documents');
|
||||
|
||||
// // Update document with s3Key and completed status
|
||||
// return this.prisma.document.update({
|
||||
// where: { id: document.id },
|
||||
// data: {
|
||||
// s3Key,
|
||||
// status: 'completed',
|
||||
// },
|
||||
// });
|
||||
// } catch (error) {
|
||||
// // If anything fails, update status to failed
|
||||
// const document = await this.prisma.document.findFirst({
|
||||
// where: { title, authorId: userId },
|
||||
// });
|
||||
// if (document) {
|
||||
// await this.prisma.document.update({
|
||||
// where: { id: document.id },
|
||||
// data: { status: 'failed' },
|
||||
// });
|
||||
// }
|
||||
// throw error;
|
||||
// }
|
||||
// }
|
||||
|
||||
// problem whith upload status writing to db, i will fix it later
|
||||
|
||||
async uploadDocument(
|
||||
file: Express.Multer.File,
|
||||
title: string,
|
||||
authorId: number,
|
||||
userId: number,
|
||||
) {
|
||||
const key = `documents/${Date.now()}-${file.originalname}`;
|
||||
const s3Key = await this.s3Service.uploadFile(file, key);
|
||||
let s3Key;
|
||||
try {
|
||||
// First upload to S3
|
||||
s3Key = await this.s3Service.uploadFile(file, 'documents');
|
||||
|
||||
return this.prisma.document.create({
|
||||
data: {
|
||||
title,
|
||||
s3Key,
|
||||
authorId,
|
||||
status: 'completed',
|
||||
},
|
||||
});
|
||||
// Then create document with completed status and s3Key
|
||||
const document = await this.prisma.document.create({
|
||||
data: {
|
||||
title,
|
||||
authorId: userId,
|
||||
s3Key,
|
||||
status: 'completed', // Set status to completed immediately after successful upload
|
||||
},
|
||||
});
|
||||
|
||||
return document;
|
||||
} catch (error) {
|
||||
// Create document with failed status if upload fails
|
||||
if (title && userId) {
|
||||
await this.prisma.document.create({
|
||||
data: {
|
||||
title,
|
||||
authorId: userId,
|
||||
s3Key: s3Key || '',
|
||||
status: 'failed',
|
||||
},
|
||||
});
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async getDocumentUrl(documentId: number) {
|
||||
|
||||
Reference in new issue
Block a user