Skip to content

Commit

Permalink
Delete unused callback on isSlugUnique function.
Browse files Browse the repository at this point in the history
  • Loading branch information
lindapaiste committed Feb 14, 2024
1 parent 6cac275 commit 6b27ea1
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions server/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down

0 comments on commit 6b27ea1

Please sign in to comment.