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 { env } from '$env/dynamic/private'; | ||||||
| import { ReportAddSchema } from './schema'; | 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 }) => { | export const POST = (async ({ request, url }) => { | ||||||
| 	if (env.REPORT_SECRET && url.searchParams.get('secret') !== env.REPORT_SECRET) | 	if (env.REPORT_SECRET && url.searchParams.get('secret') !== env.REPORT_SECRET) | ||||||
| 		return new Response(null, { status: 401 }); | 		return new Response(null, { status: 401 }); | ||||||
|   | |||||||
| @@ -1,15 +0,0 @@ | |||||||
| import type { PageServerLoad } from './$types'; |  | ||||||
| import { Report, Settings } from '$lib/server/database'; |  | ||||||
|  |  | ||||||
| export const load: PageServerLoad = async () => { |  | ||||||
| 	return { |  | ||||||
| 		created: Report.findAll({ where: {} }), |  | ||||||
|  |  | ||||||
| 		enabled: (await Settings.findOne({ where: { key: 'register.enabled' } }))?.value ?? true, |  | ||||||
| 		disabled_title: |  | ||||||
| 			(await Settings.findOne({ where: { key: 'register.disabled_title' } }))?.value ?? |  | ||||||
| 			'Anmeldung geschlossen', |  | ||||||
| 		disabled_details: |  | ||||||
| 			(await Settings.findOne({ where: { key: 'register.disabled_details' } }))?.value ?? '' |  | ||||||
| 	}; |  | ||||||
| }; |  | ||||||
		Reference in New Issue
	
	Block a user