From 1ff0083d0677081fa87c5653dbbb87378c666563 Mon Sep 17 00:00:00 2001 From: jeromegoh Date: Tue, 19 May 2026 11:12:11 +0900 Subject: [PATCH] feat: change return final form --- prisma/erd.svg | 2 +- src/helpers/submissions.helper.ts | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/prisma/erd.svg b/prisma/erd.svg index a7839aa..3c18a5c 100644 --- a/prisma/erd.svg +++ b/prisma/erd.svg @@ -1 +1 @@ -

cohort

project

user

cohort

user

cohort

user

user

enum:achievement

adviser

cohort

mentor

cohort

enum:type

evaluating

deadline

enum:type

section

question

fromProject

toProject

deadline

fromUser

toUser

fromProject

toProject

submission

enum:achievement

enum:status

deadline

application

submission

question

enum:targetAudienceRole

author

cohort

parentComment

author

announcement

user

announcement

voteEvent

voteEvent

enum:displayType

voteEvent

voteEvent

voteEvent

project

internalVoter

externalVoter

enum:role

conversation

DisplayType

None

None

Table

Table

Gallery

Gallery

TargetAudienceRole

Student

Student

Adviser

Adviser

Mentor

Mentor

All

All

DeadlineType

Milestone

Milestone

Evaluation

Evaluation

Feedback

Feedback

Application

Application

Other

Other

QuestionType

ShortAnswer

ShortAnswer

Paragraph

Paragraph

MultipleChoice

MultipleChoice

Checkboxes

Checkboxes

Dropdown

Dropdown

Url

Url

Date

Date

Time

Time

RichTextEditor

RichTextEditor

AchievementLevel

Vostok

Vostok

Gemini

Gemini

Apollo

Apollo

Artemis

Artemis

ApplicationStatus

Unprocessed

Unprocessed

Approved

Approved

Rejected

Rejected

MessageRole

USER

USER

ASSISTANT

ASSISTANT

User

Int

id

🗝️

String

name

String

email

String

profilePicUrl

String

githubUrl

String

linkedinUrl

String

personalSiteUrl

String

selfIntro

String

password

Int

submitterId

Cohort

DateTime

startDate

DateTime

endDate

Int

academicYear

🗝️

Student

Int

id

🗝️

String

nusnetId

String

matricNo

Adviser

Int

id

🗝️

String

nusnetId

String

matricNo

Mentor

Int

id

🗝️

Administrator

Int

id

🗝️

DateTime

startDate

DateTime

endDate

Project

Int

id

🗝️

String

name

String

teamName

AchievementLevel

achievement

String

proposalPdf

String

posterUrl

String

videoUrl

Boolean

hasDropped

Deadline

Int

id

🗝️

String

name

DateTime

createdOn

DateTime

dueBy

String

desc

DeadlineType

type

DateTime

updatedAt

Section

Int

id

🗝️

String

name

String

desc

Int

sectionNumber

Question

Int

id

🗝️

Int

questionNumber

String

question

String

desc

QuestionType

type

Boolean

isAnonymous

Option

String

option

Int

order

EvaluationRelation

Int

id

🗝️

Submission

Int

id

🗝️

Boolean

isDraft

DateTime

updatedAt

Application

String

teamName

AchievementLevel

achievement

ApplicationStatus

status

AnonymousApplicant

String

name

String

email

String

matricNo

🗝️

String

nusnetId

Answer

String

answer

Announcement

Int

id

🗝️

String

title

String

content

TargetAudienceRole

targetAudienceRole

DateTime

createdAt

DateTime

updatedAt

AnnouncementComment

Int

id

🗝️

String

content

DateTime

createdAt

DateTime

updatedAt

DateTime

deletedAt

AnnouncementReadLog

Int

id

🗝️

DateTime

createdAt

DateTime

updatedAt

VoteEvent

Int

id

🗝️

String

title

DateTime

startTime

DateTime

endTime

VoterManagement

Boolean

hasInternalList

Boolean

hasExternalList

DateTime

registrationStartTime

DateTime

registrationEndTime

VoteConfig

Int

maxVotes

Int

minVotes

Boolean

isRandomOrder

String

instructions

DisplayType

displayType

ResultsFilter

Boolean

areResultsPublished

Int

displayLimit

Boolean

showRank

Boolean

showVotes

Boolean

showPoints

Boolean

showPercentage

Int

studentWeight

Int

adviserWeight

Int

mentorWeight

Int

administratorWeight

Int

publicWeight

ExternalVoter

String

id

🗝️

Vote

Int

id

🗝️

FaqConversation

Int

id

🗝️

Int

userId

String

title

DateTime

createdAt

DateTime

updatedAt

Message

Int

id

🗝️

MessageRole

role

String

content

DateTime

createdAt

\ No newline at end of file +

cohort

project

user

cohort

user

cohort

user

user

enum:achievement

adviser

cohort

mentor

cohort

enum:type

evaluating

enum:evaluatorType

deadline

enum:type

enum:urlType

section

question

fromProject

toProject

deadline

fromUser

toUser

fromProject

toProject

submission

enum:achievement

enum:status

deadline

application

submission

question

enum:targetAudienceRole

author

cohort

parentComment

author

announcement

user

announcement

voteEvent

voteEvent

enum:displayType

voteEvent

voteEvent

voteEvent

project

internalVoter

externalVoter

enum:role

conversation

DisplayType

None

None

Table

Table

Gallery

Gallery

TargetAudienceRole

Student

Student

Adviser

Adviser

Mentor

Mentor

All

All

DeadlineType

Milestone

Milestone

Evaluation

Evaluation

Feedback

Feedback

Application

Application

Other

Other

EvaluatorType

Adviser

Adviser

Team

Team

Both

Both

QuestionType

ShortAnswer

ShortAnswer

Paragraph

Paragraph

MultipleChoice

MultipleChoice

Checkboxes

Checkboxes

Dropdown

Dropdown

Url

Url

Date

Date

Time

Time

RichTextEditor

RichTextEditor

UrlType

Generic

Generic

Image

Image

Video

Video

AchievementLevel

Vostok

Vostok

Gemini

Gemini

Apollo

Apollo

Artemis

Artemis

ApplicationStatus

Unprocessed

Unprocessed

Approved

Approved

Rejected

Rejected

MessageRole

USER

USER

ASSISTANT

ASSISTANT

User

Int

id

🗝️

String

name

String

email

String

profilePicUrl

String

githubUrl

String

linkedinUrl

String

personalSiteUrl

String

selfIntro

String

password

Int

submitterId

Cohort

DateTime

startDate

DateTime

endDate

Int

academicYear

🗝️

Student

Int

id

🗝️

String

nusnetId

String

matricNo

Adviser

Int

id

🗝️

String

nusnetId

String

matricNo

Mentor

Int

id

🗝️

Administrator

Int

id

🗝️

DateTime

startDate

DateTime

endDate

Project

Int

id

🗝️

String

name

String

teamName

AchievementLevel

achievement

String

proposalPdf

String

posterUrl

String

videoUrl

Boolean

hasDropped

Deadline

Int

id

🗝️

String

name

DateTime

createdOn

DateTime

dueBy

String

desc

DeadlineType

type

DateTime

updatedAt

EvaluatorType

evaluatorType

Section

Int

id

🗝️

String

name

String

desc

Int

sectionNumber

Question

Int

id

🗝️

Int

questionNumber

String

question

String

desc

QuestionType

type

Boolean

isAnonymous

Boolean

isRequired

UrlType

urlType

Json

urlValidationRules

Option

String

option

Int

order

EvaluationRelation

Int

id

🗝️

Submission

Int

id

🗝️

Boolean

isDraft

DateTime

updatedAt

Application

String

teamName

AchievementLevel

achievement

ApplicationStatus

status

AnonymousApplicant

String

name

String

email

String

matricNo

🗝️

String

nusnetId

Answer

String

answer

Announcement

Int

id

🗝️

String

title

String

content

TargetAudienceRole

targetAudienceRole

DateTime

createdAt

DateTime

updatedAt

AnnouncementComment

Int

id

🗝️

String

content

DateTime

createdAt

DateTime

updatedAt

DateTime

deletedAt

AnnouncementReadLog

Int

id

🗝️

DateTime

createdAt

DateTime

updatedAt

VoteEvent

Int

id

🗝️

String

title

DateTime

startTime

DateTime

endTime

VoterManagement

Boolean

hasInternalList

Boolean

hasExternalList

DateTime

registrationStartTime

DateTime

registrationEndTime

VoteConfig

Int

maxVotes

Int

minVotes

Boolean

isRandomOrder

String

instructions

DisplayType

displayType

ResultsFilter

Boolean

areResultsPublished

Int

displayLimit

Boolean

showRank

Boolean

showVotes

Boolean

showPoints

Boolean

showPercentage

Int

studentWeight

Int

adviserWeight

Int

mentorWeight

Int

administratorWeight

Int

publicWeight

ExternalVoter

String

id

🗝️

Vote

Int

id

🗝️

FaqConversation

Int

id

🗝️

Int

userId

String

title

DateTime

createdAt

DateTime

updatedAt

Message

Int

id

🗝️

MessageRole

role

String

content

DateTime

createdAt

\ No newline at end of file diff --git a/src/helpers/submissions.helper.ts b/src/helpers/submissions.helper.ts index c885c44..050d3fe 100644 --- a/src/helpers/submissions.helper.ts +++ b/src/helpers/submissions.helper.ts @@ -11,6 +11,7 @@ import { } from "../models/deadline.db"; import { createUniqueSubmission, + findFirstSubmission, findManySubmissions, findUniqueSubmission, updateUniqueSubmission, @@ -120,6 +121,20 @@ export async function createOneSubmission(body: { toProjectId, toUserId, } = submission; + const existingSubmission = await findFirstSubmission({ + where: { + deadlineId, + fromProjectId: fromProjectId ?? null, + fromUserId: fromUserId ?? null, + toProjectId: toProjectId ?? null, + toUserId: toUserId ?? null, + }, + }); + + if (existingSubmission) { + return existingSubmission; + } + const createdSubmission = await createUniqueSubmission({ data: { deadline: { connect: { id: deadlineId } }, @@ -182,7 +197,10 @@ export async function updateOneSubmissionBySubmissionId( }); } - return await findUniqueSubmission({ where: { id: submissionId } }); + return await findUniqueSubmission({ + where: { id: submissionId }, + include: { answers: true }, + }); } export async function getAnonymousAnswersViaAdviserID(adviserId: number) {