Skip to content

Commit

Permalink
refuse dupes
Browse files Browse the repository at this point in the history
  • Loading branch information
mudroljub committed Dec 12, 2024
1 parent 60967e8 commit 57e8e78
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/services/QuoteService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import Quote from '../models/Quote.js'
import { NotFoundError } from '../utils.js'

const create = async(quote, userId) => {
const existingQuote = await Quote.findOne({ text: quote.text })
if (existingQuote)
throw new Error('Quote already exists.')

const newQuote = await Quote.create({ ...quote, addedBy: userId })
return newQuote
}
Expand Down

0 comments on commit 57e8e78

Please sign in to comment.