Skip to content

Commit

Permalink
feat: 대시보드 우선순위 통계 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeonghak committed Nov 28, 2024
1 parent b3b8f3b commit cdbe644
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
4 changes: 2 additions & 2 deletions apps/server/src/image/controller/image.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export class ImageController {
@Post('presigned-url')
@ResponseMessage('Presigned URL이 성공적으로 생성되었습니다.')
async getUploadUrl(@Body() fileNameRequest: FileNameRequest) {
return await this.imageService.getUploadUrl(fileNameRequest.fileName);
return this.imageService.getUploadUrl(fileNameRequest.fileName);
}

@Get('access-url/:key')
@ResponseMessage('이미지의 접근 URL이 성공적으로 조회되었습니다.')
async getPublicUrl(@AuthUser() user: Account, @Param('key') key: string) {
return await this.imageService.getAccessUrl(user.id, key);
return this.imageService.getAccessUrl(user.id, key);
}
}
3 changes: 2 additions & 1 deletion apps/server/src/image/service/image.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { Injectable } from '@nestjs/common';
import { S3Client, PutObjectCommand, PutBucketCorsCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { v4 as uuidv4 } from 'uuid';
import { ConfigService } from '@nestjs/config';
import { UserService } from '@/account/user.service';
import { PresignedUrlResponse } from '../dto/presigned-url-response.dto';
import { AccessUrlResponse } from '../dto/access-url-response.dto';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class ImageService {
private readonly s3Client: S3Client;

private readonly bucketName = this.configService.get<string>('OBJECT_STORAGE_BUCKET_NAME');

constructor(
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/project/controller/project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,10 @@ export class ProjectController {
async getOverview(@AuthUser() user: Account, @Param('id') id: number) {
return this.taskService.getOverview(user.id, id);
}

@Get(':id/priority')
@ResponseMessage('프로젝트 우선순위 통계 조회에 성공했습니다.')
async getPriority(@AuthUser() user: Account, @Param('id') id: number) {
return this.taskService.getPriority(user.id, id);
}
}
29 changes: 26 additions & 3 deletions apps/server/src/task/service/task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,36 @@ export class TaskService {
...section,
count: parseInt(section.count, 10),
}));
const totalTasks = await this.taskRepository
const totalTasks = sections.reduce((sum, section) => sum + section.count, 0);
return { totalTasks, sections };
}

async getPriority(userId: number, projectId: number) {
await this.validateUserRole(userId, projectId);
const tasks = await this.taskRepository
.createQueryBuilder('t')
.leftJoin('section', 's', 't.section_id = s.id')
.leftJoin('project', 'p', 's.project_id = p.id')
.where('p.id = :projectId', { projectId })
.getCount();
return { totalTasks, sections };
.getMany();

const result = tasks.reduce(
(acc, task) => {
const key = task.priority ? task.priority : 0;
if (!acc[key]) {
acc[key] = 0;
}
acc[key] += 1;
return acc;
},
{} as Record<number, number>
);
const response = [];
const keyMapper = ['None', 'Lowest', 'Low', 'Medium', 'High', 'Highest'];
for (let i = 0; i <= 5; i += 1) {
response.push({ priority: keyMapper[i], count: result[i] ? result[i] : 0 });
}
return response;
}

private async validateUserRole(userId: number, projectId: number) {
Expand Down

0 comments on commit cdbe644

Please sign in to comment.