File tree 1 file changed +10
-24
lines changed
1 file changed +10
-24
lines changed Original file line number Diff line number Diff line change @@ -63,34 +63,20 @@ projectSchema.pre('save', function generateSlug(next) {
63
63
64
64
/**
65
65
* Check if slug is unique for this user's projects
66
+ * @return {Promise<{ isUnique: boolean; conflictingIds: string[] }> }
66
67
*/
67
- projectSchema . methods . isSlugUnique = async function isSlugUnique ( cb ) {
68
+ projectSchema . methods . isSlugUnique = async function isSlugUnique ( ) {
68
69
const project = this ;
69
- const hasCallback = typeof cb === 'function' ;
70
70
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 ( ) ;
76
75
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
+ } ;
94
80
} ;
95
81
96
82
export default mongoose . models . Project ||
You can’t perform that action at this time.
0 commit comments