Skip to content

Commit

Permalink
Merge branch 'main' into feat/application-system-config
Browse files Browse the repository at this point in the history
  • Loading branch information
norda-gunni authored Sep 9, 2024
2 parents aeac997 + 87a976d commit 59de629
Show file tree
Hide file tree
Showing 171 changed files with 7,844 additions and 2,812 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict'

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn('institution', 'address', {
type: Sequelize.STRING,
allowNull: true,
})

const institutionsToUpdate = [
{
name: 'Héraðsdómur Reykjavíkur',
address: 'Dómhúsið við Lækjartorg, Reykjavík',
},
{ name: 'Héraðsdómur Reykjaness', address: 'Fjarðargata 9, Hafnarfirði' },
{
name: 'Héraðsdómur Vesturlands',
address: 'Bjarnarbraut 8, Borgarnesi',
},
{ name: 'Héraðsdómur Vestfjarða', address: 'Hafnarstræti 9, Ísafirði' },
{
name: 'Héraðsdómur Norðurlands vestra',
address: 'Skagfirðingabraut 21, Sauðárkróki',
},
{
name: 'Héraðsdómur Norðurlands eystra',
address: 'Hafnarstræti 107, 4. hæð, Akureyri',
},
{ name: 'Héraðsdómur Austurlands', address: 'Lyngás 15, Egilsstöðum' },
{ name: 'Héraðsdómur Suðurlands', address: 'Austurvegur 4, Selfossi' },
]

await queryInterface.sequelize.transaction(async (transaction) => {
for (const institution of institutionsToUpdate) {
await queryInterface.bulkUpdate(
'institution',
{ address: institution.address },
{ name: institution.name },
{ transaction },
)
}
})
},

down: async (queryInterface) => {
await queryInterface.removeColumn('institution', 'address')
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { formatDate, lowercase } from '@island.is/judicial-system/formatters'

import {
calculatePt,
Confirmation,
drawTextWithEllipsisPDFKit,
IndictmentConfirmation,
smallFontSize,
} from './pdfHelpers'
import { PDFKitCoatOfArms } from './PDFKitCoatOfArms'

export const createConfirmedIndictment = async (
confirmation: IndictmentConfirmation,
confirmation: Confirmation,
indictmentPDF: Buffer,
): Promise<Buffer> => {
const pdfDoc = await PDFDocument.load(indictmentPDF)
Expand Down
2 changes: 1 addition & 1 deletion apps/judicial-system/backend/src/app/formatters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export {
formatPostponedCourtDateEmailNotification,
stripHtmlTags,
} from './formatters'
export { IndictmentConfirmation } from './pdfHelpers'
export { Confirmation } from './pdfHelpers'
export { getRequestPdfAsBuffer, getRequestPdfAsString } from './requestPdf'
export { getRulingPdfAsBuffer, getRulingPdfAsString } from './rulingPdf'
export { createCaseFilesRecord } from './caseFilesRecordPdf'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
addNormalPlusJustifiedText,
addNormalPlusText,
addNormalText,
IndictmentConfirmation,
Confirmation,
setTitle,
} from './pdfHelpers'

Expand Down Expand Up @@ -52,7 +52,7 @@ const roman = (num: number) => {
export const createIndictment = async (
theCase: Case,
formatMessage: FormatMessage,
confirmation?: IndictmentConfirmation,
confirmation?: Confirmation,
): Promise<Buffer> => {
const doc = new PDFDocument({
size: 'A4',
Expand Down
106 changes: 101 additions & 5 deletions apps/judicial-system/backend/src/app/formatters/pdfHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { formatDate, lowercase } from '@island.is/judicial-system/formatters'
import { coatOfArms } from './coatOfArms'
import { policeStar } from './policeStar'

export interface IndictmentConfirmation {
export interface Confirmation {
actor: string
title?: string
institution: string
Expand All @@ -22,6 +22,10 @@ export const largeFontSize = 18
export const hugeFontSize = 26
export const giganticFontSize = 33

const lightGray = '#FAFAFA'
const darkGray = '#CBCBCB'
const gold = '#ADA373'

const setFont = (doc: PDFKit.PDFDocument, font?: string) => {
if (font) {
doc.font(font)
Expand Down Expand Up @@ -106,13 +110,105 @@ export const addPoliceStar = (doc: PDFKit.PDFDocument) => {
doc.scale(25).translate(-270, -70)
}

export const addConfirmation = (
doc: PDFKit.PDFDocument,
confirmation: Confirmation,
) => {
const pageMargin = calculatePt(18)
const shaddowHeight = calculatePt(70)
const coatOfArmsWidth = calculatePt(105)
const coatOfArmsX = pageMargin + calculatePt(8)
const titleHeight = calculatePt(24)
const titleX = coatOfArmsX + coatOfArmsWidth + calculatePt(8)
const institutionWidth = calculatePt(160)
const confirmedByWidth = institutionWidth + calculatePt(48)
const shaddowWidth = institutionWidth + confirmedByWidth + coatOfArmsWidth
const titleWidth = institutionWidth + confirmedByWidth

// Draw the shadow
doc
.rect(pageMargin, pageMargin + calculatePt(8), shaddowWidth, shaddowHeight)
.fill(lightGray)
.stroke()

// Draw the coat of arms
doc
.rect(coatOfArmsX, pageMargin, coatOfArmsWidth, shaddowHeight)
.fillAndStroke('white', darkGray)

addCoatOfArms(doc, calculatePt(49), calculatePt(24))

// Draw the title
doc
.rect(coatOfArmsX + coatOfArmsWidth, pageMargin, titleWidth, titleHeight)
.fillAndStroke(lightGray, darkGray)
doc.fill('black')
doc.font('Times-Bold')
doc
.fontSize(calculatePt(smallFontSize))
.text('Réttarvörslugátt', titleX, pageMargin + calculatePt(9))
doc.font('Times-Roman')
// The X value here is approx. 8px after the title
doc.text('Rafræn staðfesting', calculatePt(210), pageMargin + calculatePt(9))
doc.text(
formatDate(confirmation.date) || '',
shaddowWidth - calculatePt(24),
pageMargin + calculatePt(9),
)

// Draw the institution
doc
.rect(
coatOfArmsX + coatOfArmsWidth,
pageMargin + titleHeight,
institutionWidth,
shaddowHeight - titleHeight,
)
.fillAndStroke('white', darkGray)
doc.fill('black')
doc.font('Times-Bold')
doc.text('Dómstóll', titleX, pageMargin + titleHeight + calculatePt(10))
doc.font('Times-Roman')
drawTextWithEllipsis(
doc,
confirmation.institution,
titleX,
pageMargin + titleHeight + calculatePt(22),
institutionWidth - calculatePt(16),
)

// Draw the actor
doc
.rect(
coatOfArmsX + coatOfArmsWidth + institutionWidth,
pageMargin + titleHeight,
confirmedByWidth,
shaddowHeight - titleHeight,
)
.fillAndStroke('white', darkGray)
doc.fill('black')
doc.font('Times-Bold')
doc.text(
'Samþykktaraðili',
titleX + institutionWidth,
pageMargin + titleHeight + calculatePt(10),
)
doc.font('Times-Roman')
doc.text(
`${confirmation.actor}${
confirmation.title ? `, ${lowercase(confirmation.title)}` : ''
}`,
titleX + institutionWidth,
pageMargin + titleHeight + calculatePt(22),
)

doc.fillColor('black')
}

export const addIndictmentConfirmation = (
doc: PDFKit.PDFDocument,
confirmation: IndictmentConfirmation,
confirmation: Confirmation,
) => {
const lightGray = '#FAFAFA'
const darkGray = '#CBCBCB'
const gold = '#ADA373'
const pageMargin = calculatePt(18)
const shaddowHeight = calculatePt(90)
const coatOfArmsWidth = calculatePt(105)
Expand Down
39 changes: 16 additions & 23 deletions apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { subpoena as strings } from '../messages'
import { Case } from '../modules/case'
import { Defendant } from '../modules/defendant'
import {
addConfirmation,
addEmptyLines,
addFooter,
addHugeHeading,
Expand All @@ -22,28 +23,6 @@ import {
setTitle,
} from './pdfHelpers'

type DistrictCourts =
| 'Héraðsdómur Reykjavíkur'
| 'Héraðsdómur Reykjaness'
| 'Héraðsdómur Vesturlands'
| 'Héraðsdómur Vestfjarða'
| 'Héraðsdómur Norðurlands vestra'
| 'Héraðsdómur Norðurlands eystra'
| 'Héraðsdómur Austurlands'
| 'Héraðsdómur Suðurlands'

// TODO: Move to databas
const DistrictCourtLocation: Record<DistrictCourts, string> = {
'Héraðsdómur Reykjavíkur': 'Dómhúsið við Lækjartorg, Reykjavík',
'Héraðsdómur Reykjaness': 'Fjarðargata 9, Hafnarfirði',
'Héraðsdómur Vesturlands': 'Bjarnarbraut 8, Borgarnesi',
'Héraðsdómur Vestfjarða': 'Hafnarstræti 9, Ísafirði',
'Héraðsdómur Norðurlands vestra': 'Skagfirðingabraut 21, Sauðárkróki',
'Héraðsdómur Norðurlands eystra': 'Hafnarstræti 107, 4. hæð, Akureyri',
'Héraðsdómur Austurlands': 'Lyngás 15, Egilsstöðum',
'Héraðsdómur Suðurlands': 'Austurvegur 4, Selfossi',
}

export const createSubpoena = (
theCase: Case,
defendant: Defendant,
Expand Down Expand Up @@ -71,6 +50,11 @@ export const createSubpoena = (
doc.on('data', (chunk) => sinc.push(chunk))

setTitle(doc, formatMessage(strings.title))

if (dateLog) {
addEmptyLines(doc, 5)
}

addNormalText(doc, `${theCase.court?.name}`, 'Times-Bold', true)

addNormalRightAlignedText(
Expand All @@ -86,7 +70,7 @@ export const createSubpoena = (
if (theCase.court?.name) {
addNormalText(
doc,
DistrictCourtLocation[theCase.court.name as DistrictCourts],
theCase.court.address || 'Ekki skráð', // the latter shouldn't happen, if it does we have an problem with the court data
'Times-Roman',
)
}
Expand Down Expand Up @@ -170,6 +154,15 @@ export const createSubpoena = (

addFooter(doc)

if (dateLog) {
addConfirmation(doc, {
actor: theCase.judge?.name || '',
title: theCase.judge?.title,
institution: theCase.judge?.institution?.name || '',
date: dateLog.created,
})
}

doc.end()

return new Promise<Buffer>((resolve) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import {
prosecutorRule,
publicProsecutorStaffRule,
} from '../../guards'
import { CaseEvent, EventService } from '../event'
import { EventService } from '../event'
import { UserService } from '../user'
import { CreateCaseDto } from './dto/createCase.dto'
import { TransitionCaseDto } from './dto/transitionCase.dto'
Expand Down Expand Up @@ -99,8 +99,8 @@ import {
prosecutorUpdateRule,
publicProsecutorStaffUpdateRule,
} from './guards/rolesRules'
import { CaseInterceptor } from './interceptors/case.interceptor'
import { CaseListInterceptor } from './interceptors/caseList.interceptor'
import { CompletedAppealAccessedInterceptor } from './interceptors/completedAppealAccessed.interceptor'
import { Case } from './models/case.model'
import { SignatureConfirmationResponse } from './models/signatureConfirmation.response'
import { transitionCase } from './state/case.state'
Expand Down Expand Up @@ -465,7 +465,7 @@ export class CaseController {
)
@Get('case/:caseId')
@ApiOkResponse({ type: Case, description: 'Gets an existing case' })
@UseInterceptors(CaseInterceptor)
@UseInterceptors(CompletedAppealAccessedInterceptor)
getById(@Param('caseId') caseId: string, @CurrentCase() theCase: Case): Case {
this.logger.debug(`Getting case ${caseId} by id`)

Expand Down Expand Up @@ -545,6 +545,7 @@ export class CaseController {
@RolesRules(
prosecutorRule,
prosecutorRepresentativeRule,
publicProsecutorStaffRule,
districtCourtJudgeRule,
districtCourtRegistrarRule,
districtCourtAssistantRule,
Expand Down Expand Up @@ -700,6 +701,7 @@ export class CaseController {
@RolesRules(
prosecutorRule,
prosecutorRepresentativeRule,
publicProsecutorStaffRule,
districtCourtJudgeRule,
districtCourtRegistrarRule,
districtCourtAssistantRule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import {
import { AwsS3Service } from '../aws-s3'
import { CourtService } from '../court'
import { Defendant, DefendantService } from '../defendant'
import { CaseEvent, EventService } from '../event'
import { EventService } from '../event'
import { EventLog, EventLogService } from '../event-log'
import { CaseFile, FileService } from '../file'
import { IndictmentCount } from '../indictment-count'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
CaseDecision,
CaseState,
CaseType,
DateType,
getIndictmentVerdictAppealDeadline,
IndictmentCaseReviewDecision,
InstitutionType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class LimitedAccessCaseExistsGuard implements CanActivate {
async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest()

const caseId = request.params.caseId
const caseId: string = request.params.caseId

if (!caseId) {
throw new BadRequestException('Missing case id')
Expand Down
Loading

0 comments on commit 59de629

Please sign in to comment.