Skip to content

Commit

Permalink
hanskataan tyhjä lähetys
Browse files Browse the repository at this point in the history
  • Loading branch information
marjakari committed Jan 25, 2024
1 parent 8de7cc5 commit a2ef687
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ object LocalUtil {
omistaja: String
*/
//kantaOperaatiot.tallennaViesti()
// viesti lähetystunnuksella
// viesti ilman lähetystunnusta

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class LoginResource {

@GetMapping(path = Array(RaportointiAPIConstants.LOGIN_PATH))
def redirect(response: HttpServletResponse): Unit = {
response.sendRedirect(RaportointiAPIConstants.HEALTHCHECK_PATH)
response.sendRedirect("localhost:3000")
}
}
27 changes: 0 additions & 27 deletions viestinvalitys-raportointi/middleware.ts

This file was deleted.

9 changes: 8 additions & 1 deletion viestinvalitys-raportointi/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import type { Metadata } from 'next'
import { AppRouterCacheProvider } from '@mui/material-nextjs/v13-appRouter';
import './globals.css'
import Link from 'next/link';
import { Roboto } from 'next/font/google'

const roboto = Roboto({
weight: ['400', '500'],
display: 'swap',
subsets: ['latin'],
})

export const metadata: Metadata = {
title: 'Viestinvälityspalvelun raportointi',
Expand All @@ -14,7 +21,7 @@ export default function RootLayout({
children: React.ReactNode
}) {
return (
<html lang="fi">
<html lang="fi" className={roboto.className}>
<body>
<header>
<nav>
Expand Down
14 changes: 11 additions & 3 deletions viestinvalitys-raportointi/src/app/lib/data.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { headers } from 'next/headers'
import { cookies, headers } from 'next/headers'
import { LahetysHakuParams } from './types'
import { apiUrl, loginUrl } from './configurations'
import { apiUrl, cookieName, loginUrl } from './configurations'
import { redirect } from 'next/navigation'

// TODO apuwrapperi headerien asettamiseen
export async function fetchLahetykset(hakuParams: LahetysHakuParams) {
console.info(hakuParams)
const sessionCookie = cookies().get(cookieName)
console.info(sessionCookie)
const headersInstance = headers()
console.info(headersInstance.get('cookie'))
if (sessionCookie === undefined) {
console.info('no session cookie, redirect to login')
redirect(loginUrl)
}
console.info(hakuParams)
const fetchUrlBase = `${apiUrl}/lahetykset/lista?enintaan=2`
const fetchParams = hakuParams.seuraavatAlkaen ? `&alkaen=${hakuParams.seuraavatAlkaen}` : ''
console.info(fetchUrlBase.concat(fetchParams))
Expand All @@ -16,6 +23,7 @@ export async function fetchLahetykset(hakuParams: LahetysHakuParams) {
console.info(res.status)
if (!res.ok) {
if(res.status===401) {
console.info('http 401, redirect to login')
redirect(loginUrl)
}
// This will activate the closest `error.js` Error Boundary
Expand Down
9 changes: 7 additions & 2 deletions viestinvalitys-raportointi/src/app/lib/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from 'vitest'
import { getLahetysStatus, getVastaanottajatPerStatus } from './util';
import { getLahetysStatus, getVastaanottajatPerStatus, lahetyksenStatus } from './util';
import { Status, VastaanotonTila, VastaanottajaTila } from './types';

const onnistunutTila = [VastaanotonTila.DELIVERY]
Expand Down Expand Up @@ -42,4 +42,9 @@ test('Vastaavassa tilassa olevien viestien lukumäärät summataan', () => {
vastaanottajaLkm: 2
}
]))).toEqual(3);
});
});

test('Tyhjä lähetys osataan käsitellä'), () => {
expect(lahetyksenStatus(undefined)).toEqual('-')
expect(lahetyksenStatus(undefined)).toEqual('-')
}
4 changes: 2 additions & 2 deletions viestinvalitys-raportointi/src/app/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const getLahetyksenVastaanottajia = (tilat: VastaanottajaTila[]): number
{ return a + b;})
}

export const lahetyksenStatus = (tilat: VastaanottajaTila[]): string => {
if(tilat.length<1) {
export const lahetyksenStatus = (tilat: VastaanottajaTila[] | undefined): string => {
if(!tilat || tilat.length<1) {
return '-'
}
const status = getVastaanottajatPerStatus(tilat)+'/'+getLahetyksenVastaanottajia(tilat)+ ' viestin lähetys ' + getLahetysStatus(tilat.map(tila => tila.vastaanottotila))
Expand Down

0 comments on commit a2ef687

Please sign in to comment.