Skip to content

Commit

Permalink
Merge branch 'main' into j-s/indictment-view-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored May 27, 2024
2 parents 0eb27b1 + aab28bd commit 8f5a414
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IsNotEmpty, IsString } from 'class-validator'

import { ApiProperty } from '@nestjs/swagger'

export class InternalCasesDto {
@IsNotEmpty()
@IsString()
@ApiProperty({ type: String })
readonly nationalId!: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'

import { TokenGuard } from '@island.is/judicial-system/auth'
import { formatNationalId } from '@island.is/judicial-system/formatters'
import {
messageEndpoint,
MessageType,
Expand All @@ -25,6 +26,7 @@ import {

import { CaseEvent, EventService } from '../event'
import { DeliverDto } from './dto/deliver.dto'
import { InternalCasesDto } from './dto/internalCases.dto'
import { InternalCreateCaseDto } from './dto/internalCreateCase.dto'
import { CurrentCase } from './guards/case.decorator'
import { CaseCompletedGuard } from './guards/caseCompleted.guard'
Expand Down Expand Up @@ -68,6 +70,21 @@ export class InternalCaseController {
return this.internalCaseService.archive()
}

@Post('cases/indictments')
@ApiOkResponse({
type: Case,
isArray: true,
description: 'Gets all indictment cases',
})
getIndictmentCases(
@Body() internalCasesDto: InternalCasesDto,
): Promise<Case[]> {
this.logger.debug('Getting all indictment cases')
const nationalId = formatNationalId(internalCasesDto.nationalId)

return this.internalCaseService.getIndictmentCases(nationalId)
}

@UseGuards(CaseExistsGuard)
@Post(
`case/:caseId/${messageEndpoint[MessageType.DELIVERY_TO_COURT_PROSECUTOR]}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { archiveFilter } from './filters/case.archiveFilter'
import { ArchiveResponse } from './models/archive.response'
import { Case } from './models/case.model'
import { CaseArchive } from './models/caseArchive.model'
import { DateLog } from './models/dateLog.model'
import { DeliverResponse } from './models/deliver.response'
import { caseModuleConfig } from './case.config'

Expand Down Expand Up @@ -1151,4 +1152,19 @@ export class InternalCaseService {

return originalAncestor
}

async getIndictmentCases(nationalId: string): Promise<Case[]> {
return this.caseModel.findAll({
include: [
{ model: Defendant, as: 'defendants' },
{ model: DateLog, as: 'dateLogs' },
],
order: [[{ model: DateLog, as: 'dateLogs' }, 'created', 'DESC']],
attributes: ['id', 'courtCaseNumber', 'type', 'state'],
where: {
type: CaseType.INDICTMENT,
'$defendants.national_id$': nationalId,
},
})
}
}
18 changes: 14 additions & 4 deletions apps/judicial-system/digital-mailbox-api/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Controller, Get, Inject } from '@nestjs/common'
import { UseGuards } from '@nestjs/common'
import { Controller, Get, Inject, Query, UseGuards } from '@nestjs/common'
import { ApiCreatedResponse } from '@nestjs/swagger'

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

import type { User as TUser } from '@island.is/judicial-system/types'

import { JwtAuthGuard } from './guards/auth.guard'
import { User } from './guards/user.decorator'
import { CasesResponse } from './models/cases.response'
import { AppService } from './app.service'

@Controller('api')
Expand All @@ -26,4 +25,15 @@ export class AppController {

return this.appService.testConnection(user.nationalId)
}

@Get('cases')
@ApiCreatedResponse({ type: String, description: 'Get all cases' })
async getAllCases(
@User() user: Pick<TUser, 'nationalId'>,
@Query() query?: { lang: string },
): Promise<CasesResponse[]> {
this.logger.debug('Getting all cases')

return this.appService.getCases(user.nationalId, query?.lang)
}
}
85 changes: 81 additions & 4 deletions apps/judicial-system/digital-mailbox-api/src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { Inject, Injectable } from '@nestjs/common'
import { BadGatewayException, Inject, Injectable } from '@nestjs/common'

import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'
import { type Logger, LOGGER_PROVIDER } from '@island.is/logging'
import { type ConfigType } from '@island.is/nest/config'

import { AuditTrailService } from '@island.is/judicial-system/audit-trail'
import {
AuditedAction,
AuditTrailService,
} from '@island.is/judicial-system/audit-trail'
import { isCompletedCase } from '@island.is/judicial-system/types'

import { CasesResponse } from './models/cases.response'
import { InternalCasesResponse } from './models/internalCases.response'
import { digitalMailboxModuleConfig } from './app.config'

@Injectable()
Expand All @@ -24,4 +29,76 @@ export class AppService {
async testConnection(nationalId: string): Promise<string> {
return this.test(nationalId)
}

private format(
response: InternalCasesResponse[],
lang?: string,
): CasesResponse[] {
return response.map((item: InternalCasesResponse) => {
const language = lang?.toLowerCase()

return {
id: item.id,
state: {
color: isCompletedCase(item.state) ? 'purple' : 'blue',
label:
language === 'en'
? isCompletedCase(item.state)
? 'Completed'
: 'Active'
: isCompletedCase(item.state)
? 'Lokið'
: 'Í vinnslu',
},
caseNumber:
language === 'en'
? `Case number ${item.courtCaseNumber}`
: `Málsnúmer ${item.courtCaseNumber}`,
type: language === 'en' ? 'Indictment' : 'Ákæra',
}
})
}

private async getAllCases(
nationalId: string,
lang?: string,
): Promise<CasesResponse[]> {
return fetch(`${this.config.backendUrl}/api/internal/cases/indictments`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
authorization: `Bearer ${this.config.secretToken}`,
},
body: JSON.stringify({ nationalId }),
})
.then(async (res) => {
const response = await res.json()

if (res.ok) {
return this.format(response, lang)
}

if (res.status < 500) {
throw new BadGatewayException(response?.detail)
}

throw response
})
.catch((reason) => {
if (reason instanceof BadGatewayException) {
throw reason
}

throw new BadGatewayException(reason)
})
}

async getCases(nationalId: string, lang?: string): Promise<CasesResponse[]> {
return this.auditTrailService.audit(
'digital-mailbox-api',
AuditedAction.GET_INDICTMENTS,
this.getAllCases(nationalId, lang),
nationalId,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ApiProperty } from '@nestjs/swagger'

export class CasesResponse {
@ApiProperty({ type: String })
id!: string

@ApiProperty({ type: String })
caseNumber!: string

@ApiProperty({ type: String })
type!: string

@ApiProperty({ type: Object })
state!: {
color: string
label: string
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ApiProperty } from '@nestjs/swagger'

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

export class InternalCasesResponse {
@ApiProperty({ type: String })
id!: string

@ApiProperty({ type: String })
courtCaseNumber!: string

@ApiProperty({ type: String })
type!: string

@ApiProperty({ type: String })
state!: CaseState
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ export class CitizenshipService extends BaseTemplateApiService {
auth,
}: TemplateApiModuleActionProps): Promise<ApplicantInformation> {
const validApplicant = await this.getApplicantValidity(auth)
if (!validApplicant.applicantExists && !validApplicant.isEESCitizen) {
const validOptions = []

for (const [key, value] of Object.entries(validApplicant)) {
if (value) {
validOptions.push(key)
}
}

if (validOptions.length === 0) {
throw new TemplateApiError(
{
title: errorMessages.applicationConditionsNotMet,
Expand Down Expand Up @@ -167,7 +175,15 @@ export class CitizenshipService extends BaseTemplateApiService {
auth,
}: TemplateApiModuleActionProps) {
const validApplicant = await this.getApplicantValidity(auth)
if (!validApplicant.applicantExists && !validApplicant.isEESCitizen) {
const validOptions = []

for (const [key, value] of Object.entries(validApplicant)) {
if (value) {
validOptions.push(key)
}
}

if (validOptions.length === 0) {
throw new TemplateApiError(
{
title: errorMessages.applicationConditionsNotMet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,7 @@ export const CitizenshipSchema = z.object({
passport: PassportSchema,
childrenPassport: z.array(ChildrenPassportSchema).optional(),
maritalStatus: MaritalStatusSchema,
// TODO revert
// formerIcelander: z
// .string()
// .min(1)
// .refine((v) => v === YES),
formerIcelander: z.enum([YES, NO]),
formerIcelander: z.enum([YES, NO]).refine((v) => v === YES),
supportingDocuments: SupportingDocumentsSchema,
childrenSupportingDocuments: z
.array(ChildrenSupportingDocumentsSchema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { auditTrailModuleConfig } from './auditTrail.config'
export enum AuditedAction {
LOGIN = 'LOGIN',
GET_CASES = 'GET_CASES',
GET_INDICTMENTS = 'GET_INDICTMENTS',
GET_CASE = 'GET_CASE',
CREATE_CASE = 'CREATE_CASE',
UPDATE_CASE = 'UPDATE_CASE',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
m,
formatDate,
IntroHeader,
EmptyState,
FootNote,
LinkResolver,
SAMGONGUSTOFA_SLUG,
Expand All @@ -29,6 +28,7 @@ import {
import PhysicalLessons from '../../components/DrivingLessonsTables/PhysicalLessons'
import DrivingLessonsSchools from '../../components/DrivingLessonsTables/DrivingLessonsSchools'
import Exams from '../../components/DrivingLessonsTables/Exams'
import { Problem } from '@island.is/react-spa/shared'

export const GET_STUDENT_BOOK = gql`
query GetUserDrivingLessonsBook {
Expand Down Expand Up @@ -104,6 +104,21 @@ const DrivingLessonsBook = () => {
<SkeletonLoader space={1} height={40} repeat={5} />
</Box>
)}
{!loading && !error && !book?.createdOn && (
<Box>
<LinkResolver href={formatMessage(urls.licenseApplication)}>
<Button
colorScheme="default"
icon="receipt"
iconType="outline"
variant="utility"
size="small"
>
{formatMessage(messages.signupToDrivingSchool)}
</Button>
</LinkResolver>
</Box>
)}
{book?.createdOn && !loading && (
<>
<Stack space={2}>
Expand Down Expand Up @@ -198,26 +213,25 @@ const DrivingLessonsBook = () => {
data={book?.testResults}
/>
)}
<FootNote
serviceProviderSlug={SAMGONGUSTOFA_SLUG}
notes={[
{ text: formatMessage(messages.vehicleDrivingLessonsInfoNote) },
]}
/>
</>
)}
{!loading && !error && !book?.createdOn && (
<Box marginTop={8}>
<EmptyState />
<Box display="flex" alignItems="center" justifyContent="center">
<LinkResolver href={formatMessage(urls.licenseApplication)}>
<Button as="span" unfocusable>
{formatMessage(messages.signupToDrivingSchool)}
</Button>
</LinkResolver>
</Box>
<Box marginTop={4}>
<Problem
type="no_data"
noBorder={false}
title={formatMessage(m.noData)}
message={formatMessage(m.noDataFoundDetail)}
imgSrc="./assets/images/sofa.svg"
/>
</Box>
)}
<FootNote
serviceProviderSlug={SAMGONGUSTOFA_SLUG}
notes={[
{ text: formatMessage(messages.vehicleDrivingLessonsInfoNote) },
]}
/>
</>
)
}
Expand Down

0 comments on commit 8f5a414

Please sign in to comment.