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

feat(j-s): Event to handle case sent to public prosecutor #15288

Merged
merged 7 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/judicial-system/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { SharedAuthModule } from '@island.is/judicial-system/auth'

import { environment } from '../environments'
import { BackendApi } from './data-sources/backend'
import { EventLogModule } from './modules/event-log/eventLog.module'
gudjong marked this conversation as resolved.
Show resolved Hide resolved
import {
AuthModule,
authModuleConfig,
Expand Down Expand Up @@ -67,6 +68,7 @@ const autoSchemaFile = environment.production
FeatureModule,
CmsTranslationsModule,
PoliceModule,
EventLogModule,
ProblemModule.forRoot({ logAllErrors: true }),
ConfigModule.forRoot({
isGlobal: true,
Expand Down
17 changes: 17 additions & 0 deletions apps/judicial-system/api/src/app/data-sources/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import {
CommentType,
DateType,
EventType,

Check warning on line 11 in apps/judicial-system/api/src/app/data-sources/backend.ts

View workflow job for this annotation

GitHub Actions / linting (judicial-system-api,judicial-system-auth,judicial-system-consts,judicial-system-digital-...

'EventType' is defined but never used. Allowed unused vars must match /^_[a-zA-Z0-9]*$/u
type User,
UserRole,
} from '@island.is/judicial-system/types'

import { environment } from '../../environments'
Expand All @@ -20,6 +22,7 @@
} from '../modules/case'
import { CaseListEntry } from '../modules/case-list'
import { Defendant, DeleteDefendantResponse } from '../modules/defendant'
import { CreateEventLogInput } from '../modules/event-log'
import {
CaseFile,
DeleteFileResponse,
Expand Down Expand Up @@ -407,6 +410,20 @@
limitedAccessGetAllFiles(caseId: string): Promise<Buffer> {
return this.get(`case/${caseId}/limitedAccess/files/all`)
}

createEventLog(eventLog: CreateEventLogInput, userRole?: UserRole) {
return fetch(`${environment.backend.url}/api/eventLog/event`, {
method: 'POST',
headers: {
authorization: `Bearer ${environment.auth.secretToken}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
...eventLog,
userRole,
}),
})
}
}

export default BackendApi
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class AuthService {
nationalId: string,
userRole?: UserRole,
) {
await fetch(`${this.config.backendUrl}/api/event-log/log-event`, {
await fetch(`${this.config.backendUrl}/api/eventLog/event`, {
method: 'POST',
headers: {
authorization: `Bearer ${this.config.secretToken}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import {
} from '@island.is/judicial-system/types'

import { Defendant } from '../../defendant'
import { EventLog } from '../../event-log'
import { CaseFile } from '../../file'
import { IndictmentCount } from '../../indictment-count'
import { Institution } from '../../institution'
import { User } from '../../user'
import { EventLog } from './eventLog.model'
import { Notification } from './notification.model'

registerEnumType(CaseOrigin, { name: 'CaseOrigin' })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Allow, IsOptional } from 'class-validator'

import { Field, InputType } from '@nestjs/graphql'

import { EventType } from '@island.is/judicial-system/types'

@InputType()
export class CreateEventLogInput {
@Allow()
@Field(() => EventType)
readonly eventType!: EventType

@Allow()
@IsOptional()
@Field(() => String, { nullable: true })
readonly caseId?: string

@Allow()
@IsOptional()
@Field(() => String, { nullable: true })
readonly nationalId?: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from '@island.is/nest/config'

export const eventLogModuleConfig = defineConfig({
name: 'EventLogModule',
load: (env) => ({
backendUrl: env.required('BACKEND_URL', 'http://localhost:3344'),
secretToken: env.required(
'BACKEND_ACCESS_TOKEN',
'secret-backend-api-token',
),
}),
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common'

import { EventLogResolver } from './eventLog.resolver'

@Module({
providers: [EventLogResolver],
})
export class EventLogModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Inject, UseGuards } from '@nestjs/common'
import { Args, Context, Mutation, Resolver } from '@nestjs/graphql'

import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'

import {
CurrentGraphQlUser,
JwtGraphQlAuthGuard,
} from '@island.is/judicial-system/auth'
import type { User } from '@island.is/judicial-system/types'

import { BackendApi } from '../../data-sources'
import { CreateEventLogInput } from '../event-log/dto/createEventLog.input'

@UseGuards(JwtGraphQlAuthGuard)
@Resolver()
export class EventLogResolver {
constructor(
@Inject(LOGGER_PROVIDER)
private readonly logger: Logger,
) {}

@Mutation(() => Boolean, { nullable: true })
async createEventLog(
@Args('input', { type: () => CreateEventLogInput })
input: CreateEventLogInput,
@CurrentGraphQlUser() user: User,
@Context('dataSources') { backendApi }: { backendApi: BackendApi },
): Promise<boolean> {
this.logger.debug(`Creating event log for case ${input.caseId}`)

const res = await backendApi.createEventLog(input, user.role)
return res.ok
}
}
2 changes: 2 additions & 0 deletions apps/judicial-system/api/src/app/modules/event-log/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { CreateEventLogInput } from './dto/createEventLog.input'
export { EventLog } from './models/eventLog.model'
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Field, ID, ObjectType, registerEnumType } from '@nestjs/graphql'
import { EventType, UserRole } from '@island.is/judicial-system/types'

registerEnumType(EventType, { name: 'EventType' })

@ObjectType()
export class EventLog {
@Field(() => ID)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common'
import { Body, Controller, Post, UseGuards } from '@nestjs/common'
import { ApiCreatedResponse } from '@nestjs/swagger'

import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'

import { TokenGuard } from '@island.is/judicial-system/auth'

import { CreateEventLogDto } from './dto/createEventLog.dto'
import { EventLogService } from './eventLog.service'

@Controller('api/event-log')
@Controller('api/eventLog')
export class EventLogController {
constructor(
private readonly eventLogService: EventLogService,
@Inject(LOGGER_PROVIDER) private readonly logger: Logger,
) {}
constructor(private readonly eventLogService: EventLogService) {}

@UseGuards(TokenGuard)
@Post('log-event')
@Post('event')
@ApiCreatedResponse({ description: 'Logs an event to event log' })
logEvent(@Body() event: CreateEventLogDto): Promise<void> {
return this.eventLogService.create(event)
Expand Down
5 changes: 5 additions & 0 deletions apps/judicial-system/web/messages/Core/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,9 @@ export const errors = defineMessages({
description:
'Notaður sem skilaboð þegar ekki tókst að sækja gögn úr gagnagrunni',
},
createEventLog: {
id: 'judicial.system.core:errors.create_event_log',
defaultMessage: 'Upp kom villa við að skrá aðgerð',
description: 'Notaður sem villuskilaboð þegar ekki gengur að skrá atburð',
},
})
Loading
Loading