Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events v2: only return user's own drafts as part of event #8303

Merged
merged 8 commits into from
Jan 9, 2025
22 changes: 22 additions & 0 deletions packages/events/src/drafts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

import { EventDocument } from '@opencrvs/commons/events'

export function getEventWithOnlyUserSpecificDrafts(
event: EventDocument,
userId: string
): EventDocument {
return {
...event,
actions: event.actions.filter((action) => action.data.createdBy === userId)
}
}
7 changes: 6 additions & 1 deletion packages/events/src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import { EventConfig, getUUID } from '@opencrvs/commons'
import { getIndexedEvents } from '@events/service/indexing/indexing'
import { presignFilesInEvent } from '@events/service/files'
import { getEventWithOnlyUserSpecificDrafts } from '@events/drafts'

const ContextSchema = z.object({
user: z.object({
Expand Down Expand Up @@ -110,7 +111,11 @@ export const appRouter = router({
get: publicProcedure.input(z.string()).query(async ({ input, ctx }) => {
const event = await getEventById(input)
const eventWithSignedFiles = await presignFilesInEvent(event, ctx.token)
return eventWithSignedFiles
const eventWithUserSpecificDrafts = getEventWithOnlyUserSpecificDrafts(
eventWithSignedFiles,
ctx.user.id
)
return eventWithUserSpecificDrafts
}),
delete: publicProcedure
.input(z.object({ eventId: z.string() }))
Expand Down
Loading