@ -68,7 +68,7 @@ issueRoutes.get<Record<string, string>, IssueResultsResponse>(
return next ( {
return next ( {
status : 403 ,
status : 403 ,
message :
message :
'You do not have permission to view issues crea ted by other users',
'You do not have permission to view issues repor ted by other users',
} ) ;
} ) ;
}
}
query = query . andWhere ( 'createdBy.id = :id' , { id : req.user?.id } ) ;
query = query . andWhere ( 'createdBy.id = :id' , { id : req.user?.id } ) ;
@ -291,35 +291,41 @@ issueRoutes.post<{ issueId: string; status: string }, Issue>(
}
}
) ;
) ;
issueRoutes . delete ( '/:issueId' , async ( req , res , next ) = > {
issueRoutes . delete (
const issueRepository = getRepository ( Issue ) ;
'/:issueId' ,
isAuthenticated ( [ Permission . MANAGE_ISSUES , Permission . CREATE_ISSUES ] , {
try {
type : 'or' ,
const issue = await issueRepository . findOneOrFail ( {
} ) ,
where : { id : Number ( req . params . issueId ) } ,
async ( req , res , next ) = > {
relations : [ 'createdBy' ] ,
const issueRepository = getRepository ( Issue ) ;
} ) ;
if (
try {
! req . user ? . hasPermission ( Permission . MANAGE_ISSUES ) &&
const issue = await issueRepository . findOneOrFail ( {
( issue . createdBy . id !== req . user ? . id || issue . comments . length > 1 )
where : { id : Number ( req . params . issueId ) } ,
) {
relations : [ 'createdBy' ] ,
return next ( {
status : 401 ,
message : 'You do not have permission to delete this issue.' ,
} ) ;
} ) ;
}
await issueRepository . remove ( issue ) ;
if (
! req . user ? . hasPermission ( Permission . MANAGE_ISSUES ) &&
( issue . createdBy . id !== req . user ? . id || issue . comments . length > 1 )
) {
return next ( {
status : 401 ,
message : 'You do not have permission to delete this issue.' ,
} ) ;
}
return res . status ( 204 ) . send ( ) ;
await issueRepository . remove ( issue ) ;
} catch ( e ) {
logger . error ( 'Something went wrong deleting an issue.' , {
return res . status ( 204 ) . send ( ) ;
label : 'API' ,
} catch ( e ) {
errorMessage : e.message ,
logger . error ( 'Something went wrong deleting an issue.' , {
} ) ;
label : 'API' ,
next ( { status : 404 , message : 'Issue not found.' } ) ;
errorMessage : e.message ,
} ) ;
next ( { status : 404 , message : 'Issue not found.' } ) ;
}
}
}
} ) ;
) ;
export default issueRoutes ;
export default issueRoutes ;