File tree Expand file tree Collapse file tree 1 file changed +10
-24
lines changed Expand file tree Collapse file tree 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) {
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
9682export default mongoose . models . Project ||
You can’t perform that action at this time.
0 commit comments