Show pending ISAC contributions immediately
This commit is contained in:
+29
-7
@@ -1,7 +1,8 @@
|
||||
import { json, type Handle, type HandleServerError } from '@sveltejs/kit';
|
||||
import { stringify } from 'devalue';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { getSessionUser } from '$lib/server/auth/session';
|
||||
import { DATA_MODULES, queueDataProposal, shouldModerateDataMutation, type DataModule } from '$lib/server/data-moderation';
|
||||
import { DATA_MODULES, proposalActionResult, queueDataProposal, shouldModerateDataMutation, type DataModule } from '$lib/server/data-moderation';
|
||||
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
if (event.url.pathname === '/admin' || event.url.pathname.startsWith('/admin/')) {
|
||||
@@ -22,14 +23,35 @@ export const handle: Handle = async ({ event, resolve }) => {
|
||||
}
|
||||
return new Response('Contributor mode must be enabled before submitting data changes.', { status: 403 });
|
||||
}
|
||||
const proposalId = await queueDataProposal(user, module, action, await event.request.formData());
|
||||
const target = new URL(event.url.pathname, event.url);
|
||||
target.searchParams.set('proposal', proposalId);
|
||||
const location = `${target.pathname}${target.search}`;
|
||||
const submittedForm = await event.request.formData();
|
||||
const proposal = await queueDataProposal(user, module, action, submittedForm);
|
||||
if (event.request.headers.get('accept')?.includes('application/json')) {
|
||||
return json({ type: 'redirect', status: 303, location });
|
||||
const result = proposalActionResult(module, action, Boolean(proposal.entityId), proposal.id);
|
||||
if (module === 'attributes' && action === 'save') {
|
||||
Object.assign(result, {
|
||||
savedItem: {
|
||||
id: proposal.entityId ?? proposal.draftEntityId,
|
||||
name: String(submittedForm.get('name') ?? ''),
|
||||
type: String(submittedForm.get('type') ?? ''),
|
||||
category: String(submittedForm.get('category') ?? ''),
|
||||
calculation_type: String(submittedForm.get('calculationType') ?? ''),
|
||||
unit: String(submittedForm.get('unit') ?? ''),
|
||||
active: 1,
|
||||
pending: true,
|
||||
proposalId: proposal.id,
|
||||
proposerName: user.displayName
|
||||
}
|
||||
});
|
||||
}
|
||||
return json({
|
||||
type: 'success',
|
||||
status: 200,
|
||||
data: stringify(result)
|
||||
});
|
||||
}
|
||||
return new Response(null, { status: 303, headers: { location } });
|
||||
const target = new URL(event.url.pathname, event.url);
|
||||
target.searchParams.set('proposal', proposal.id);
|
||||
return new Response(null, { status: 303, headers: { location: `${target.pathname}${target.search}` } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user