Compare commits
2 Commits
59ee1fbe33
...
85aea30730
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85aea30730 | ||
|
|
da9707f3fb |
@@ -54,7 +54,7 @@ export class ClientController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
@Roles('manager')
|
@Roles('manager', 'technician', 'collector')
|
||||||
async update(
|
async update(
|
||||||
@CurrentUser() user: CurrentUserPayload,
|
@CurrentUser() user: CurrentUserPayload,
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import {
|
|||||||
UseGuards,
|
UseGuards,
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
UploadedFiles,
|
UploadedFiles,
|
||||||
|
BadRequestException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { AuthGuard } from '@nestjs/passport';
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
import { FileFieldsInterceptor } from '@nestjs/platform-express';
|
import { FileFieldsInterceptor } from '@nestjs/platform-express';
|
||||||
import { CommentService } from './comment.service';
|
import { CommentService } from './comment.service';
|
||||||
import { CreateCommentDto } from './dto/create-comment.dto';
|
|
||||||
import { Roles } from '../common/decorators/roles.decorator';
|
import { Roles } from '../common/decorators/roles.decorator';
|
||||||
import { RolesGuard } from '../common/guards/roles.guard';
|
import { RolesGuard } from '../common/guards/roles.guard';
|
||||||
import { TenantGuard } from '../common/guards/tenant.guard';
|
import { TenantGuard } from '../common/guards/tenant.guard';
|
||||||
@@ -38,14 +38,20 @@ export class CommentController {
|
|||||||
async create(
|
async create(
|
||||||
@CurrentUser() user: CurrentUserPayload,
|
@CurrentUser() user: CurrentUserPayload,
|
||||||
@Param('ticketId') ticketId: string,
|
@Param('ticketId') ticketId: string,
|
||||||
@Body() dto: CreateCommentDto,
|
@Body() body: any,
|
||||||
@UploadedFiles() files?: { files?: Express.Multer.File[] },
|
@UploadedFiles() files?: { files?: Express.Multer.File[] },
|
||||||
) {
|
) {
|
||||||
|
let content = body?.content;
|
||||||
|
if (Array.isArray(content)) content = content[0];
|
||||||
|
if (typeof content !== 'string') content = String(content ?? '');
|
||||||
|
if (!content || content.length > 50000) {
|
||||||
|
throw new BadRequestException('Content must be between 1 and 50000 characters');
|
||||||
|
}
|
||||||
return this.commentService.create(
|
return this.commentService.create(
|
||||||
user.tenantId,
|
user.tenantId,
|
||||||
ticketId,
|
ticketId,
|
||||||
user.sub,
|
user.sub,
|
||||||
dto.content,
|
content,
|
||||||
files?.files,
|
files?.files,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,19 @@
|
|||||||
import { IsString, MinLength } from 'class-validator';
|
import {
|
||||||
|
IsString,
|
||||||
|
IsOptional,
|
||||||
|
IsArray,
|
||||||
|
MinLength,
|
||||||
|
MaxLength,
|
||||||
|
} from 'class-validator';
|
||||||
|
|
||||||
export class CreateCommentDto {
|
export class CreateCommentDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@MinLength(1)
|
@MinLength(1)
|
||||||
content!: string;
|
@MaxLength(50000)
|
||||||
|
content: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
files?: string[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
import { MulterOptions } from '@nestjs/platform-express/multer/interfaces/multer-options.interface';
|
import { MulterOptions } from '@nestjs/platform-express/multer/interfaces/multer-options.interface';
|
||||||
import { diskStorage } from 'multer';
|
import { diskStorage } from 'multer';
|
||||||
import { extname } from 'path';
|
import { extname, resolve } from 'path';
|
||||||
|
import { existsSync, mkdirSync } from 'fs';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
|
|
||||||
|
const uploadDir = resolve('./uploads');
|
||||||
|
if (!existsSync(uploadDir)) mkdirSync(uploadDir, { recursive: true });
|
||||||
|
|
||||||
export const multerOptions: MulterOptions = {
|
export const multerOptions: MulterOptions = {
|
||||||
storage: diskStorage({
|
storage: diskStorage({
|
||||||
destination: (_req: Request, _file: Express.Multer.File, cb: (error: Error | null, destination: string) => void) => {
|
destination: (_req: Request, _file: Express.Multer.File, cb: (error: Error | null, destination: string) => void) => {
|
||||||
cb(null, './uploads');
|
cb(null, uploadDir);
|
||||||
},
|
},
|
||||||
filename: (_req: Request, file: Express.Multer.File, cb: (error: Error | null, filename: string) => void) => {
|
filename: (_req: Request, file: Express.Multer.File, cb: (error: Error | null, filename: string) => void) => {
|
||||||
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1e9);
|
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1e9);
|
||||||
@@ -22,7 +26,6 @@ export const multerOptions: MulterOptions = {
|
|||||||
'image/png',
|
'image/png',
|
||||||
'image/gif',
|
'image/gif',
|
||||||
'image/webp',
|
'image/webp',
|
||||||
'application/pdf',
|
|
||||||
];
|
];
|
||||||
if (allowed.includes(file.mimetype)) {
|
if (allowed.includes(file.mimetype)) {
|
||||||
cb(null, true);
|
cb(null, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user