Skip to content

Commit

Permalink
Removes dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
gudjong committed Jan 16, 2025
1 parent 3dc3098 commit 0475900
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 275 deletions.
174 changes: 0 additions & 174 deletions apps/judicial-system/backend/src/app/formatters/confirmedPdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import {
import { PDFKitCoatOfArms } from './PDFKitCoatOfArms'

type ConfirmableCaseFileCategories =
| CaseFileCategory.INDICTMENT
| CaseFileCategory.RULING
| CaseFileCategory.COURT_RECORD

// Colors
const lightGray = rgb(0.9804, 0.9804, 0.9804)
const darkGray = rgb(0.7961, 0.7961, 0.7961)
const gold = rgb(0.6784, 0.6392, 0.451)
const white = rgb(1, 1, 1)

// Spacing
Expand All @@ -29,175 +27,6 @@ const coatOfArmsWidth = calculatePt(105)
const confirmedByHeight = calculatePt(50)
const titleX = coatOfArmsX + coatOfArmsWidth + calculatePt(8)

const createIndictmentConfirmation = async (
confirmation: Confirmation,
pdfDoc: PDFDocument,
) => {
const pages = pdfDoc.getPages()
const doc = pages[0]

const shadowHeight = calculatePt(90)
const { width, height } = doc.getSize()
const titleHeight = calculatePt(32)
const titleWidth = width - coatOfArmsWidth - 2 * coatOfArmsX
const confirmedByWidth = calculatePt(258)
const institutionWidth = confirmedByWidth + calculatePt(48)

// Draw the shadow
doc.drawRectangle({
x: pageMargin,
y: height - shadowHeight - pageMargin,
width: doc.getWidth() - 2 * pageMargin - calculatePt(16),
height: shadowHeight,
color: lightGray,
})

// Draw the box around the coat of arms
doc.drawRectangle({
x: coatOfArmsX,
y: height - shadowHeight - pageMargin + calculatePt(8),
width: coatOfArmsWidth,
height: shadowHeight,
color: rgb(1, 1, 1),
borderColor: darkGray,
borderWidth: 1,
})

PDFKitCoatOfArms(doc, height)

doc.drawRectangle({
x: coatOfArmsX + coatOfArmsWidth,
y: height - pageMargin - titleHeight + calculatePt(8),
width: titleWidth,
height: titleHeight,
color: lightGray,
borderColor: darkGray,
borderWidth: 1,
})

const timesRomanFont = await pdfDoc.embedFont(StandardFonts.TimesRoman)
const timesRomanBoldFont = await pdfDoc.embedFont(
StandardFonts.TimesRomanBold,
)
doc.drawText('Réttarvörslugátt', {
x: titleX,
y: height - pageMargin - titleHeight + calculatePt(20),
size: calculatePt(smallFontSize),
font: timesRomanBoldFont,
})

doc.drawText('Skjal samþykkt rafrænt', {
x: 158,
y: height - pageMargin - titleHeight + calculatePt(20),
size: calculatePt(smallFontSize),
font: timesRomanFont,
})

doc.drawSvgPath(
'M0.763563 11.8047H7.57201C7.85402 11.8047 8.08264 11.5761 8.08264 11.2941V5.50692C8.08264 5.22492 7.85402 4.99629 7.57201 4.99629H7.06138V3.46439C7.06138 1.86887 5.76331 0.570801 4.16779 0.570801C2.57226 0.570801 1.2742 1.86887 1.2742 3.46439V4.99629H0.763563C0.481557 4.99629 0.25293 5.22492 0.25293 5.50692V11.2941C0.25293 11.5761 0.481557 11.8047 0.763563 11.8047ZM5.61394 8.03817L4.16714 9.48496C4.06743 9.58467 3.93674 9.63455 3.80609 9.63455C3.67543 9.63455 3.54471 9.58467 3.44504 9.48496L2.72164 8.76157C2.52222 8.56215 2.52222 8.23888 2.72164 8.03943C2.92102 7.84001 3.24436 7.84001 3.44378 8.03943L3.80612 8.40174L4.89187 7.31603C5.09125 7.11661 5.41458 7.11661 5.614 7.31603C5.81339 7.51549 5.81339 7.83875 5.61394 8.03817ZM2.29546 3.46439C2.29546 2.43199 3.13539 1.59207 4.16779 1.59207C5.20019 1.59207 6.04011 2.43199 6.04011 3.46439V4.99629H2.29546V3.46439Z',
{
color: gold,
x: width - 38,
y: height - pageMargin - titleHeight + calculatePt(33),
},
)

// Draw the "Confirmed by" box
doc.drawRectangle({
x: coatOfArmsX + coatOfArmsWidth,
y: height - pageMargin - titleHeight - confirmedByHeight,
width: confirmedByWidth,
height: shadowHeight - titleHeight,
color: white,
borderColor: darkGray,
borderWidth: 1,
})

doc.drawText('Staðfestingaraðili', {
x: titleX,
y: height - pageMargin - titleHeight - calculatePt(15),
size: calculatePt(smallFontSize),
font: timesRomanBoldFont,
})

if (confirmation?.actor) {
timesRomanFont.widthOfTextAtSize(
`${confirmation.actor}${
confirmation.title ? `, ${lowercase(confirmation.title)}` : ''
}`,
calculatePt(smallFontSize),
)
drawTextWithEllipsisPDFKit(
doc,
`${confirmation.actor}${
confirmation.title ? `, ${lowercase(confirmation.title)}` : ''
}`,
{ type: timesRomanFont, size: calculatePt(smallFontSize) },
titleX,
height - pageMargin - titleHeight - calculatePt(29),
confirmedByWidth - 16,
)
}

// Draw the "Institution" box
doc.drawRectangle({
x: coatOfArmsX + coatOfArmsWidth + confirmedByWidth,
y: height - pageMargin - titleHeight - confirmedByHeight,
width: institutionWidth,
height: shadowHeight - titleHeight,
color: white,
borderColor: darkGray,
borderWidth: 1,
})

doc.drawText('Embætti', {
x: titleX + confirmedByWidth,
y: height - pageMargin - titleHeight - calculatePt(15),
size: calculatePt(smallFontSize),
font: timesRomanBoldFont,
})

if (confirmation?.institution) {
doc.drawText(confirmation.institution, {
x: titleX + confirmedByWidth,
y: height - pageMargin - titleHeight - calculatePt(29),
font: timesRomanFont,
size: calculatePt(smallFontSize),
})
}

// Draw the "Indictment date" box
doc.drawRectangle({
x: width - 90,
y: height - pageMargin - titleHeight - confirmedByHeight,
width: 70,
height: shadowHeight - titleHeight,
color: white,
borderColor: darkGray,
borderWidth: 1,
})

doc.drawText('Útgáfa ákæru', {
x: width - 72,
y: height - pageMargin - titleHeight - calculatePt(15),
size: calculatePt(smallFontSize),
font: timesRomanBoldFont,
})

if (confirmation?.date) {
const dateFormattedDate = formatDate(confirmation.date)

if (dateFormattedDate) {
doc.drawText(dateFormattedDate, {
x: width - 62,
y: height - pageMargin - titleHeight - calculatePt(29),
font: timesRomanFont,
size: calculatePt(smallFontSize),
})
}
}
}

const createRulingConfirmation = async (
confirmation: Confirmation,
pdfDoc: PDFDocument,
Expand Down Expand Up @@ -443,9 +272,6 @@ export const createConfirmedPdf = async (
const pdfDoc = await PDFDocument.load(pdf)

switch (fileType) {
case CaseFileCategory.INDICTMENT:
await createIndictmentConfirmation(confirmation, pdfDoc)
break
case CaseFileCategory.RULING: {
await createRulingConfirmation(confirmation, pdfDoc)
break
Expand Down
12 changes: 0 additions & 12 deletions apps/judicial-system/backend/src/app/modules/case/case.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ export const include: Includeable[] = [
state: { [Op.not]: CaseFileState.DELETED },
category: {
[Op.in]: [
CaseFileCategory.INDICTMENT,
CaseFileCategory.COURT_RECORD,
CaseFileCategory.CRIMINAL_RECORD,
CaseFileCategory.COST_BREAKDOWN,
Expand Down Expand Up @@ -1840,10 +1839,6 @@ export class CaseService {
): Promise<Case | undefined> {
const receivingCase =
update.courtCaseNumber && theCase.state === CaseState.SUBMITTED
const returningIndictmentCase =
isIndictmentCase(theCase.type) &&
update.state === CaseState.DRAFT &&
theCase.state === CaseState.RECEIVED
const completingIndictmentCaseWithoutRuling =
isIndictmentCase(theCase.type) &&
update.state === CaseState.COMPLETED &&
Expand Down Expand Up @@ -1902,13 +1897,6 @@ export class CaseService {
await this.fileService.resetCaseFileStates(theCase.id, transaction)
}

if (returningIndictmentCase) {
await this.fileService.resetIndictmentCaseFileHashes(
theCase.id,
transaction,
)
}

// Remove uploaded ruling files if an indictment case is completed without a ruling
if (completingIndictmentCaseWithoutRuling && theCase.caseFiles) {
await Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ export const include: Includeable[] = [
CaseFileCategory.APPEAL_RULING,
CaseFileCategory.APPEAL_COURT_RECORD,
CaseFileCategory.COURT_RECORD,
CaseFileCategory.INDICTMENT,
CaseFileCategory.CRIMINAL_RECORD,
CaseFileCategory.COST_BREAKDOWN,
CaseFileCategory.CASE_FILE,
Expand Down Expand Up @@ -276,7 +275,6 @@ export const include: Includeable[] = [
state: { [Op.not]: CaseFileState.DELETED },
category: {
[Op.in]: [
CaseFileCategory.INDICTMENT,
CaseFileCategory.COURT_RECORD,
CaseFileCategory.CRIMINAL_RECORD,
CaseFileCategory.COST_BREAKDOWN,
Expand Down
87 changes: 18 additions & 69 deletions apps/judicial-system/backend/src/app/modules/file/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
CaseFileCategory,
CaseFileState,
EventType,
hasIndictmentCaseBeenSubmittedToCourt,
isCompletedCase,
isIndictmentCase,
} from '@island.is/judicial-system/types'
Expand Down Expand Up @@ -107,24 +106,6 @@ export class FileService {
return true
}

if (
isIndictmentCase(theCase.type) &&
file.category === CaseFileCategory.INDICTMENT
) {
// The file may have been confirmed
return this.awsS3Service
.deleteConfirmedIndictmentCaseObject(theCase.type, file.key)
.catch((reason) => {
// Tolerate failure, but log what happened
this.logger.error(
`Could not delete confirmed file ${file.id} of case ${file.caseId} from AWS S3`,
{ reason },
)

return false
})
}

return this.awsS3Service
.deleteObject(theCase.type, file.key)
.catch((reason) => {
Expand All @@ -142,7 +123,6 @@ export class FileService {
let courtDocumentFolder: CourtDocumentFolder

switch (file.category) {
case CaseFileCategory.INDICTMENT:
case CaseFileCategory.CRIMINAL_RECORD:
case CaseFileCategory.COST_BREAKDOWN:
courtDocumentFolder = CourtDocumentFolder.INDICTMENT_DOCUMENTS
Expand Down Expand Up @@ -177,6 +157,14 @@ export class FileService {
file: CaseFile,
pdf: Buffer,
): Promise<string | undefined> {
if (
!theCase.rulingDate ||
(file.category !== CaseFileCategory.RULING &&
file.category !== CaseFileCategory.COURT_RECORD)
) {
return undefined
}

const confirmationEvent = theCase.eventLogs?.find(
(event) => event.eventType === EventType.INDICTMENT_CONFIRMED,
)
Expand All @@ -185,40 +173,16 @@ export class FileService {
return undefined
}

return this.userService
.findByNationalId(confirmationEvent.nationalId)
.then((user) => {
if (file.category === CaseFileCategory.INDICTMENT) {
return createConfirmedPdf(
{
actor: user.name,
title: user.title,
institution: user.institution?.name ?? '',
date: confirmationEvent.created,
},
pdf,
CaseFileCategory.INDICTMENT,
)
}

if (
(file.category === CaseFileCategory.RULING ||
file.category === CaseFileCategory.COURT_RECORD) &&
isCompletedCase(theCase.state) &&
theCase.rulingDate
) {
return createConfirmedPdf(
{
actor: theCase.judge?.name ?? '',
title: theCase.judge?.title,
institution: theCase.judge?.institution?.name ?? '',
date: theCase.rulingDate,
},
pdf,
file.category,
)
}
})
return createConfirmedPdf(
{
actor: theCase.judge?.name ?? '',
title: theCase.judge?.title,
institution: theCase.judge?.institution?.name ?? '',
date: theCase.rulingDate,
},
pdf,
file.category,
)
.then((confirmedPdf) => {
if (!confirmedPdf) {
throw new Error('Failed to create confirmed PDF')
Expand Down Expand Up @@ -248,14 +212,6 @@ export class FileService {
return false
}

// Only indictments that have been submitted to court can be confirmed
if (
file.category === CaseFileCategory.INDICTMENT &&
hasIndictmentCaseBeenSubmittedToCourt(theCase.state)
) {
return true
}

// Rulings and court records are only confirmed when a case is completed
if (
(file.category === CaseFileCategory.RULING ||
Expand Down Expand Up @@ -572,13 +528,6 @@ export class FileService {
)
}

resetIndictmentCaseFileHashes(caseId: string, transaction: Transaction) {
return this.fileModel.update(
{ hash: null },
{ where: { caseId, category: CaseFileCategory.INDICTMENT }, transaction },
)
}

async deliverCaseFileToCourtOfAppeals(
theCase: Case,
file: CaseFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const defenderDefaultCaseFileCategoriesForIndictmentCases = [

const defenderCaseFileCategoriesForIndictmentCases =
defenderDefaultCaseFileCategoriesForIndictmentCases.concat(
CaseFileCategory.INDICTMENT,
CaseFileCategory.CRIMINAL_RECORD,
CaseFileCategory.COST_BREAKDOWN,
CaseFileCategory.CASE_FILE,
Expand Down
Loading

0 comments on commit 0475900

Please sign in to comment.