feat(api): create endpoint for managing hidden bands/authors
This commit is contained in:
		
							parent
							
								
									8713f442c1
								
							
						
					
					
						commit
						25af14ceea
					
				
							
								
								
									
										39
									
								
								server/api/user/me/hide.put.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								server/api/user/me/hide.put.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,39 @@ | |||||||
|  | import { HidePayload } from "~/lib/client/types/form/favSub"; | ||||||
|  | import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn"; | ||||||
|  | import { User } from "~/models/user"; | ||||||
|  | 
 | ||||||
|  | export default eventHandler(async (ev) => { | ||||||
|  | 	isLoggedIn(ev); | ||||||
|  | 	const body = await readBody<HidePayload>(ev); | ||||||
|  | 	await User.findByIdAndUpdate(ev.context.currentUser!._id, { | ||||||
|  | 		$pull: { | ||||||
|  | 			hiddenAuthors: { | ||||||
|  | 				$in: body.pull?.authors || [], | ||||||
|  | 			}, | ||||||
|  | 			hiddenBands: { | ||||||
|  | 				$in: body.pull?.bands || [], | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 	}); | ||||||
|  | 	const nu: any = await User.findByIdAndUpdate( | ||||||
|  | 		ev.context.currentUser!._id, | ||||||
|  | 		{ | ||||||
|  | 			$addToSet: { | ||||||
|  | 				hiddenAuthors: { | ||||||
|  | 					$each: body.pull?.authors || [], | ||||||
|  | 				}, | ||||||
|  | 				hiddenBands: { | ||||||
|  | 					$each: body.pull?.bands || [], | ||||||
|  | 				}, | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 		{ new: true }, | ||||||
|  | 	); | ||||||
|  | 	return { | ||||||
|  | 		success: true, | ||||||
|  | 		data: { | ||||||
|  | 			hiddenBands: nu?.hiddenBands, | ||||||
|  | 			hiddenAuthors: nu?.hiddenAuthors, | ||||||
|  | 		}, | ||||||
|  | 	}; | ||||||
|  | }); | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user