Skip to content

Commit

Permalink
fix: 논문 정보 업데이트 api 파일 업데이트 부분 수정 (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
hynseok authored May 17, 2024
1 parent a551d9a commit 240900a
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 60 deletions.
75 changes: 45 additions & 30 deletions src/modules/students/students.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1537,22 +1537,27 @@ export class StudentsService {
(thesisFile) => thesisFile.type === ThesisFileType.PRESENTATION
)[0];

const fileUpdateData = [];
if (thesisFileUUID) {
fileUpdateData.push({
where: { id: preThesisFile.id },
data: { fileId: thesisFileUUID },
});
}
if (presentationFileUUID) {
fileUpdateData.push({
where: { id: prePPTFile.id },
data: { fileId: presentationFileUUID },
});
}

return await this.prismaService.thesisInfo.update({
where: { id: preThesisInfo.id },
data: {
title,
abstract,
thesisFiles: {
update: [
{
where: { id: preThesisFile.id },
data: { fileId: thesisFileUUID },
},
{
where: { id: prePPTFile.id },
data: { fileId: presentationFileUUID },
},
],
update: fileUpdateData,
},
},
include: {
Expand All @@ -1574,6 +1579,20 @@ export class StudentsService {
(thesisFile) => thesisFile.type === ThesisFileType.PRESENTATION
)[0];

const fileUpdateData = [];
if (thesisFileUUID) {
fileUpdateData.push({
where: { id: mainThesisFile.id },
data: { fileId: thesisFileUUID },
});
}
if (presentationFileUUID) {
fileUpdateData.push({
where: { id: mainPPTFile.id },
data: { fileId: presentationFileUUID },
});
}

const thesisInfo = await this.prismaService.$transaction(async (tx) => {
// 본심 논문 정보 업데이트
const thesisData = await tx.thesisInfo.update({
Expand All @@ -1582,16 +1601,7 @@ export class StudentsService {
title,
abstract,
thesisFiles: {
update: [
{
where: { id: mainThesisFile.id },
data: { fileId: thesisFileUUID },
},
{
where: { id: mainPPTFile.id },
data: { fileId: presentationFileUUID },
},
],
update: fileUpdateData,
},
},
include: {
Expand Down Expand Up @@ -1628,20 +1638,25 @@ export class StudentsService {
(thesisFile) => thesisFile.type === ThesisFileType.REVISION_REPORT
)[0];

const fileUpdateData = [];
if (thesisFileUUID) {
fileUpdateData.push({
where: { id: revisionThesisFile.id },
data: { fileId: thesisFileUUID },
});
}
if (revisionReportFileUUID) {
fileUpdateData.push({
where: { id: revisionReportFile.id },
data: { fileId: revisionReportFileUUID },
});
}

return await this.prismaService.thesisInfo.update({
where: { id: revisionThesisInfo.id },
data: {
thesisFiles: {
update: [
{
where: { id: revisionThesisFile.id },
data: { fileId: thesisFileUUID },
},
{
where: { id: revisionReportFile.id },
data: { fileId: revisionReportFileUUID },
},
],
update: fileUpdateData,
},
},
include: {
Expand Down
75 changes: 45 additions & 30 deletions src/modules/theses/theses.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,27 @@ export class ThesesService {
(thesisFile) => thesisFile.type === ThesisFileType.PRESENTATION
)[0];

const fileUpdateData = [];
if (thesisFileUUID) {
fileUpdateData.push({
where: { id: preThesisFile.id },
data: { fileId: thesisFileUUID },
});
}
if (presentationFileUUID) {
fileUpdateData.push({
where: { id: prePPTFile.id },
data: { fileId: presentationFileUUID },
});
}

return await this.prismaService.thesisInfo.update({
where: { id },
data: {
title,
abstract,
thesisFiles: {
update: [
{
where: { id: preThesisFile.id },
data: { fileId: thesisFileUUID },
},
{
where: { id: prePPTFile.id },
data: { fileId: presentationFileUUID },
},
],
update: fileUpdateData,
},
},
include: {
Expand All @@ -78,6 +83,20 @@ export class ThesesService {
(thesisInfo) => thesisInfo.stage === Stage.REVISION
)[0];

const fileUpdateData = [];
if (thesisFileUUID) {
fileUpdateData.push({
where: { id: mainThesisFile.id },
data: { fileId: thesisFileUUID },
});
}
if (presentationFileUUID) {
fileUpdateData.push({
where: { id: mainPPTFile.id },
data: { fileId: presentationFileUUID },
});
}

const thesisInfo = await this.prismaService.$transaction(async (tx) => {
// 본심 논문 정보 업데이트
const thesisData = tx.thesisInfo.update({
Expand All @@ -86,16 +105,7 @@ export class ThesesService {
title,
abstract,
thesisFiles: {
update: [
{
where: { id: mainThesisFile.id },
data: { fileId: thesisFileUUID },
},
{
where: { id: mainPPTFile.id },
data: { fileId: presentationFileUUID },
},
],
update: fileUpdateData,
},
},
include: {
Expand Down Expand Up @@ -139,6 +149,20 @@ export class ThesesService {
(thesisInfo) => thesisInfo.stage === Stage.MAIN
)[0];

const fileUpdateData = [];
if (thesisFileUUID) {
fileUpdateData.push({
where: { id: revisionThesisFile.id },
data: { fileId: thesisFileUUID },
});
}
if (revisionReportFileUUID) {
fileUpdateData.push({
where: { id: revisionReportFile.id },
data: { fileId: presentationFileUUID },
});
}

const [thesisInfo] = await this.prismaService.$transaction([
// 수정지시사항 논문 정보 업데이트
this.prismaService.thesisInfo.update({
Expand All @@ -147,16 +171,7 @@ export class ThesesService {
title,
abstract,
thesisFiles: {
update: [
{
where: { id: revisionThesisFile.id },
data: { fileId: thesisFileUUID },
},
{
where: { id: revisionReportFile.id },
data: { fileId: revisionReportFileUUID },
},
],
update: fileUpdateData,
},
},
include: {
Expand Down

0 comments on commit 240900a

Please sign in to comment.