Skip to content

Commit

Permalink
Merge branch 'main' into j-s/subpoena-info
Browse files Browse the repository at this point in the history
  • Loading branch information
unakb authored Jun 21, 2024
2 parents d3d6b36 + 110e634 commit 712f2fb
Show file tree
Hide file tree
Showing 50 changed files with 1,004 additions and 226 deletions.
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 @@ -22,6 +22,7 @@ import {
DefendantModule,
DefenderModule,
defenderModuleConfig,
EventLogModule,
FeatureModule,
featureModuleConfig,
FileModule,
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
16 changes: 16 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 @@ -9,6 +9,7 @@ import {
CommentType,
DateType,
type User,
UserRole,
} from '@island.is/judicial-system/types'

import { environment } from '../../environments'
Expand All @@ -20,6 +21,7 @@ import {
} 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 +409,20 @@ export class BackendApi extends DataSource<{ req: Request }> {
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
1 change: 1 addition & 0 deletions apps/judicial-system/api/src/app/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export { IndictmentCountModule } from './indictment-count/indictmentCount.module
export { DefenderModule } from './defender/defender.module'
export { CaseListModule } from './case-list/caseList.module'
export { defenderModuleConfig } from './defender/defender.config'
export { EventLogModule } from './event-log/eventLog.module'
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

0 comments on commit 712f2fb

Please sign in to comment.