Skip to content

Commit

Permalink
Merge branch 'efs_fixes_4_6' of https://github.com/island-is/island.is
Browse files Browse the repository at this point in the history
…into efs_fixes_4_6
  • Loading branch information
albina committed Jun 5, 2024
2 parents b5cf3cb + ac09ee9 commit 3335509
Show file tree
Hide file tree
Showing 63 changed files with 897 additions and 461 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Field, ID, InputType } from '@nestjs/graphql'

import {
DefendantPlea,
DefenderChoice,
Gender,
ServiceRequirement,
} from '@island.is/judicial-system/types'
Expand Down Expand Up @@ -68,11 +69,6 @@ export class UpdateDefendantInput {
@Field(() => String, { nullable: true })
readonly defenderPhoneNumber?: string

@Allow()
@IsOptional()
@Field(() => Boolean, { nullable: true })
readonly defendantWaivesRightToCounsel?: boolean

@Allow()
@IsOptional()
@Field(() => DefendantPlea, { nullable: true })
Expand All @@ -87,4 +83,9 @@ export class UpdateDefendantInput {
@IsOptional()
@Field(() => String, { nullable: true })
readonly verdictViewDate?: string

@Allow()
@IsOptional()
@Field(() => DefenderChoice, { nullable: true })
readonly defenderChoice?: DefenderChoice
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { Field, ID, ObjectType, registerEnumType } from '@nestjs/graphql'

import {
DefendantPlea,
DefenderChoice,
Gender,
ServiceRequirement,
} from '@island.is/judicial-system/types'

registerEnumType(Gender, { name: 'Gender' })
registerEnumType(DefendantPlea, { name: 'DefendantPlea' })
registerEnumType(ServiceRequirement, { name: 'ServiceRequirement' })
registerEnumType(DefenderChoice, { name: 'DefenderChoice' })

@ObjectType()
export class Defendant {
Expand Down Expand Up @@ -54,9 +56,6 @@ export class Defendant {
@Field(() => String, { nullable: true })
readonly defenderPhoneNumber?: string

@Field(() => Boolean, { nullable: true })
readonly defendantWaivesRightToCounsel?: boolean

@Field(() => DefendantPlea, { nullable: true })
readonly defendantPlea?: DefendantPlea

Expand All @@ -68,4 +67,7 @@ export class Defendant {

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

@Field(() => DefenderChoice, { nullable: true })
readonly defenderChoice?: DefenderChoice
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((t) =>
queryInterface
.addColumn(
'defendant',
'defender_choice',
{
type: Sequelize.STRING,
allowNull: true,
},
{ transaction: t },
)
.then(() =>
queryInterface.sequelize.query(
`UPDATE "defendant" SET defender_choice = 'WAIVE' WHERE defendant_waives_right_to_counsel = true;`,
{ transaction: t },
),
)
.then(() =>
queryInterface.removeColumn(
'defendant',
'defendant_waives_right_to_counsel',
{ transaction: t },
),
),
)
},

down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((t) =>
queryInterface
.addColumn(
'defendant',
'defendant_waives_right_to_counsel',
{
type: Sequelize.BOOLEAN,
defaultValue: false,
allowNull: false,
},
{ transaction: t },
)
.then(() =>
queryInterface.sequelize.query(
`UPDATE "defendant" SET defendant_waives_right_to_counsel = true WHERE defender_choice = 'WAIVE';`,
{ transaction: t },
),
)
.then(() =>
queryInterface.removeColumn('defendant', 'defender_choice', {
transaction: t,
}),
),
)
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ export const include: Includeable[] = [
as: 'appealJudge3',
include: [{ model: Institution, as: 'institution' }],
},
{
model: User,
as: 'indictmentReviewer',
include: [{ model: Institution, as: 'institution' }],
},
{
model: Case,
as: 'parentCase',
Expand Down Expand Up @@ -289,11 +294,6 @@ export const include: Includeable[] = [
where: { commentType: { [Op.in]: commentTypes } },
},
{ model: Notification, as: 'notifications' },
{
model: User,
as: 'indictmentReviewer',
include: [{ model: Institution, as: 'institution' }],
},
]

export const order: OrderItem[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ export class InternalCaseController {
@Body() internalCasesDto: InternalCasesDto,
): Promise<Case[]> {
this.logger.debug('Getting all indictment cases')
const nationalId = formatNationalId(internalCasesDto.nationalId)

return this.internalCaseService.getIndictmentCases(nationalId)
return this.internalCaseService.getIndictmentCases(
internalCasesDto.nationalId,
)
}

@Post('cases/indictment/:caseId')
Expand All @@ -95,9 +96,11 @@ export class InternalCaseController {
@Body() internalCasesDto: InternalCasesDto,
): Promise<Case | null> {
this.logger.debug(`Getting indictment case ${caseId}`)
const nationalId = formatNationalId(internalCasesDto.nationalId)

return this.internalCaseService.getIndictmentCase(caseId, nationalId)
return this.internalCaseService.getIndictmentCase(
caseId,
internalCasesDto.nationalId,
)
}

@UseGuards(CaseExistsGuard)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import { FormatMessage, IntlService } from '@island.is/cms-translations'
import { type Logger, LOGGER_PROVIDER } from '@island.is/logging'
import type { ConfigType } from '@island.is/nest/config'

import { formatCaseType } from '@island.is/judicial-system/formatters'
import {
formatCaseType,
formatNationalId,
} from '@island.is/judicial-system/formatters'
import {
CaseFileCategory,
CaseOrigin,
Expand Down Expand Up @@ -1048,6 +1051,8 @@ export class InternalCaseService {
}

async getIndictmentCases(nationalId: string): Promise<Case[]> {
const formattedNationalId = formatNationalId(nationalId)

return this.caseModel.findAll({
include: [
{ model: Defendant, as: 'defendants' },
Expand All @@ -1057,7 +1062,10 @@ export class InternalCaseService {
attributes: ['id', 'courtCaseNumber', 'type', 'state'],
where: {
type: CaseType.INDICTMENT,
'$defendants.national_id$': nationalId,
[Op.or]: [
{ '$defendants.national_id$': nationalId },
{ '$defendants.national_id$': formattedNationalId },
],
},
})
}
Expand All @@ -1066,6 +1074,10 @@ export class InternalCaseService {
caseId: string,
nationalId: string,
): Promise<Case | null> {
// The national id could be without a hyphen or with a hyphen so we need to
// search for both
const formattedNationalId = formatNationalId(nationalId)

const caseById = await this.caseModel.findOne({
include: [
{ model: Defendant, as: 'defendants' },
Expand All @@ -1078,7 +1090,10 @@ export class InternalCaseService {
where: {
type: CaseType.INDICTMENT,
id: caseId,
'$defendants.national_id$': nationalId,
[Op.or]: [
{ '$defendants.national_id$': nationalId },
{ '$defendants.national_id$': formattedNationalId },
],
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ import {
CaseState,
CommentType,
DateType,
EventType,
NotificationType,
UserRole,
} from '@island.is/judicial-system/types'

import { nowFactory, uuidFactory } from '../../factories'
import { AwsS3Service } from '../aws-s3'
import { Defendant, DefendantService } from '../defendant'
import { EventLog } from '../event-log'
import {
CaseFile,
defenderCaseFileCategoriesForRestrictionAndInvestigationCases,
Expand Down Expand Up @@ -97,6 +99,7 @@ export const attributes: (keyof Case)[] = [
'appealRulingModifiedHistory',
'requestAppealRulingNotToBePublished',
'prosecutorsOfficeId',
'indictmentRulingDecision',
'indictmentHash',
]

Expand All @@ -110,6 +113,7 @@ export interface LimitedAccessUpdateCase
| 'appealRulingDecision'
> {}

const eventTypes = Object.values(EventType)
const dateTypes = Object.values(DateType)
const commentTypes = Object.values(CommentType)

Expand Down Expand Up @@ -185,6 +189,14 @@ export const include: Includeable[] = [
],
},
},
{
model: EventLog,
as: 'eventLogs',
required: false,
where: { eventType: { [Op.in]: eventTypes } },
order: [['created', 'ASC']],
separate: true,
},
{
model: DateLog,
as: 'dateLogs',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
Inject,
Injectable,
InternalServerErrorException,
NotFoundException,
} from '@nestjs/common'
import { InjectModel } from '@nestjs/sequelize'

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

import { formatNationalId } from '@island.is/judicial-system/formatters'
import {
CaseMessage,
MessageService,
Expand Down Expand Up @@ -195,6 +197,37 @@ export class DefendantService {
return updatedDefendant
}

async updateByNationalId(
caseId: string,
defendantNationalId: string,
update: UpdateDefendantDto,
): Promise<Defendant> {
const formattedNationalId = formatNationalId(defendantNationalId)

const [numberOfAffectedRows, defendants] = await this.defendantModel.update(
update,
{
where: {
caseId,
[Op.or]: [
{ national_id: formattedNationalId },
{ national_id: defendantNationalId },
],
},
returning: true,
},
)

const updatedDefendant = this.getUpdatedDefendant(
numberOfAffectedRows,
defendants,
defendants[0].id,
caseId,
)

return updatedDefendant
}

async delete(
theCase: Case,
defendantId: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IsBoolean, IsEnum, IsOptional, IsString } from 'class-validator'

import { ApiPropertyOptional } from '@nestjs/swagger'

import { Gender } from '@island.is/judicial-system/types'
import { DefenderChoice, Gender } from '@island.is/judicial-system/types'

export class CreateDefendantDto {
@IsOptional()
Expand Down Expand Up @@ -56,7 +56,7 @@ export class CreateDefendantDto {
readonly defenderPhoneNumber?: string

@IsOptional()
@IsBoolean()
@ApiPropertyOptional({ type: Boolean })
readonly defendantWaivesRightToCounsel?: boolean
@IsEnum(DefenderChoice)
@ApiPropertyOptional({ enum: DefenderChoice })
readonly defenderChoice?: DefenderChoice
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ApiPropertyOptional } from '@nestjs/swagger'

import {
DefendantPlea,
DefenderChoice,
Gender,
ServiceRequirement,
} from '@island.is/judicial-system/types'
Expand Down Expand Up @@ -60,9 +61,9 @@ export class UpdateDefendantDto {
readonly defenderPhoneNumber?: string

@IsOptional()
@IsBoolean()
@ApiPropertyOptional({ type: Boolean })
readonly defendantWaivesRightToCounsel?: boolean
@IsEnum(DefenderChoice)
@ApiPropertyOptional({ enum: DefenderChoice })
readonly defenderChoice?: DefenderChoice

@IsOptional()
@IsEnum(DefendantPlea)
Expand Down
Loading

0 comments on commit 3335509

Please sign in to comment.