Make admin can delete any note
This commit is contained in:
		
							parent
							
								
									7576569dc9
								
							
						
					
					
						commit
						faf29b768f
					
				
					 2 changed files with 10 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -21,14 +21,17 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
 | 
			
		|||
 | 
			
		||||
	// Fetch note
 | 
			
		||||
	const note = await Note.findOne({
 | 
			
		||||
		_id: noteId,
 | 
			
		||||
		userId: user._id
 | 
			
		||||
		_id: noteId
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	if (note === null) {
 | 
			
		||||
		return rej('note not found');
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!user.isAdmin && !note.userId.equals(user._id)) {
 | 
			
		||||
		return rej('access denied');
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	await deleteNote(user, note);
 | 
			
		||||
 | 
			
		||||
	res();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue