mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 06:34:39 -04:00
fix: use better already-exist check in note creation
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
d856c0acb5
commit
cd26aaa86e
1 changed files with 13 additions and 7 deletions
|
@ -60,17 +60,23 @@ exports.newNote = async function (req, res, body) {
|
||||||
} else {
|
} else {
|
||||||
return req.method === 'POST' ? errors.errorForbidden(res) : errors.errorNotFound(res)
|
return req.method === 'POST' ? errors.errorForbidden(res) : errors.errorNotFound(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const count = await models.Note.count({
|
const id = await new Promise((resolve, reject) => {
|
||||||
where: {
|
models.Note.parseNoteId(noteId, (err, id) => {
|
||||||
alias: req.alias
|
if (err) {
|
||||||
|
reject(err)
|
||||||
|
} else {
|
||||||
|
resolve(id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (count > 0) {
|
})
|
||||||
|
|
||||||
|
if (id) {
|
||||||
return errors.errorConflict(res)
|
return errors.errorConflict(res)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
logger.error('Error while checking for possible duplicate: ' + err)
|
logger.error(error)
|
||||||
return errors.errorInternalError(res)
|
return errors.errorInternalError(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue