working version
This commit is contained in:
parent
de05b2ccbe
commit
dec7814f1e
@ -1,118 +1,3 @@
|
|||||||
// import {
|
|
||||||
// Controller,
|
|
||||||
// Get,
|
|
||||||
// Post,
|
|
||||||
// Body,
|
|
||||||
// Param,
|
|
||||||
// Put,
|
|
||||||
// UseInterceptors,
|
|
||||||
// UploadedFile,
|
|
||||||
// ParseIntPipe,
|
|
||||||
// UseGuards,
|
|
||||||
// } from '@nestjs/common';
|
|
||||||
// import { FileInterceptor } from '@nestjs/platform-express';
|
|
||||||
// import { AdminService } from './admin.service';
|
|
||||||
// //import { CreateDocumentDto } from '../dto/create-document.dto';
|
|
||||||
// import { UpdateDocumentDto } from '../dto/update-document.dto';
|
|
||||||
// import { AdminGuard } from '../auth/admin.guard';
|
|
||||||
// import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
||||||
// import { CreateUserDto } from '../dto/create-user.dto';
|
|
||||||
// import { S3Service } from 'src/s3/s3.service';
|
|
||||||
// import { PrismaService } from 'src/prisma/prisma.service';
|
|
||||||
|
|
||||||
// @Controller('admin')
|
|
||||||
// @UseGuards(JwtAuthGuard, AdminGuard)
|
|
||||||
// export class AdminController {
|
|
||||||
// constructor(
|
|
||||||
// private readonly adminService: AdminService,
|
|
||||||
// private readonly s3Service: S3Service,
|
|
||||||
// private readonly prisma: PrismaService,
|
|
||||||
// ) {}
|
|
||||||
|
|
||||||
// @Get('documents')
|
|
||||||
// getAllDocuments() {
|
|
||||||
// return this.adminService.getAllDocuments();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Put('documents/:id')
|
|
||||||
// @UseInterceptors(FileInterceptor('file'))
|
|
||||||
// updateDocument(
|
|
||||||
// @Param('id', ParseIntPipe) id: number,
|
|
||||||
// @Body() updateDocumentDto: UpdateDocumentDto,
|
|
||||||
// @UploadedFile() file?: Express.Multer.File,
|
|
||||||
// ) {
|
|
||||||
// return this.adminService.updateDocument(id, updateDocumentDto, file);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Get('users')
|
|
||||||
// getAllUsers() {
|
|
||||||
// return this.adminService.getAllUsers();
|
|
||||||
// }
|
|
||||||
// @Post('test-document')
|
|
||||||
// async testDocumentCreation() {
|
|
||||||
// try {
|
|
||||||
// const document = await this.prisma.document.create({
|
|
||||||
// data: {
|
|
||||||
// title: 'Test Document',
|
|
||||||
// s3Key: 'test-key',
|
|
||||||
// status: 'completed',
|
|
||||||
// sharedWithId: 2, // ID of 'pero' user
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// return document;
|
|
||||||
// } catch (error) {
|
|
||||||
// console.error('Test document creation error:', error);
|
|
||||||
// throw error;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Post('users')
|
|
||||||
// async createUser(@Body() createUserDto: CreateUserDto) {
|
|
||||||
// return this.adminService.createUser(createUserDto);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Post('documents/:id/share')
|
|
||||||
// async shareDocument(
|
|
||||||
// @Param('id') id: string,
|
|
||||||
// @Body() { userId }: { userId: number },
|
|
||||||
// ) {
|
|
||||||
// return this.adminService.shareDocument(+id, userId);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Put('documents/:id/status')
|
|
||||||
// async updateDocumentStatus(
|
|
||||||
// @Param('id') id: string,
|
|
||||||
// @Body() { status }: { status: string },
|
|
||||||
// ) {
|
|
||||||
// return this.adminService.updateDocumentStatus(+id, status);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Post('documents')
|
|
||||||
// @UseInterceptors(FileInterceptor('file'))
|
|
||||||
// async uploadDocument(
|
|
||||||
// @UploadedFile() file: Express.Multer.File,
|
|
||||||
// @Body('title') title: string,
|
|
||||||
// @Body('sharedWithId') sharedWithId: number,
|
|
||||||
// @Body('uploadedById') uploadedById: number
|
|
||||||
// ) {
|
|
||||||
// const document = await this.adminService.uploadDocument(
|
|
||||||
// file,
|
|
||||||
// title,
|
|
||||||
// sharedWithId,
|
|
||||||
// uploadedById // Add this missing parameter
|
|
||||||
// );
|
|
||||||
// return document;
|
|
||||||
// }
|
|
||||||
// @Get('test-s3-connection')
|
|
||||||
// async testS3Connection() {
|
|
||||||
// const isConnected = await this.s3Service.testConnection();
|
|
||||||
// if (isConnected) {
|
|
||||||
// return { message: 'Successfully connected to S3' };
|
|
||||||
// } else {
|
|
||||||
// return { message: 'Failed to connect to S3' };
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
import {
|
import {
|
||||||
Controller,
|
Controller,
|
||||||
Get,
|
Get,
|
||||||
@ -180,6 +65,7 @@ async uploadDocument(
|
|||||||
throw new BadRequestException('sharedWithId and uploadedById must be valid numbers');
|
throw new BadRequestException('sharedWithId and uploadedById must be valid numbers');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const document = await this.adminService.uploadDocument(
|
const document = await this.adminService.uploadDocument(
|
||||||
file,
|
file,
|
||||||
title,
|
title,
|
||||||
@ -194,25 +80,6 @@ async uploadDocument(
|
|||||||
return this.adminService.getAllUsers();
|
return this.adminService.getAllUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Post('test-document')
|
|
||||||
// async testDocumentCreation() {
|
|
||||||
// try {
|
|
||||||
// const document = await this.prisma.document.create({
|
|
||||||
// data: {
|
|
||||||
// title: 'Test Document',
|
|
||||||
// s3Key: 'test-key',
|
|
||||||
// status: 'completed',
|
|
||||||
// sharedWith: {
|
|
||||||
// connect: { id: 2 } // ID of 'pero' user
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// return document;
|
|
||||||
// } catch (error) {
|
|
||||||
// console.error('Test document creation error:', error);
|
|
||||||
// throw error;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Post('users')
|
@Post('users')
|
||||||
async createUser(@Body() createUserDto: CreateUserDto) {
|
async createUser(@Body() createUserDto: CreateUserDto) {
|
||||||
|
|||||||
@ -121,7 +121,9 @@ export class AdminService {
|
|||||||
title: string,
|
title: string,
|
||||||
sharedWithId: number,
|
sharedWithId: number,
|
||||||
uploadedById: number
|
uploadedById: number
|
||||||
) {
|
)
|
||||||
|
|
||||||
|
{
|
||||||
const s3Key = await this.s3Service.uploadFile(file, 'documents');
|
const s3Key = await this.s3Service.uploadFile(file, 'documents');
|
||||||
|
|
||||||
return this.prisma.document.create({
|
return this.prisma.document.create({
|
||||||
@ -154,4 +156,5 @@ export class AdminService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -2,14 +2,17 @@ import { Injectable, Logger, NotFoundException, ForbiddenException } from '@nest
|
|||||||
import { PrismaService } from '../prisma/prisma.service';
|
import { PrismaService } from '../prisma/prisma.service';
|
||||||
import { S3Service } from '../s3/s3.service';
|
import { S3Service } from '../s3/s3.service';
|
||||||
import { Document, User, Prisma } from '@prisma/client';
|
import { Document, User, Prisma } from '@prisma/client';
|
||||||
|
import { EmailService } from '../email/email.service'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DocumentsService {
|
export class DocumentsService {
|
||||||
private readonly logger = new Logger(DocumentsService.name);
|
private readonly logger = new Logger(DocumentsService.name);
|
||||||
|
//private readonly Logger = new Logger(DocumentsService.user);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private readonly s3Service: S3Service
|
private readonly s3Service: S3Service,
|
||||||
|
private readonly emailService: EmailService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async findDocumentByS3Key(s3Key: string) {
|
async findDocumentByS3Key(s3Key: string) {
|
||||||
@ -116,5 +119,7 @@ export class DocumentsService {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
console.log(title, sharedWithId, uploadedById)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user