Skip to content

Commit

Permalink
[FIX] 논문실적 지도교수 관련 기능 수정 (#161)
Browse files Browse the repository at this point in the history
* chore: kafka 비활성화

* fix: 논문실적 등록시 지도교수 선택 기능 삭제

* feat: 논문실적 엑셀 다운로드시 지도교수도 함께 출력

* chore: kafka 활성화
  • Loading branch information
yesjuhee authored Dec 26, 2024
1 parent 7b570b3 commit 3d12b50
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 114 deletions.
46 changes: 20 additions & 26 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@ datasource db {

/// 사용자
model User {
id Int @id @default(autoincrement())
loginId String @unique @db.VarChar(255)
password String @db.VarChar(255)
name String @db.VarChar(255)
email String? @unique @db.VarChar(255)
phone String? @db.VarChar(255)
type UserType
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
deletedAt DateTime?
deptId Int?
signId String? @unique
headReviewProcesses Process[] @relation("headReviewer")
studentProcess Process? @relation("student")
reviews Review[]
reviewers Reviewer[]
department Department? @relation(fields: [deptId], references: [id], onDelete: SetNull)
signFile File? @relation(fields: [signId], references: [uuid])
studentAchivements Achievements[] @relation("student")
profesosr1Achivements Achievements[] @relation("professor1")
profesor2Achivements Achievements[] @relation("professor2")
id Int @id @default(autoincrement())
loginId String @unique @db.VarChar(255)
password String @db.VarChar(255)
name String @db.VarChar(255)
email String? @unique @db.VarChar(255)
phone String? @db.VarChar(255)
type UserType
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
deletedAt DateTime?
deptId Int?
signId String? @unique
headReviewProcesses Process[] @relation("headReviewer")
studentProcess Process? @relation("student")
reviews Review[]
reviewers Reviewer[]
department Department? @relation(fields: [deptId], references: [id], onDelete: SetNull)
signFile File? @relation(fields: [signId], references: [uuid])
Achievements Achievements[]
@@index([deptId], map: "user_deptId_fkey")
@@map("user")
Expand Down Expand Up @@ -169,11 +167,7 @@ model Achievements {
authorType AuthorType
authorNumbers Int
userId Int?
professorId1 Int?
professorId2 Int?
User User? @relation("student", fields: [userId], references: [id], onDelete: Cascade)
Professor1 User? @relation("professor1", fields: [professorId1], references: [id], onDelete: SetNull)
Professor2 User? @relation("professor2", fields: [professorId2], references: [id], onDelete: SetNull)
User User? @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId], map: "achievements_userId_fkey")
@@map("achievements")
Expand Down
50 changes: 21 additions & 29 deletions src/modules/achievements/achievements.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PrismaService } from "../../config/database/prisma.service";
import { CreateAchievementsDto } from "./dtos/create-achievements.dto";
import { UpdateAchievementsDto } from "./dtos/update-achievements.dto";
import { AchievementsExcelQuery, AchievementsSearchQuery } from "./dtos/achievements-query.dto";
import { AuthorType, Performance, User, UserType } from "@prisma/client";
import { AuthorType, Performance, Role, User, UserType } from "@prisma/client";
import * as XLSX from "xlsx";
import * as DateUtil from "../../common/utils/date.util";
import { Readable } from "stream";
Expand All @@ -12,7 +12,7 @@ export class AchievementsService {
constructor(private readonly prismaService: PrismaService) {}

async createAchievement(userId: number, user: User, createAchievementsDto: CreateAchievementsDto) {
const { performance, paperTitle, journalName, ISSN, publicationDate, authorType, authorNumbers, professorIds } =
const { performance, paperTitle, journalName, ISSN, publicationDate, authorType, authorNumbers } =
createAchievementsDto;

if ((user.type === UserType.STUDENT || user.type === UserType.PHD) && userId !== user.id)
Expand All @@ -24,19 +24,6 @@ export class AchievementsService {
});
if (!foundUser) throw new BadRequestException("해당 유저가 존재하지 않습니다.");

// 교수 아이디 확인
if (professorIds && professorIds.length !== 0) {
const foundProfessors = await this.prismaService.user.findMany({
where: {
id: { in: professorIds },
type: UserType.PROFESSOR,
},
});
const foundIds = foundProfessors.map((user) => user.id);
const missingIds = professorIds.filter((id) => !foundIds.includes(id));
if (missingIds.length !== 0) throw new BadRequestException(`ID:[${missingIds}]에 해당하는 교수가 없습니다.`);
}

return await this.prismaService.achievements.create({
data: {
userId,
Expand All @@ -47,8 +34,6 @@ export class AchievementsService {
publicationDate,
authorNumbers,
authorType,
professorId1: professorIds ? professorIds[0] : undefined,
professorId2: professorIds && professorIds.length == 2 ? professorIds[1] : undefined,
},
});
}
Expand All @@ -62,7 +47,7 @@ export class AchievementsService {
if (!foundUser) throw new BadRequestException("해당 논문실적은 존재하지 않습니다.");
if ((user.type === UserType.STUDENT || user.type === UserType.PHD) && foundUser.userId != user.id)
throw new BadRequestException("다른 학생의 논문실적은 수정할수 없습니다.");
const { performance, paperTitle, journalName, ISSN, publicationDate, authorType, authorNumbers, professorIds } =
const { performance, paperTitle, journalName, ISSN, publicationDate, authorType, authorNumbers } =
updateAchievementDto;
try {
return await this.prismaService.achievements.update({
Expand All @@ -77,12 +62,6 @@ export class AchievementsService {
...(publicationDate && { publicationDate }),
...(authorType && { authorType }),
...(authorNumbers && { authorNumbers }),
...(professorIds.length == 0 && { professorId1: null }),
...(professorIds.length == 0 && { professorId2: null }),
...(professorIds.length == 1 && { professorId1: professorIds[0] }),
...(professorIds.length == 1 && { professorId2: null }),
...(professorIds.length == 2 && { professorId1: professorIds[0] }),
...(professorIds.length == 2 && { professorId2: professorIds[1] }),
},
});
} catch {
Expand Down Expand Up @@ -167,31 +146,44 @@ export class AchievementsService {
User: {
include: {
department: true,
studentProcess: {
include: {
reviewers: {
include: {
reviewer: true,
},
where: {
role: Role.ADVISOR,
},
},
},
},
},
},
Professor1: true,
Professor2: true,
},
});
if (!achievements) throw new BadRequestException("검색된 논문 실적이 없습니다.");
const records = achievements.map((achievement) => {
const record = {};
const student = achievement.User;
const dept = achievement.User.department;
const advisors = student.studentProcess ? student.studentProcess.reviewers : null; // 박사과정생은 지도교수 등록되어있지 않음

record["학번"] = student.loginId;
record["이름"] = student.name;
record["학과"] = dept.name;
record["학위과정"] = achievement.User.type === UserType.STUDENT ? "석사" : "박사";
record["지도교수1"] = achievement.Professor1 ? achievement.Professor1.name : null;
record["지도교수2"] = achievement.Professor2 ? achievement.Professor2.name : null;

record["실적 구분"] = this.PerformanceToFullname(achievement.performance);
record["학술지 또는 학술대회명"] = achievement.journalName;
record["논문 제목"] = achievement.paperTitle;
(record["ISSN"] = achievement.ISSN ? achievement.ISSN : ""), (record["게재년월일"] = achievement.publicationDate);
record["주저자여부"] = this.authorToFullname(achievement.authorType);
record["저자수"] = achievement.authorNumbers;
if (advisors !== null) {
advisors.forEach((reviewerInfo, index) => {
record[`지도 교수${index + 1}`] = reviewerInfo.reviewer.name;
});
}

return record;
});
Expand Down
16 changes: 0 additions & 16 deletions src/modules/achievements/dtos/achievement.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export class AchievementDto {
this.authorNumbers = achievement.authorNumbers;
this.name = achievement.User.name;
this.department = achievement.User.department.name;
this.professorId1 = achievement.professorId1;
this.professorId2 = achievement.professorId2;
}
@ApiProperty({ description: "논문실적 id" })
id: number;
Expand Down Expand Up @@ -45,12 +43,6 @@ export class AchievementDto {

@ApiProperty({ description: "학과" })
department?: string;

@ApiProperty({ description: "지도교수1" })
professorId1: number;

@ApiProperty({ description: "지도교수2" })
professorId2: number;
}

export class CreateAchievementResponseDto {
Expand All @@ -64,8 +56,6 @@ export class CreateAchievementResponseDto {
this.authorType = achievement.authorType;
this.authorNumbers = achievement.authorNumbers;
this.userId = achievement.userId;
this.professorId1 = achievement.professorId1;
this.professorId2 = achievement.professorId2;
}
@ApiProperty({ description: "논문실적 id" })
id: number;
Expand Down Expand Up @@ -93,10 +83,4 @@ export class CreateAchievementResponseDto {

@ApiProperty({ description: "유저ID" })
userId: number;

@ApiProperty({ description: "지도교수1" })
professorId1: number;

@ApiProperty({ description: "지도교수2" })
professorId2: number;
}
22 changes: 1 addition & 21 deletions src/modules/achievements/dtos/create-achievements.dto.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
import {
ArrayMaxSize,
ArrayMinSize,
IsArray,
IsDate,
IsEnum,
IsInt,
IsNotEmpty,
IsOptional,
IsPositive,
IsString,
} from "class-validator";
import { IsDate, IsEnum, IsInt, IsNotEmpty, IsOptional, IsPositive, IsString } from "class-validator";
import { Performance } from "../../../common/enums/performance.enum";
import { Author } from "../../../common/enums/author.enum";
import { ApiProperty } from "@nestjs/swagger";
Expand Down Expand Up @@ -80,13 +69,4 @@ export class CreateAchievementsDto {
@IsInt()
@IsPositive()
authorNumbers: number;

@ApiProperty({ description: "지도교수 아이디 리스트", type: [Number], example: "[3, 4]" })
@IsArray()
@Type(() => Number)
@IsInt({ each: true })
@IsPositive({ each: true })
@ArrayMinSize(0)
@ArrayMaxSize(2)
professorIds: number[];
}
21 changes: 1 addition & 20 deletions src/modules/achievements/dtos/update-achievements.dto.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import {
ArrayMaxSize,
ArrayMinSize,
IsArray,
IsDate,
IsEnum,
IsInt,
IsOptional,
IsPositive,
IsString,
} from "class-validator";
import { IsDate, IsEnum, IsInt, IsOptional, IsPositive, IsString } from "class-validator";
import { Author } from "../../../common/enums/author.enum";
import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";
Expand Down Expand Up @@ -80,13 +70,4 @@ export class UpdateAchievementsDto {
@IsInt()
@IsPositive()
authorNumbers: number;

@ApiProperty({ description: "지도교수 아이디 리스트", type: [Number], example: "[3, 4]" })
@IsArray()
@Type(() => Number)
@IsInt({ each: true })
@IsPositive({ each: true })
@ArrayMinSize(0)
@ArrayMaxSize(2)
professorIds: number[];
}
2 changes: 1 addition & 1 deletion src/modules/professors/professors.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ProfessorsController {
summary: "교수 목록 조회",
description: "교수 목록 조회",
})
@UseUserTypeGuard([UserType.ADMIN, UserType.STUDENT, UserType.PHD])
@UseUserTypeGuard([UserType.ADMIN])
@ApiUnauthorizedResponse({ description: "[관리자] 로그인 후 접근 가능" })
@ApiInternalServerErrorResponse({ description: "서버 내부 오류" })
@ApiPaginationOKResponse({ description: "교수 목록 조회 성공", dto: ProfessorDto })
Expand Down
2 changes: 1 addition & 1 deletion src/modules/reviews/reviews.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Module } from "@nestjs/common";
import { ReviewsService } from "./reviews.service";
import { ReviewsController } from "./reviews.controller";
import { JwtStrategy } from "../auth/jwt/jwt.strategy";
import { KafkaModule } from "../../config/kafka/kafka.module";
import { KafkaModule } from "src/config/kafka/kafka.module";

@Module({
imports: [KafkaModule],
Expand Down

0 comments on commit 3d12b50

Please sign in to comment.