From 6b27ea130bf8c3e7446b96086f2633253cc12f14 Mon Sep 17 00:00:00 2001 From: Linda Paiste Date: Wed, 14 Feb 2024 17:01:54 -0600 Subject: [PATCH] Delete unused callback on `isSlugUnique` function. --- server/models/project.js | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/server/models/project.js b/server/models/project.js index 4dfd25aeef..89fc8bed50 100644 --- a/server/models/project.js +++ b/server/models/project.js @@ -63,34 +63,20 @@ projectSchema.pre('save', function generateSlug(next) { /** * Check if slug is unique for this user's projects + * @return {Promise<{ isUnique: boolean; conflictingIds: string[] }>} */ -projectSchema.methods.isSlugUnique = async function isSlugUnique(cb) { +projectSchema.methods.isSlugUnique = async function isSlugUnique() { const project = this; - const hasCallback = typeof cb === 'function'; - try { - const docsWithSlug = await project - .model('Project') - .find({ user: project.user, slug: project.slug }, '_id') - .exec(); + const docsWithSlug = await project + .model('Project') + .find({ user: project.user, slug: project.slug }, '_id') + .exec(); - const result = { - isUnique: docsWithSlug.length === 0, - conflictingIds: docsWithSlug.map((d) => d._id) || [] - }; - - if (hasCallback) { - cb(null, result); - } - - return result; - } catch (err) { - if (hasCallback) { - cb(err, null); - } - - throw err; - } + return { + isUnique: docsWithSlug.length === 0, + conflictingIds: docsWithSlug.map((d) => d._id) || [] + }; }; export default mongoose.models.Project ||