Skip to content

Commit

Permalink
fix: clean up unused imports, add missing license header
Browse files Browse the repository at this point in the history
  • Loading branch information
makelicious committed Jan 10, 2025
1 parent 03e241f commit 3131ec3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
*/

import { Mutation as TanstackMutation } from '@tanstack/query-core'
import { hashKey, useMutation } from '@tanstack/react-query'
import { getMutationKey, getQueryKey } from '@trpc/react-query'
import { useMutation } from '@tanstack/react-query'
import { getMutationKey } from '@trpc/react-query'
import {
ActionInput,
EventDocument,
getCurrentEventState
} from '@opencrvs/commons/client'
import { ActionFormData } from '@opencrvs/commons'
import { api, queryClient, utils } from '@client/v2-events/trpc'

async function updateLocalEvent(updatedEvent: EventDocument) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import { renderHook, RenderHookResult, waitFor } from '@testing-library/react'
import React, { act, PropsWithChildren } from 'react'
import React, { PropsWithChildren } from 'react'

import { http, HttpResponse, HttpResponseResolver } from 'msw'
import { setupServer } from 'msw/node'
Expand Down
36 changes: 27 additions & 9 deletions packages/commons/src/events/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@
*/

import { ActionType } from '../ActionConfig'
import { ActionDocument } from '../ActionDocument'
import { EventDocument } from '../EventDocument'
import {
ActionDocument,
ResolvedActionDocument,
ResolvedLocation,
ResolvedUser
} from '../ActionDocument'
import { EventDocument, ResolvedEventDocument } from '../EventDocument'
import { EventIndex } from '../EventIndex'
import { EventStatus } from '../EventMetadata'

function getStatusFromActions(actions: Array<ActionDocument>) {
function getStatusFromActions(
actions: Array<ActionDocument> | Array<ResolvedActionDocument>
) {
return actions.reduce<EventStatus>((status, action) => {
if (action.type === ActionType.CREATE) {
return EventStatus.CREATED
Expand All @@ -38,19 +45,19 @@ function getStatusFromActions(actions: Array<ActionDocument>) {
}, EventStatus.CREATED)
}

function getAssignedUserFromActions(actions: Array<ActionDocument>) {
return actions.reduce<null | string>((status, action) => {
function getAssignedUserFromActions(actions: Array<ResolvedActionDocument>) {
return actions.reduce<null | ResolvedUser>((user, action) => {
if (action.type === ActionType.ASSIGN) {
return action.assignedTo
}
if (action.type === ActionType.UNASSIGN) {
return null
}
return status
return user
}, null)
}

function getData(actions: Array<ActionDocument>) {
function getData(actions: Array<ResolvedActionDocument>) {
return actions.reduce((status, action) => {
return {
...status,
Expand All @@ -59,13 +66,24 @@ function getData(actions: Array<ActionDocument>) {
}, {})
}

export function isUndeclaredDraft(event: EventDocument): boolean {
export function isUndeclaredDraft(event: ResolvedEventDocument): boolean {
return event.actions.every(
({ type, draft }) => type === ActionType.CREATE || draft
)
}

export function getCurrentEventState(event: EventDocument): EventIndex {
type ResolvedEventIndex = Omit<
EventIndex,
'createdBy' | 'updatedBy' | 'createdAtLocation' | 'assignedTo'
> & {
createdBy: ResolvedUser
updatedBy: ResolvedUser
createdAtLocation: ResolvedLocation
assignedTo: ResolvedUser | null
}
export function getCurrentEventState(
event: ResolvedEventDocument
): ResolvedEventIndex {
const creationAction = event.actions.find(
(action) => action.type === ActionType.CREATE
)
Expand Down
12 changes: 11 additions & 1 deletion packages/events/src/service/users/users.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import * as userMgntDb from '@events/storage/mongodb/user-mgnt'
/*
* 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 * as userMgntDb from '@events/storage/mongodb/user-mgnt'
import { ObjectId } from 'mongodb'

export const getUsersById = async (ids: string[]) => {
Expand Down

0 comments on commit 3131ec3

Please sign in to comment.