add api endpoint to get all reported related to a user (#27)
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				delpoy / build-and-deploy (push) Successful in 55s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	delpoy / build-and-deploy (push) Successful in 55s
				
			This commit is contained in:
		| @@ -5,6 +5,39 @@ import { env as public_env } from '$env/dynamic/public'; | ||||
| import { env } from '$env/dynamic/private'; | ||||
| import { ReportAddSchema } from './schema'; | ||||
|  | ||||
| export const GET = async ({ url }) => { | ||||
| 	if (env.REPORT_SECRET && url.searchParams.get('secret') !== env.REPORT_SECRET) | ||||
| 		return new Response(null, { status: 401 }); | ||||
|  | ||||
| 	const user = await User.findOne({ where: { uuid: url.searchParams.get('user') ?? '' } }); | ||||
| 	if (user === null) return new Response(null, { status: 400 }); | ||||
|  | ||||
| 	const reports = { | ||||
| 		from_self: await Report.findAll({ where: { reporter_id: user.id } }).then((reports) => | ||||
| 			reports.map((report) => { | ||||
| 				return { | ||||
| 					subject: report.subject, | ||||
| 					draft: report.draft, | ||||
| 					status: report.status, | ||||
| 					url: `${url.protocol}//${url.host}${public_env.PUBLIC_BASE_PATH || ''}/report/${report.url_hash}` | ||||
| 				}; | ||||
| 			}) | ||||
| 		), | ||||
| 		to_self: await Report.findAll({ where: { reported_id: user.id } }).then((reports) => | ||||
| 			reports.map((report) => { | ||||
| 				return { | ||||
| 					subject: report.subject, | ||||
| 					draft: report.draft, | ||||
| 					status: report.status, | ||||
| 					url: `${url.protocol}//${url.host}${public_env.PUBLIC_BASE_PATH || ''}/report/${report.url_hash}` | ||||
| 				}; | ||||
| 			}) | ||||
| 		) | ||||
| 	}; | ||||
|  | ||||
| 	return new Response(JSON.stringify(reports), { status: 200 }); | ||||
| }; | ||||
|  | ||||
| export const POST = (async ({ request, url }) => { | ||||
| 	if (env.REPORT_SECRET && url.searchParams.get('secret') !== env.REPORT_SECRET) | ||||
| 		return new Response(null, { status: 401 }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user