feat(api): implement band editing
This commit is contained in:
		
							parent
							
								
									9d4af2b256
								
							
						
					
					
						commit
						4ce4693e56
					
				
							
								
								
									
										29
									
								
								server/api/band/[id]/index.put.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								server/api/band/[id]/index.put.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,29 @@ | ||||
| import { messages } from "~/lib/server/constants"; | ||||
| import isAdmin from "~/lib/server/middlewareButNotReally/isAdmin"; | ||||
| import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn"; | ||||
| import { Band, IBand } from "~/models/band"; | ||||
| 
 | ||||
| export default eventHandler(async (ev) => { | ||||
| 	isAdmin(ev); | ||||
| 	const id = parseInt(getRouterParam(ev, "id")!); | ||||
| 	const body = await readBody<Partial<Omit<IBand, "_id">>>(ev); | ||||
| 	const data = await Band.findByIdAndUpdate( | ||||
| 		id, | ||||
| 		{ | ||||
| 			$set: { | ||||
| 				...body, | ||||
| 			}, | ||||
| 		}, | ||||
| 		{ new: true }, | ||||
| 	); | ||||
| 	if (!data) { | ||||
| 		throw createError({ | ||||
| 			statusCode: 404, | ||||
| 			message: messages[404], | ||||
| 		}); | ||||
| 	} | ||||
| 	return { | ||||
| 		success: true, | ||||
| 		data, | ||||
| 	}; | ||||
| }); | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user