Skip to content

Commit 47aa8fd

Browse files
authored
Merge pull request #3022 from lindapaiste/cleanup/cb
Delete unused callback on `isSlugUnique` function
2 parents a36830b + fd50239 commit 47aa8fd

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

server/models/project.js

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,20 @@ projectSchema.pre('save', function generateSlug(next) {
6363

6464
/**
6565
* Check if slug is unique for this user's projects
66+
* @return {Promise<{ isUnique: boolean; conflictingIds: string[] }>}
6667
*/
67-
projectSchema.methods.isSlugUnique = async function isSlugUnique(cb) {
68+
projectSchema.methods.isSlugUnique = async function isSlugUnique() {
6869
const project = this;
69-
const hasCallback = typeof cb === 'function';
7070

71-
try {
72-
const docsWithSlug = await project
73-
.model('Project')
74-
.find({ user: project.user, slug: project.slug }, '_id')
75-
.exec();
71+
const docsWithSlug = await project
72+
.model('Project')
73+
.find({ user: project.user, slug: project.slug }, '_id')
74+
.exec();
7675

77-
const result = {
78-
isUnique: docsWithSlug.length === 0,
79-
conflictingIds: docsWithSlug.map((d) => d._id) || []
80-
};
81-
82-
if (hasCallback) {
83-
cb(null, result);
84-
}
85-
86-
return result;
87-
} catch (err) {
88-
if (hasCallback) {
89-
cb(err, null);
90-
}
91-
92-
throw err;
93-
}
76+
return {
77+
isUnique: docsWithSlug.length === 0,
78+
conflictingIds: docsWithSlug.map((d) => d._id) || []
79+
};
9480
};
9581

9682
export default mongoose.models.Project ||

0 commit comments

Comments
 (0)