-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/admin-paper-signature-upload
- Loading branch information
Showing
45 changed files
with
831 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
#!/bin/bash | ||
|
||
source_env .env.secret | ||
declare -A TIME_KEEP | ||
# t <target> - get elapsed time in milliseconds since first invocation (with nanosecond precision) | ||
t() { | ||
if [[ -v TIME_KEEP[$1] ]]; then | ||
D="$(date +%N)" | ||
echo "$(((${D##0} - ${TIME_KEEP[$1]##0}) / 1000000))" | ||
else | ||
TIME_KEEP[$1]=$(date +%N) | ||
fi | ||
} | ||
set -euo pipefail | ||
t root | ||
|
||
# global | ||
|
||
export NODE_OPTIONS="--max-old-space-size=8192" | ||
|
||
# MacOS specific | ||
|
||
export REDIS_CLUSTER_IP=0.0.0.0 | ||
|
||
# developer custom direnv config | ||
|
||
source_env_if_exists .envrc.private | ||
if [[ "${IS_DEVCONTAINER:-}" == true ]]; then | ||
source_env_if_exists .devcontainer/.envrc.private | ||
fi | ||
|
||
# Podman compatibility | ||
# NOTE: Exits direnv if user is using docker. | ||
source_env_if_exists .envrc.podman | ||
|
||
source_env_if_exists .envrc.kube | ||
# Developer custom direnv config | ||
for envrc in .envrc.* $(if [[ "${IS_DEVCONTAINER:-}" == true ]]; then echo .devcontainer/.envrc.private; fi); do | ||
t "${envrc}" | ||
source_env_if_exists "$envrc" | ||
T_TOTAL=$(t "${envrc}") | ||
if ((T_TOTAL > 100)); then | ||
echo -e "\033[93mSetting '$envrc' took ${T_TOTAL}ms\033[0m" | ||
fi | ||
done | ||
|
||
echo "Loading .envrc took $(t root)ms" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
apps/judicial-system/backend/src/app/formatters/serviceCertificatePdf.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import PDFDocument from 'pdfkit' | ||
|
||
import { FormatMessage } from '@island.is/cms-translations' | ||
|
||
import { | ||
capitalize, | ||
formatDate, | ||
formatDOB, | ||
getWordByGender, | ||
Word, | ||
} from '@island.is/judicial-system/formatters' | ||
import { ServiceStatus, SubpoenaType } from '@island.is/judicial-system/types' | ||
|
||
import { serviceCertificate as strings } from '../messages' | ||
import { Case } from '../modules/case' | ||
import { Defendant } from '../modules/defendant' | ||
import { Subpoena } from '../modules/subpoena' | ||
import { | ||
addEmptyLines, | ||
addFooter, | ||
addHugeHeading, | ||
addMediumCenteredText, | ||
addNormalCenteredText, | ||
addNormalText, | ||
setTitle, | ||
} from './pdfHelpers' | ||
|
||
const getSubpoenaType = (subpoenaType?: SubpoenaType): string => { | ||
switch (subpoenaType) { | ||
case SubpoenaType.ABSENCE: | ||
return 'Útivistarfyrirkall' | ||
case SubpoenaType.ARREST: | ||
return 'Handtökufyrirkall' | ||
default: | ||
// Should never happen | ||
return 'Ekki skráð' | ||
} | ||
} | ||
|
||
export const createServiceCertificate = ( | ||
theCase: Case, | ||
defendant: Defendant, | ||
subpoena: Subpoena, | ||
formatMessage: FormatMessage, | ||
): Promise<Buffer> => { | ||
const doc = new PDFDocument({ | ||
size: 'A4', | ||
margins: { | ||
top: 40, | ||
bottom: 60, | ||
left: 50, | ||
right: 50, | ||
}, | ||
bufferPages: true, | ||
}) | ||
|
||
const sinc: Buffer[] = [] | ||
|
||
doc.on('data', (chunk) => sinc.push(chunk)) | ||
|
||
setTitle(doc, formatMessage(strings.title)) | ||
|
||
addHugeHeading(doc, formatMessage(strings.title).toUpperCase(), 'Times-Bold') | ||
addMediumCenteredText( | ||
doc, | ||
`Mál nr. ${theCase.courtCaseNumber || ''}`, | ||
'Times-Bold', | ||
) | ||
addNormalCenteredText(doc, theCase.court?.name || '', 'Times-Bold') | ||
|
||
addEmptyLines(doc, 2) | ||
|
||
addMediumCenteredText( | ||
doc, | ||
`Birting tókst ${ | ||
subpoena.serviceDate ? formatDate(subpoena.serviceDate, 'PPp') : '' | ||
}`, | ||
'Times-Bold', | ||
) | ||
|
||
addEmptyLines(doc) | ||
|
||
addNormalText(doc, 'Birtingaraðili: ', 'Times-Bold', true) | ||
addNormalText( | ||
doc, | ||
subpoena.serviceStatus === ServiceStatus.ELECTRONICALLY | ||
? 'Rafrænt pósthólf island.is' | ||
: subpoena.servedBy || '', | ||
'Times-Roman', | ||
) | ||
|
||
if (subpoena.serviceStatus !== ServiceStatus.ELECTRONICALLY) { | ||
addNormalText(doc, 'Athugasemd: ', 'Times-Bold', true) | ||
addNormalText( | ||
doc, | ||
subpoena.serviceStatus === ServiceStatus.DEFENDER | ||
? `Birt fyrir verjanda ${ | ||
defendant.defenderName ? `- ${defendant.defenderName}` : '' | ||
}` | ||
: subpoena.comment || '', | ||
'Times-Roman', | ||
) | ||
} | ||
|
||
addEmptyLines(doc, 2) | ||
|
||
addNormalText( | ||
doc, | ||
`${capitalize(getWordByGender(Word.AKAERDI, defendant.gender))}: `, | ||
'Times-Bold', | ||
true, | ||
) | ||
addNormalText( | ||
doc, | ||
defendant.name && defendant.nationalId && defendant.address | ||
? `${defendant.name}, ${formatDOB( | ||
defendant.nationalId, | ||
defendant.noNationalId, | ||
)}, ${defendant.address}` | ||
: 'Ekki skráður', | ||
'Times-Roman', | ||
) | ||
|
||
addEmptyLines(doc, 2) | ||
|
||
addNormalText(doc, 'Ákærandi: ', 'Times-Bold', true) | ||
addNormalText( | ||
doc, | ||
theCase.prosecutor?.institution | ||
? theCase.prosecutor.institution.name | ||
: 'Ekki skráður', | ||
'Times-Roman', | ||
) | ||
|
||
addNormalText(doc, 'Dómari: ', 'Times-Bold', true) | ||
addNormalText( | ||
doc, | ||
theCase.judge ? theCase.judge.name : 'Ekki skráður', | ||
'Times-Roman', | ||
) | ||
|
||
addEmptyLines(doc) | ||
|
||
addNormalText(doc, 'Þingfesting: ', 'Times-Bold', true) | ||
addNormalText( | ||
doc, | ||
formatDate( | ||
subpoena.arraignmentDate ? new Date(subpoena.arraignmentDate) : null, | ||
'Pp', | ||
) || 'Ekki skráð', | ||
'Times-Roman', | ||
) | ||
|
||
addNormalText(doc, 'Staður: ', 'Times-Bold', true) | ||
addNormalText(doc, subpoena.location || 'Ekki skráður', 'Times-Roman') | ||
|
||
addNormalText(doc, 'Tegund fyrirkalls: ', 'Times-Bold', true) | ||
addNormalText(doc, getSubpoenaType(defendant.subpoenaType), 'Times-Roman') | ||
|
||
addFooter(doc) | ||
doc.end() | ||
|
||
return new Promise<Buffer>((resolve) => | ||
doc.on('end', () => resolve(Buffer.concat(sinc))), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
apps/judicial-system/backend/src/app/messages/pdfServiceCertificate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defineMessage } from '@formatjs/intl' | ||
|
||
export const serviceCertificate = { | ||
title: defineMessage({ | ||
id: 'judicial.system.backend:pdf.service_certificate.title', | ||
defaultMessage: 'Birtingarvottorð', | ||
description: 'Notaður sem titill á birtingarvottorði.', | ||
}), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.