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): Civil Demands #16010

Merged
merged 6 commits into from
Sep 16, 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import { Inject, Injectable } from '@nestjs/common'
import { type ConfigType } from '@island.is/nest/config'
import { ProblemError } from '@island.is/nest/problem'

import {
CommentType,
DateType,
type User,
UserRole,
} from '@island.is/judicial-system/types'
import { DateType, type User, UserRole } from '@island.is/judicial-system/types'

import {
Case,
Expand Down Expand Up @@ -144,7 +139,6 @@ export class BackendService extends DataSource<{ req: Request }> {
private caseTransformer<Case>(data: unknown): Case {
const theCase = data as Case & {
dateLogs?: { dateType: DateType; date: string }[]
explanatoryComments?: { commentType: CommentType; comment: string }[]
}

return {
Expand All @@ -155,11 +149,6 @@ export class BackendService extends DataSource<{ req: Request }> {
courtDate: theCase.dateLogs?.find(
(dateLog) => dateLog.dateType === DateType.COURT_DATE,
),
postponedIndefinitelyExplanation: theCase.explanatoryComments?.find(
(comment) =>
comment.commentType ===
CommentType.POSTPONED_INDEFINITELY_EXPLANATION,
)?.comment,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,9 @@ export class UpdateCaseInput {
@IsOptional()
@Field(() => ID, { nullable: true })
readonly mergeCaseId?: string

@Allow()
@IsOptional()
@Field(() => String, { nullable: true })
readonly civilDemands?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,7 @@ export class Case {

@Field(() => [Case], { nullable: true })
readonly mergedCases?: Case[]

@Field(() => String, { nullable: true })
readonly civilDemands?: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict'
gudjong marked this conversation as resolved.
Show resolved Hide resolved

module.exports = {
async up(queryInterface) {
return queryInterface.sequelize.transaction(async (transaction) =>
queryInterface
.renameTable('explanatory_comment', 'case_string', {
transaction,
})
.then(() =>
Promise.all([
queryInterface.renameColumn(
'case_string',
'comment_type',
'string_type',
{ transaction },
),
queryInterface.renameColumn('case_string', 'comment', 'value', {
transaction,
}),
]),
),
)
},

async down(queryInterface) {
return queryInterface.sequelize.transaction(async (transaction) =>
queryInterface
.renameTable('case_string', 'explanatory_comment', {
transaction,
})
.then(() =>
Promise.all([
queryInterface.renameColumn(
'explanatory_comment',
'string_type',
'comment_type',
{ transaction },
),
queryInterface.renameColumn(
'explanatory_comment',
'value',
'comment',
{ transaction },
),
]),
),
)
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ import {
prosecutorUpdateRule,
publicProsecutorStaffUpdateRule,
} from './guards/rolesRules'
import {
CaseInterceptor,
CasesInterceptor,
} from './interceptors/case.interceptor'
import { CaseListInterceptor } from './interceptors/caseList.interceptor'
import { CompletedAppealAccessedInterceptor } from './interceptors/completedAppealAccessed.interceptor'
import { Case } from './models/case.model'
Expand Down Expand Up @@ -140,6 +144,7 @@ export class CaseController {

@UseGuards(JwtAuthGuard, RolesGuard)
@RolesRules(prosecutorRule, prosecutorRepresentativeRule)
@UseInterceptors(CaseInterceptor)
@Post('case')
@ApiCreatedResponse({ type: Case, description: 'Creates a new case' })
async create(
Expand Down Expand Up @@ -167,6 +172,7 @@ export class CaseController {
courtOfAppealsAssistantUpdateRule,
publicProsecutorStaffUpdateRule,
)
@UseInterceptors(CaseInterceptor)
@Patch('case/:caseId')
@ApiOkResponse({ type: Case, description: 'Updates an existing case' })
async update(
Expand Down Expand Up @@ -284,6 +290,7 @@ export class CaseController {
courtOfAppealsRegistrarTransitionRule,
courtOfAppealsAssistantTransitionRule,
)
@UseInterceptors(CaseInterceptor)
@Patch('case/:caseId/state')
@ApiOkResponse({
type: Case,
Expand Down Expand Up @@ -438,13 +445,13 @@ export class CaseController {
prisonSystemStaffRule,
defenderRule,
)
@UseInterceptors(CaseListInterceptor)
@Get('cases')
@ApiOkResponse({
type: Case,
isArray: true,
description: 'Gets all existing cases',
})
@UseInterceptors(CaseListInterceptor)
getAll(@CurrentHttpUser() user: User): Promise<Case[]> {
this.logger.debug('Getting all cases')

Expand All @@ -463,9 +470,9 @@ export class CaseController {
courtOfAppealsRegistrarRule,
courtOfAppealsAssistantRule,
)
@UseInterceptors(CompletedAppealAccessedInterceptor, CaseInterceptor)
@Get('case/:caseId')
@ApiOkResponse({ type: Case, description: 'Gets an existing case' })
@UseInterceptors(CompletedAppealAccessedInterceptor)
getById(@Param('caseId') caseId: string, @CurrentCase() theCase: Case): Case {
this.logger.debug(`Getting case ${caseId} by id`)

Expand All @@ -478,6 +485,7 @@ export class CaseController {
districtCourtRegistrarRule,
districtCourtAssistantRule,
)
@UseInterceptors(CasesInterceptor)
@Get('case/:caseId/connectedCases')
@ApiOkResponse({ type: [Case], description: 'Gets all connected cases' })
async getConnectedCases(
Expand Down Expand Up @@ -872,6 +880,7 @@ export class CaseController {
CaseReadGuard,
)
@RolesRules(prosecutorRule)
@UseInterceptors(CaseInterceptor)
@Post('case/:caseId/extend')
@ApiCreatedResponse({
type: Case,
Expand Down Expand Up @@ -901,6 +910,7 @@ export class CaseController {
districtCourtRegistrarRule,
districtCourtAssistantRule,
)
@UseInterceptors(CaseInterceptor)
@Post('case/:caseId/court')
@ApiCreatedResponse({
type: Case,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
} from '../index'
import { Case } from './models/case.model'
import { CaseArchive } from './models/caseArchive.model'
import { CaseString } from './models/caseString.model'
import { DateLog } from './models/dateLog.model'
import { ExplanatoryComment } from './models/explanatoryComment.model'
import { CaseController } from './case.controller'
import { CaseService } from './case.service'
import { InternalCaseController } from './internalCase.controller'
Expand All @@ -43,12 +43,7 @@ import { PdfService } from './pdf.service'
forwardRef(() => EventModule),
forwardRef(() => PoliceModule),
forwardRef(() => EventLogModule),
SequelizeModule.forFeature([
Case,
CaseArchive,
DateLog,
ExplanatoryComment,
]),
SequelizeModule.forFeature([Case, CaseArchive, DateLog, CaseString]),
],
providers: [
CaseService,
Expand Down
70 changes: 36 additions & 34 deletions apps/judicial-system/backend/src/app/modules/case/case.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ import {
CaseState,
CaseTransition,
CaseType,
CommentType,
DateType,
EventType,
isCompletedCase,
isIndictmentCase,
isRequestCase,
isTrafficViolationCase,
NotificationType,
StringType,
UserRole,
} from '@island.is/judicial-system/types'

Expand All @@ -66,8 +66,8 @@ import { User } from '../user'
import { CreateCaseDto } from './dto/createCase.dto'
import { getCasesQueryFilter } from './filters/cases.filter'
import { Case } from './models/case.model'
import { CaseString } from './models/caseString.model'
import { DateLog } from './models/dateLog.model'
import { ExplanatoryComment } from './models/explanatoryComment.model'
import { SignatureConfirmationResponse } from './models/signatureConfirmation.response'
import { transitionCase } from './state/case.state'
import { caseModuleConfig } from './case.config'
Expand Down Expand Up @@ -178,6 +178,7 @@ export interface UpdateCase
indictmentReturnedExplanation?: string | null
indictmentDeniedExplanation?: string | null
indictmentHash?: string | null
civilDemands?: string | null
}

type DateLogKeys = keyof Pick<UpdateCase, 'arraignmentDate' | 'courtDate'>
Expand All @@ -187,19 +188,20 @@ const dateLogTypes: Record<DateLogKeys, DateType> = {
courtDate: DateType.COURT_DATE,
}

type ExplanatoryCommentKeys = keyof Pick<
type CaseStringKeys = keyof Pick<
UpdateCase,
'postponedIndefinitelyExplanation'
'postponedIndefinitelyExplanation' | 'civilDemands'
>

const explanatoryCommentTypes: Record<ExplanatoryCommentKeys, CommentType> = {
const caseStringTypes: Record<CaseStringKeys, StringType> = {
postponedIndefinitelyExplanation:
CommentType.POSTPONED_INDEFINITELY_EXPLANATION,
StringType.POSTPONED_INDEFINITELY_EXPLANATION,
civilDemands: StringType.CIVIL_DEMANDS,
}

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

export const include: Includeable[] = [
{ model: Institution, as: 'prosecutorsOffice' },
Expand Down Expand Up @@ -293,10 +295,10 @@ export const include: Includeable[] = [
where: { dateType: { [Op.in]: dateTypes } },
},
{
model: ExplanatoryComment,
as: 'explanatoryComments',
model: CaseString,
as: 'caseStrings',
required: false,
where: { commentType: { [Op.in]: commentTypes } },
where: { stringType: { [Op.in]: stringTypes } },
},
{ model: Notification, as: 'notifications' },
{ model: Case, as: 'mergeCase' },
Expand Down Expand Up @@ -374,10 +376,10 @@ export const caseListInclude: Includeable[] = [
where: { dateType: { [Op.in]: dateTypes } },
},
{
model: ExplanatoryComment,
as: 'explanatoryComments',
model: CaseString,
as: 'caseStrings',
required: false,
where: { commentType: { [Op.in]: commentTypes } },
where: { stringType: { [Op.in]: stringTypes } },
},
{
model: EventLog,
Expand All @@ -400,8 +402,8 @@ export class CaseService {
@InjectConnection() private readonly sequelize: Sequelize,
@InjectModel(Case) private readonly caseModel: typeof Case,
@InjectModel(DateLog) private readonly dateLogModel: typeof DateLog,
@InjectModel(ExplanatoryComment)
private readonly explanatoryCommentModel: typeof ExplanatoryComment,
@InjectModel(CaseString)
private readonly caseStringModel: typeof CaseString,
@Inject(caseModuleConfig.KEY)
private readonly config: ConfigType<typeof caseModuleConfig>,
private readonly defendantService: DefendantService,
Expand Down Expand Up @@ -1468,39 +1470,39 @@ export class CaseService {
update: UpdateCase,
transaction: Transaction,
) {
// Iterate over all known explanatory comment types
for (const key in explanatoryCommentTypes) {
const commentKey = key as ExplanatoryCommentKeys
const updateComment = update[commentKey]
// Iterate over all known case string types
for (const key in caseStringTypes) {
const caseStringKey = key as CaseStringKeys
const updateCaseString = update[caseStringKey]

if (updateComment !== undefined) {
const commentType = explanatoryCommentTypes[commentKey]
if (updateCaseString !== undefined) {
const stringType = caseStringTypes[caseStringKey]

const comment = await this.explanatoryCommentModel.findOne({
where: { caseId: theCase.id, commentType },
const caseString = await this.caseStringModel.findOne({
where: { caseId: theCase.id, stringType },
transaction,
})

if (comment) {
if (updateComment === null) {
await this.explanatoryCommentModel.destroy({
where: { caseId: theCase.id, commentType },
if (caseString) {
if (updateCaseString === null) {
await this.caseStringModel.destroy({
where: { caseId: theCase.id, stringType },
transaction,
})
} else {
await this.explanatoryCommentModel.update(
{ comment: updateComment },
{ where: { caseId: theCase.id, commentType }, transaction },
await this.caseStringModel.update(
{ value: updateCaseString },
{ where: { caseId: theCase.id, stringType }, transaction },
)
}
} else if (updateComment !== null) {
await this.explanatoryCommentModel.create(
{ caseId: theCase.id, commentType, comment: updateComment },
} else if (updateCaseString !== null) {
await this.caseStringModel.create(
{ caseId: theCase.id, stringType, value: updateCaseString },
{ transaction },
)
}

delete update[commentKey]
delete update[caseStringKey]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,9 @@ export class UpdateCaseDto {
@IsUUID()
@ApiPropertyOptional({ type: String })
readonly mergeCaseId?: string

@IsOptional()
@IsString()
@ApiPropertyOptional({ type: String })
readonly civilDemands?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const prosecutorFields: (keyof UpdateCaseDto)[] = [
'requestAppealRulingNotToBePublished',
'indictmentDeniedExplanation',
'indictmentReviewDecision',
'civilDemands',
]

const publicProsecutorFields: (keyof UpdateCaseDto)[] = ['indictmentReviewerId']
Expand Down
Loading
Loading