diff --git a/packages/commons/src/events/ActionDocument.ts b/packages/commons/src/events/ActionDocument.ts index 2062fc6dd1..576f5ae17f 100644 --- a/packages/commons/src/events/ActionDocument.ts +++ b/packages/commons/src/events/ActionDocument.ts @@ -14,6 +14,7 @@ import { z } from 'zod' const ActionBase = z.object({ createdAt: z.string().datetime(), createdBy: z.string(), + createdAtLocation: z.string(), data: z.record(z.string(), z.any()) }) @@ -60,15 +61,13 @@ const DraftAction = ActionBase.merge( const CreatedAction = ActionBase.merge( z.object({ - type: z.literal(ActionType.CREATE), - createdAtLocation: z.string() + type: z.literal(ActionType.CREATE) }) ) const NotifiedAction = ActionBase.merge( z.object({ - type: z.literal(ActionType.NOTIFY), - createdAtLocation: z.string() + type: z.literal(ActionType.NOTIFY) }) ) diff --git a/packages/events/src/router/router.ts b/packages/events/src/router/router.ts index aa98ccdc6a..d54a593745 100644 --- a/packages/events/src/router/router.ts +++ b/packages/events/src/router/router.ts @@ -112,19 +112,22 @@ export const appRouter = router({ notify: publicProcedure.input(NotifyActionInput).mutation((options) => { return addAction(options.input, { eventId: options.input.eventId, - createdBy: options.ctx.user.id + createdBy: options.ctx.user.id, + createdAtLocation: options.ctx.user.primaryOfficeId }) }), draft: publicProcedure.input(DraftActionInput).mutation((options) => { return addAction(options.input, { eventId: options.input.eventId, - createdBy: options.ctx.user.id + createdBy: options.ctx.user.id, + createdAtLocation: options.ctx.user.primaryOfficeId }) }), declare: publicProcedure.input(DeclareActionInput).mutation((options) => { return addAction(options.input, { eventId: options.input.eventId, - createdBy: options.ctx.user.id + createdBy: options.ctx.user.id, + createdAtLocation: options.ctx.user.primaryOfficeId }) }), register: publicProcedure @@ -140,7 +143,8 @@ export const appRouter = router({ }, { eventId: options.input.eventId, - createdBy: options.ctx.user.id + createdBy: options.ctx.user.id, + createdAtLocation: options.ctx.user.primaryOfficeId } ) }) diff --git a/packages/events/src/service/events.ts b/packages/events/src/service/events.ts index 537fc664a5..d3dc867240 100644 --- a/packages/events/src/service/events.ts +++ b/packages/events/src/service/events.ts @@ -101,7 +101,11 @@ export async function createEvent({ export async function addAction( input: ActionInput, - { eventId, createdBy }: { eventId: string; createdBy: string } + { + eventId, + createdBy, + createdAtLocation + }: { eventId: string; createdBy: string; createdAtLocation: string } ) { const db = await getClient() const now = new Date().toISOString() @@ -115,7 +119,8 @@ export async function addAction( actions: { ...input, createdBy, - createdAt: now + createdAt: now, + createdAtLocation } } } diff --git a/packages/gateway/src/graphql/config.ts b/packages/gateway/src/graphql/config.ts index 254f568f9a..f3f51b95a7 100644 --- a/packages/gateway/src/graphql/config.ts +++ b/packages/gateway/src/graphql/config.ts @@ -18,8 +18,6 @@ import { } from 'graphql' import { ApolloServerOptions } from '@apollo/server' -import { resolvers as eventsV2Resolvers } from '@gateway/v2-events/events/root-resolvers' -import { eventResolvers as eventsV2TypeResolvers } from '@gateway/v2-events/events/type-resolvers' import { resolvers as bookmarkAdvancedSearchResolvers } from '@gateway/features/bookmarkAdvancedSearch/root-resolvers' import { resolvers as correctionRootResolvers } from '@gateway/features/correction/root-resolvers' import { resolvers as locationRootResolvers } from '@gateway/features/location/root-resolvers' @@ -61,8 +59,6 @@ interface IStringIndexSignatureInterface { type StringIndexed = T & IStringIndexSignatureInterface export const resolvers: StringIndexed = merge( - eventsV2Resolvers, - eventsV2TypeResolvers, notificationRootResolvers as IResolvers, registrationRootResolvers as IResolvers, locationRootResolvers as IResolvers, diff --git a/packages/gateway/src/graphql/index.graphql b/packages/gateway/src/graphql/index.graphql index 4b9c623f48..f9f8634bfd 100644 --- a/packages/gateway/src/graphql/index.graphql +++ b/packages/gateway/src/graphql/index.graphql @@ -19,8 +19,6 @@ # import Mutation.* from '../features/systems/schema.graphql' # import Query.* from '../features/systems/schema.graphql' # import Mutation from '../features/bookmarkAdvancedSearch/schema.graphql' -# import Mutation.* from '../v2-events/events/schema.graphql' -# import Query.* from '../v2-events/events/schema.graphql' # import * from 'common.graphql' # TODO diff --git a/packages/gateway/src/v2-events/events/root-resolvers.ts b/packages/gateway/src/v2-events/events/root-resolvers.ts deleted file mode 100644 index 6b5d105b1c..0000000000 --- a/packages/gateway/src/v2-events/events/root-resolvers.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 { GQLResolver } from '@gateway/graphql/schema' - -import uuid from 'uuid' -import { api } from './service' - -export const resolvers: GQLResolver = { - Query: { - async getEvent(_, { eventId }, { headers }) { - return api.event.get.query(eventId, { context: { headers } }) - } - }, - Mutation: { - async createEvent(_, { event }, { headers }) { - const createdEvent = await api.event.create.mutate( - { - type: event.type, - transactionId: uuid.v4() - }, - { context: { headers } } - ) - return createdEvent - }, - async notifyEvent(_, { eventId, input }, { headers }) { - return api.event.actions.notify.mutate( - { - eventId: eventId, - data: Object.fromEntries(input.data.map((d) => [d.id, d.value])), - createdAtLocation: '123', - transactionId: uuid.v4() - }, - { context: { headers } } - ) - }, - async declareEvent(_, { eventId, input }, { headers }) { - const data = await api.event.actions.declare.mutate( - { - eventId: eventId, - data: Object.fromEntries(input.data.map((d) => [d.id, d.value])), - transactionId: uuid.v4() - }, - { context: { headers } } - ) - - return data - } - } -} diff --git a/packages/gateway/src/v2-events/events/schema.graphql b/packages/gateway/src/v2-events/events/schema.graphql deleted file mode 100644 index 2dc90acb09..0000000000 --- a/packages/gateway/src/v2-events/events/schema.graphql +++ /dev/null @@ -1,149 +0,0 @@ -# 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. - -scalar DateTime - -type Event { - type: String! - id: String! - createdAt: DateTime! - updatedAt: DateTime! - actions: [Action!]! -} - -input EventInput { - type: String! -} - -type Field { - id: String! - value: FieldValue! -} - -input FieldInput { - id: String! - value: FieldValue! -} - -union Action = CreateAction | RegisterAction | NotifyAction | DeclareAction - -type CreateAction { - type: String! - createdAt: DateTime! - createdBy: String! - data: [Field!]! -} - -type NotifyAction { - type: String! - createdAt: DateTime! - createdBy: String! - data: [Field!]! -} - -type DeclareAction { - type: String! - createdAt: DateTime! - createdBy: String! - data: [Field!]! - identifiers: Identifiers! -} - -type RegisterAction { - type: String! - createdAt: DateTime! - createdBy: String! - data: [Field!]! - identifiers: Identifiers! -} - -input NotifyActionInput { - data: [FieldInput!]! -} - -input DeclareActionInput { - data: [FieldInput!]! -} - -input RegisterActionInput { - data: [FieldInput!]! -} - -input CertifyActionInput { - data: [FieldInput!]! -} - -input IssueActionInput { - data: [FieldInput!]! -} - -input RevokeActionInput { - data: [FieldInput!]! -} - -input ReinstateActionInput { - data: [FieldInput!]! -} - -input RevokeCorrectionActionInput { - data: [FieldInput!]! -} - -input RequestCorrectionActionInput { - data: [FieldInput!]! -} - -input ApproveCorrectionActionInput { - data: [FieldInput!]! -} - -input RejectCorrectionActionInput { - data: [FieldInput!]! -} - -type Identifiers { - trackingId: String! - registrationNumber: String! -} - -input IdentifiersInput { - trackingId: String! - registrationNumber: String! -} - -type Query { - getEvent(eventId: ID!): Event! -} - -type Mutation { - createEvent(event: EventInput!): Event! - notifyEvent(eventId: ID!, input: NotifyActionInput!): Event! - declareEvent(eventId: ID!, input: DeclareActionInput!): Event! - registerEvent(eventId: ID!, input: RegisterActionInput!): Event! - certifyEvent(eventId: ID!, input: CertifyActionInput!): Event! - issueEvent(eventId: ID!, input: IssueActionInput!): Event! - revokeEvent(eventId: ID!, input: RevokeActionInput!): Event! - reinstateEvent(eventId: ID!, input: ReinstateActionInput!): Event! - revokeCorrectionEvent( - eventId: ID! - input: RevokeCorrectionActionInput! - ): Event! - requestCorrectionEvent( - eventId: ID! - input: RequestCorrectionActionInput! - ): Event! - approveCorrectionEvent( - eventId: ID! - input: ApproveCorrectionActionInput! - ): Event! - rejectCorrectionEvent( - eventId: ID! - input: RejectCorrectionActionInput! - ): Event! -} diff --git a/packages/gateway/src/v2-events/events/type-resolvers.ts b/packages/gateway/src/v2-events/events/type-resolvers.ts deleted file mode 100644 index bf98aaacdd..0000000000 --- a/packages/gateway/src/v2-events/events/type-resolvers.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 { - GQLCreateActionTypeResolver, - GQLResolver -} from '@gateway/graphql/schema' -import { ActionType } from '@opencrvs/commons' -import { ActionDocument } from '@opencrvs/commons/events' - -const ActionResolver: GQLCreateActionTypeResolver = { - data: (list) => - Object.entries(list.data).map(([id, value]) => ({ id, value })) -} - -export const eventResolvers: GQLResolver = { - CreateAction: ActionResolver, - NotifyAction: ActionResolver, - DeclareAction: ActionResolver, - RegisterAction: ActionResolver, - Action: { - __resolveType: (obj: ActionDocument) => { - if (obj.type === ActionType.NOTIFY) { - return 'NotifyAction' - } - if (obj.type === ActionType.DECLARE) { - return 'DeclareAction' - } - if (obj.type === ActionType.REGISTER) { - return 'RegisterAction' - } - return 'CreateAction' - } - } -}