Skip to content

Commit 2d1ade1

Browse files
committed
refactor: clean up logging and enhance task management features
- Removed unnecessary console logs from ProjectManagementService. - Improved handling of optional properties in task updates to prevent errors. - Enhanced the upload controller to include a public decorator for better access control. - Optimized task merging logic in ProjectManagement component to ensure comments are preserved during updates. - Added loading states in TaskModal for better user experience during file uploads and task saving.
1 parent 408193f commit 2d1ade1

File tree

6 files changed

+718
-160
lines changed

6 files changed

+718
-160
lines changed

backend/src/project-management/project-management.service.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,6 @@ export class ProjectManagementService {
414414
},
415415
});
416416

417-
console.log(
418-
"[createTask] created id=",
419-
t.id,
420-
"clientId=",
421-
payload.clientId ?? null
422-
);
423-
424417
// return serialized created task (timestamps as ISO)
425418
return {
426419
...t,
@@ -462,7 +455,7 @@ export class ProjectManagementService {
462455
});
463456
if (!project) throw new NotFoundException("Project not found");
464457
}
465-
console.log(project);
458+
466459
let assignee: any = null;
467460
// validate assignee if present and not null
468461
if (
@@ -569,9 +562,11 @@ export class ProjectManagementService {
569562
}
570563

571564
if (assigneeId !== data.assigneeId) {
572-
emailTitle = `👤 Task Assignee has Changed to ${assignee.name ?? "none"}`;
565+
emailTitle = `👤 Task Assignee has Changed to ${
566+
assignee?.name ?? "none"
567+
}`;
573568
emailDescription = `👤 A task Assignee has been changed to ${
574-
assignee.name ?? "none"
569+
assignee?.name ?? "none"
575570
} on <strong>${projectName}</strong>.`;
576571
}
577572

@@ -584,11 +579,11 @@ export class ProjectManagementService {
584579
Description:
585580
${updated.description ?? "No description"}
586581
587-
Status: ${updated.status}
588-
Assignee: ${assignee.name ?? "none"}
589-
Priority: ${updated.priority ?? "none"}
590-
Start Date: ${format(updated.startDate)}
591-
Due Date: ${format(updated.dueDate)}
582+
Status: ${updated?.status}
583+
Assignee: ${assignee?.name ?? "none"}
584+
Priority: ${updated?.priority ?? "none"}
585+
Start Date: ${format(updated?.startDate)}
586+
Due Date: ${format(updated?.dueDate)}
592587
593588
Project:
594589
${projectName}
@@ -623,22 +618,22 @@ export class ProjectManagementService {
623618
624619
<p style="margin:0 0 14px; font-size:15px;">
625620
<strong style="color:#2b6cb0;">Status:</strong> ${
626-
updated.status
621+
updated?.status
627622
}<br>
628623
<strong style="color:#2b6cb0;">Assignee:</strong> ${
629-
assignee.name ?? "none"
624+
assignee?.name ?? "none"
630625
}<br>
631626
<strong style="color:#2b6cb0;">Priority:</strong> ${
632-
updated.priority ?? "none"
627+
updated?.priority ?? "none"
633628
}
634629
</p>
635630
636631
<p style="margin:0 0 14px; font-size:15px;">
637632
<strong style="color:#2b6cb0;">Start Date:</strong> ${format(
638-
updated.startDate
633+
updated?.startDate
639634
)}<br>
640635
<strong style="color:#2b6cb0;">Due Date:</strong> ${format(
641-
updated.dueDate
636+
updated?.dueDate
642637
)}
643638
</p>
644639
@@ -667,7 +662,6 @@ export class ProjectManagementService {
667662
</div>
668663
`;
669664

670-
console.log(textMsg);
671665
// KIRIM EMAIL
672666
for (const recipient of toEmails) {
673667
await this.email.sendMail({
@@ -1330,7 +1324,7 @@ export class ProjectManagementService {
13301324
include: { assignee: true },
13311325
orderBy: { createdAt: "desc" },
13321326
});
1333-
console.log(tasks);
1327+
13341328
const team = await prisma.teamMember.findMany({
13351329
where: { isTrash: false },
13361330
orderBy: { name: "asc" },
Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,65 @@
11
// src/upload/upload.controller.ts
22
import {
3-
Controller,
4-
Post,
5-
UseInterceptors,
6-
UploadedFiles,
7-
Body,
8-
BadRequestException,
9-
HttpCode,
10-
HttpStatus,
11-
} from '@nestjs/common';
12-
import { FilesInterceptor } from '@nestjs/platform-express';
13-
import { UploadService } from './upload.service';
14-
import multer from 'multer';
3+
Controller,
4+
Post,
5+
UseInterceptors,
6+
UploadedFiles,
7+
Body,
8+
BadRequestException,
9+
HttpCode,
10+
HttpStatus,
11+
} from "@nestjs/common";
12+
import { FilesInterceptor } from "@nestjs/platform-express";
13+
import { UploadService } from "./upload.service";
14+
import multer from "multer";
15+
import { Public } from "src/auth/public.decorator";
1516

16-
@Controller('upload')
17+
@Controller("upload")
1718
export class UploadController {
18-
constructor(private readonly uploadService: UploadService) { }
19+
constructor(private readonly uploadService: UploadService) {}
1920

20-
/**
21-
* POST /upload
22-
* multipart form:
23-
* - file: single or multiple files (use input name "file")
24-
* - folder: optional form field for prefix
25-
*
26-
* Response:
27-
* { success: true, uploaded: [ { key, url }, ... ] }
28-
*/
29-
@Post()
30-
@HttpCode(HttpStatus.OK)
31-
@UseInterceptors(
32-
FilesInterceptor('file', 20, {
33-
storage: multer.memoryStorage(),
34-
limits: { fileSize: 50 * 1024 * 1024 }, // max 50MB per file (tweak as needed)
35-
}),
36-
)
37-
async uploadFiles(@UploadedFiles() files: Express.Multer.File[], @Body('folder') folder?: string) {
38-
if (!files || files.length === 0) {
39-
throw new BadRequestException('No file provided. Use field name "file" in multipart form.');
40-
}
21+
/**
22+
* POST /upload
23+
* multipart form:
24+
* - file: single or multiple files (use input name "file")
25+
* - folder: optional form field for prefix
26+
*
27+
* Response:
28+
* { success: true, uploaded: [ { key, url }, ... ] }
29+
*/
30+
@Public()
31+
@Post()
32+
@HttpCode(HttpStatus.OK)
33+
@UseInterceptors(
34+
FilesInterceptor("file", 20, {
35+
storage: multer.memoryStorage(),
36+
limits: { fileSize: 50 * 1024 * 1024 }, // max 50MB per file (tweak as needed)
37+
})
38+
)
39+
async uploadFiles(
40+
@UploadedFiles() files: Express.Multer.File[],
41+
@Body("folder") folder?: string
42+
) {
43+
if (!files || files.length === 0) {
44+
throw new BadRequestException(
45+
'No file provided. Use field name "file" in multipart form.'
46+
);
47+
}
4148

42-
// sanitize folder - disallow leading ../ for safety
43-
const safeFolder = folder ? folder.replace(/\.\.+/g, '').replace(/^\/+/, '') : '';
49+
// sanitize folder - disallow leading ../ for safety
50+
const safeFolder = folder
51+
? folder.replace(/\.\.+/g, "").replace(/^\/+/, "")
52+
: "";
4453

45-
const uploaded = await this.uploadService.uploadMultipleFiles(files, safeFolder);
54+
const uploaded = await this.uploadService.uploadMultipleFiles(
55+
files,
56+
safeFolder
57+
);
4658

47-
return {
48-
success: true,
49-
count: uploaded.length,
50-
uploaded,
51-
};
52-
}
59+
return {
60+
success: true,
61+
count: uploaded.length,
62+
uploaded,
63+
};
64+
}
5365
}

0 commit comments

Comments
 (0)