Skip to content

Commit

Permalink
fix: moved logic to set date to prevent user from accidentally passin…
Browse files Browse the repository at this point in the history
…g it in
  • Loading branch information
evan-desu committed Sep 11, 2023
1 parent 60ec5c3 commit c54e42d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/services/submissionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,35 @@ export async function getSubmissions(filters: dbSchema.SubmissionSearchFilters =
}
}

function convertToDbSubmission(submission: gqlType.Submission):
function convertToDbSubmission(submission: gqlType.SubmissionInput):
dbSchema.Submission {
return {
...submission,
id: '',
isUnderReview: true,
isApproved: false,
isRejected: false,
createdDate: new Date().toISOString(),
updatedDate: new Date().toISOString(),
spokenLanguages: submission.spokenLanguages
.filter(lang => lang !== null) as dbSchema.SpokenLanguage[]
}
}

export const addSubmission = async (submission: gqlType.Submission):
export const addSubmission = async (submissionInput: gqlType.SubmissionInput):
Promise<dbSchema.Submission> => {
try {
const dbSubmission = convertToDbSubmission(submission)
const dbSubmission = convertToDbSubmission(submissionInput)

const submissionRef = dbInstance.collection('submissions')

const docRef = await submissionRef.add(dbSubmission)

const currentDate = new Date().toISOString()

const newSubmission: dbSchema.Submission = {
...dbSubmission,
id: docRef.id,
createdDate: currentDate,
updatedDate: currentDate
createdDate: new Date().toISOString(),
updatedDate: new Date().toISOString()
}

return newSubmission
Expand Down

0 comments on commit c54e42d

Please sign in to comment.