Skip to content

Nodejs script that handles documents from MinElev

License

Notifications You must be signed in to change notification settings

vtfk/minelev-robot

Repository files navigation

minelev-robot

Nodejs script that handles documents from MinElev

Definitions

Flow

A definition of jobs that should be run for a given document-type. e.g how to handle elevsamtale

See flow dir for current flows and their defined jobs

Job

A single job that can be run in a flow. e.g archive a document Result of the job is stored in flowStatus

See jobs dir for available jobs

FlowStatus

Object that is created on a single document. Keeps tracks of which jobs have run, and result from the job If a job is not enabled - it will not be present in flowstatus

Scripts

npm run start

Runs ./index.js - which is the main "robot", and does the following:

npm run status-alert

Creates a status-report and sends it to Teams-channel

npm run delete-files

Deletes files in 'finished' and 'copies' directories

npm run setup

Creates needed directories based on your .env preferences (see #setup)

Jobs (sorted in the same way the are run if they are enabled in a flow)

Almost all jobs can be tailored to suit a flow's needs (see the flows for examples/mappers)

KRR

Fetches info about an ssn from Kontakt og reservasjonsregisteret. Used mainly for getting preferred language for a person.

FREG

Fetches info about an ssn from Folkeregisteret. Used mainly for getting parents for a person.

SyncElevmappe

Creates/updates elevmappe in archive.

AddParentsIfUnder18

Creates/updates privatepersons in archive for ssn's parents if ssn is under 18 of age, and if parents are found in folkeregisteret. Used when you need to send copy of document to guardians/parents.

SyncEnterprise

Creates/updates enterprise in archive based on data fetched from Brønnøysundsregisteret (on enterprisenumber). Used when sending document to enterprise (yff-bekreftelse-bedrift)

CreatePdf

Creates a pdf and returns it in base64-format. Base64 is saved as a separate txt-file in queue

Special case: If recipient have address block or has svarut exception - addresses are removed from the pdfs

Archive

Archives document in archive.

SvarUt

Sends archived document on svarut to recipients defined on archived document.

Special cases: Checks recipients in the following order:

  1. Does recipient have address block => do not send on Svarut, send internal note to school that letter must be delivered to student manually
  2. Does recipient exists in SVARUT_EXCEPTIONS => do not send on Svarut, send internal note to school that letter must be delivered to student manually
  3. Does recipient have illegal zipCode (not 4 digits, set to 9999), or zipPlace set to UKJENT => do not send on Svarut, send internal note to school that letter must be delivered to student manually
  4. Does student not have registered parents and is under 18 => do not send on Svarut, send internal note to school that letter must be distributed manually to student and parents

GetContactTeachers

Fetches contact-teachers for a student from PIFU-api. Used when you need to send email alerts to students contact teachers.

SendEmail

Sends email to given recipients in the flows job-mapper. Can send any email to any recipent.

UpdateDocumentStatus

Updates status on the document in the DB it was fetched from in the beginning. The statuses are used in frontend for users to see status on the document. Typically "queued - timestamp", "archived - timestamp", "sent - timestamp".

Statistics

Creates anonymous statistics element in shared statistics database

FailOnPurpose

Makes the flow fail - simply used for testing purposes when you need the flow to fail

Setup and development

  1. Clone project
  2. npm i
  3. Create .env with values from .env
  4. Run npm run setup
  5. If production env - Create tasks that trigger different scripts as you like (e.g npm run start, npm run status-alert, npm run delete-files)

.env

MONGODB_CONNECTION_STRING="connection string to Mongodb"
MONGODB_DB="name of database"
MONGODB_COLLECTION="name of collection"
DOCUMENTS_PER_RUN="how many documents to you want to fetch from DB each run"
ENCRYPTION_KEY="super secret key"
RETRY_INTERVALS_MINUTES="5,30,60,60,60" # Intervals between retries for a document in minutes
KRR_URL="url to KRR api"
KRR_KEY="KRR KEEEY"
APPREG_CLIENT_SECRET="client secret from app registration"
APPREG_TENANT_ID="tenant id for app registration"
APPREG_CLIENT_ID="client id for app registration"
FREG_API_SCOPE="skup"
FREG_URL="url to FREG api"
ARCHIVE_URL="url to ARCHIVE api"
ARCHIVE_API_SCOPE="skupi"
PDF_URL="url for pdf-generator api"
PDF_KEY="keyyyy"
PIFU_JWT_SECRET="PIFU secret for signing jwt"
PIFU_URL="url to PIFU api"
MAIL_URL="https://url-to-mail-api.com?subscription-key=subscription-key-for-mail-api"
MAIL_KEY="MAIL kyeyeyey"
MAIL_TEMPLATE_NAME="du vil vel ha en template?"
MINELEV_URL="url to minelev frontend"
STATISTICS_KEY="key for statistics api"
STATISTICS_URL="url for statistics api"
STATISTICS_COMPANY="kortkode for sektor"
TEAMS_WEBHOOK_URL="teams webhook url" # Optional - if you want error and warn to teams channel
TEAMS_STATUS_WEBHOOK_URL="teams webhook url" # Required when running script "status-alert". Where to send status-alert
PAPERTRAIL_HOST="papertrail host url" # Optional - if you want logging to papertrail
PAPERTRAIL_TOKEN="papertrail token" # Optiional - if you want logging to papertrail
SVARUT_EXCEPTIONS="12345678910,12345678911" # comma-separated ssn's that should not receive letter's on svarut

Notes to remember stuff...

Samtale og notat skal ikke sendes ut (ikke-samtale skal faktisk sendes ut...)

About

Nodejs script that handles documents from MinElev

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •