Skip to content

Commit

Permalink
Merge branch 'main' into chore/inao-cem-income-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Dec 12, 2024
2 parents 4c90cf1 + 32a256e commit da567fa
Show file tree
Hide file tree
Showing 198 changed files with 2,929 additions and 2,749 deletions.
68 changes: 67 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,70 @@ apps/**/index.html
# E2E outputs
test-results/
playwright-report/
tmp-sessions/
tmp-sessions/

# React Native

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.dSYM.zip
*.xcuserstate
**/.xcode.env.local
ios/*.cer
ios/*.certSigningRequest
ios/*.mobileprovision
ios/*.p12

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof
.cxx/
*.keystore
!debug.keystore
google-services.json
service-account.json

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

**/fastlane/report.xml
**/fastlane/Preview.html
**/fastlane/screenshots
**/fastlane/test_output

# Bundle artifact
*.jsbundle

# Ruby / CocoaPods
**/Pods/
**/vendor/bundle/

# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

# testing
/coverage
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { UserService } from '../user/user.service'
import type { User as AuthUser } from '@island.is/auth-nest-tools'
import { ExplicitFlight } from './dto/ExplicitFlight.dto'
import { CreateSuperExplicitDiscountCodeParams } from './dto'
import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'

interface CachedDiscount {
user: User
Expand Down Expand Up @@ -47,6 +49,8 @@ export class DiscountService {

@InjectModel(ExplicitCode)
private explicitModel: typeof ExplicitCode,
@Inject(LOGGER_PROVIDER)
private readonly logger: Logger,

private readonly userService: UserService,
) {}
Expand Down Expand Up @@ -197,13 +201,19 @@ export class DiscountService {
unConnectedFlights: Flight[] | ExplicitFlight[],
isExplicit: boolean,
flightLegs = 1,
isManual?: boolean,
): Promise<Array<Discount> | null> {
const user = await this.userService.getUserInfoByNationalId(
nationalId,
auth,
isExplicit,
isManual,
)

if (!user) {
this.logger.warn('User by national id not found for explicit discount.', {
category: 'ads-backend',
})
return null
}
// overwrite credit since validation may return 0 depending on what the problem is
Expand All @@ -212,10 +222,19 @@ export class DiscountService {
user.fund.credit = 2 //making sure we can get flight from and to
user.fund.total = 2
} else {
this.logger.warn(
`User fund used requirements not met: ${user.fund.used}.`,
{
category: 'ads-backend',
},
)
return null
}
}
if (user.fund.credit === 0 && user.fund.total !== undefined) {
this.logger.warn(`User fund no credit, has total: ${user.fund.total}.`, {
category: 'ads-backend',
})
return null
}

Expand Down Expand Up @@ -477,6 +496,7 @@ export class DiscountService {
],
}

const isManual = true
const discount = await this.createExplicitDiscountCode(
auth,
body.nationalId,
Expand All @@ -487,6 +507,7 @@ export class DiscountService {
body.needsConnectionFlight ? [flight] : [],
isExplicit,
1,
isManual,
)
if (!discount) {
throw new Error(`Could not create explicit discount`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ describe('DiscountService', () => {
{
provide: LOGGER_PROVIDER,
useClass: jest.fn(() => ({
error: () => ({}),
error: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
})),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const ONE_WEEK = 604800 // seconds
const CACHE_KEY = 'userService'
const MAX_AGE_LIMIT = 18

const DEFAULT_FUND: Fund = {
credit: 2,
total: 2,
used: 0,
}

interface CustodianCache {
custodians: Array<NationalRegistryUser | null>
}
Expand All @@ -42,14 +48,15 @@ export class UserService {
private async getFund(
user: NationalRegistryUser,
auth?: AuthUser,
isManual?: boolean,
): Promise<Fund> {
const { used, unused, total } =
await this.flightService.countThisYearsFlightLegsByNationalId(
user.nationalId,
)
let meetsADSRequirements = false

if (this.flightService.isADSPostalCode(user.postalcode)) {
if (this.flightService.isADSPostalCode(user.postalcode) || isManual) {
meetsADSRequirements = true
} else if (info(user.nationalId).age < MAX_AGE_LIMIT) {
// NationalId is a minor and doesn't live in ADS postal codes.
Expand Down Expand Up @@ -95,20 +102,33 @@ export class UserService {
nationalId: string,
model: new (user: NationalRegistryUser, fund: Fund) => T,
auth: AuthUser,
isExplicit?: boolean,
isManual?: boolean,
): Promise<T | null> {
const user = await this.nationalRegistryService.getUser(nationalId, auth)
if (!user) {
return null
}
const fund = await this.getFund(user, auth)
if (isExplicit) {
return new model(user, DEFAULT_FUND)
}
const fund = await this.getFund(user, auth, isManual)
return new model(user, fund)
}

async getUserInfoByNationalId(
nationalId: string,
auth: AuthUser,
isExplicit?: boolean,
isManual?: boolean,
): Promise<User | null> {
return this.getUserByNationalId<User>(nationalId, User, auth)
return this.getUserByNationalId<User>(
nationalId,
User,
auth,
isExplicit,
isManual,
)
}

async getMultipleUsersByNationalIdArray(
Expand Down
2 changes: 2 additions & 0 deletions apps/judicial-system/backend/infra/judicial-system-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export const serviceSetup = (): ServiceBuilder<'judicial-system-backend'> =>
EMAIL_FROM_NAME: '/k8s/judicial-system/EMAIL_FROM_NAME',
EMAIL_REPLY_TO: '/k8s/judicial-system/EMAIL_REPLY_TO',
EMAIL_REPLY_TO_NAME: '/k8s/judicial-system/EMAIL_REPLY_TO_NAME',
POLICE_INSTITUTIONS_EMAILS:
'/k8s/judicial-system/POLICE_INSTITUTIONS_EMAILS',
PRISON_EMAIL: '/k8s/judicial-system/PRISON_EMAIL',
PRISON_ADMIN_EMAIL: '/k8s/judicial-system/PRISON_ADMIN_EMAIL',
PRISON_ADMIN_INDICTMENT_EMAILS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const notifications = {
}),
emailWhitelistDomains: defineMessage({
id: 'judicial.system.backend:notifications.email_whitelist_domains',
defaultMessage: 'omnitrix.is,kolibri.is',
defaultMessage: 'omnitrix.is,kolibri.is,dummy.dd',
description: 'Notað til að tilgreina hvort póstfang sé í hvítlista',
}),
readyForCourt: defineMessages({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ export class InternalCaseService {
? {
name: theCase.prosecutor.name,
nationalId: theCase.prosecutor.nationalId,
email: theCase.prosecutor.email,
}
: undefined,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ describe('InternalCaseController - Deliver indictment info to court', () => {
{ eventType: EventType.INDICTMENT_CONFIRMED, created: indictmentDate },
],
defendants: [{ name: 'Test Ákærði', nationalId: '1234567890' }],
prosecutor: { name: 'Test Sækjandi', nationalId: '0101010101' },
prosecutor: {
name: 'Test Sækjandi',
nationalId: '0101010101',
email: '[email protected]',
},
} as Case

let mockCourtService: CourtService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ export class CourtService {
)

const isIndictment = isIndictmentCase(type)
const policeCaseNumber = policeCaseNumbers[0]
? policeCaseNumbers[0].replace(/-/g, '')
: ''

return await this.courtClientService.createCase(courtId, {
caseType: isIndictment ? 'S - Ákærumál' : 'R - Rannsóknarmál',
Expand All @@ -344,7 +347,7 @@ export class CourtService {
receivalDate: formatISO(receivalDate, { representation: 'date' }),
basedOn: isIndictment ? 'Sakamál' : 'Rannsóknarhagsmunir',
// TODO: pass in all policeCaseNumbers when CourtService supports it
sourceNumber: policeCaseNumbers[0] ? policeCaseNumbers[0] : '',
sourceNumber: policeCaseNumber,
})
} catch (reason) {
if (reason instanceof ServiceUnavailableException) {
Expand Down Expand Up @@ -569,14 +572,17 @@ export class CourtService {
policeCaseNumber?: string,
subtypes?: string[],
defendants?: { name?: string; nationalId?: string }[],
prosecutor?: { name?: string; nationalId?: string },
prosecutor?: { name?: string; nationalId?: string; email?: string },
): Promise<unknown> {
try {
const subject = `${courtName} - ${courtCaseNumber} - upplýsingar`

const sanitizedPoliceCaseNumber = policeCaseNumber?.replace(/-/g, '')

const content = JSON.stringify({
receivedByCourtDate,
indictmentDate,
policeCaseNumber,
sanitizedPoliceCaseNumber,
subtypes,
defendants,
prosecutor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('CourtService - Create court case', () => {
status: 'Skráð',
receivalDate: formatISO(receivalDate, { representation: 'date' }),
basedOn: 'Rannsóknarhagsmunir',
sourceNumber: policeCaseNumbers[0],
sourceNumber: policeCaseNumbers[0].replace(/-/g, ''),
},
)
})
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('CourtService - Create court case', () => {
status: 'Skráð',
receivalDate: formatISO(receivalDate, { representation: 'date' }),
basedOn: 'Sakamál',
sourceNumber: policeCaseNumbers[0],
sourceNumber: policeCaseNumbers[0].replace(/-/g, ''),
},
)
})
Expand Down Expand Up @@ -183,7 +183,7 @@ describe('CourtService - Create court case', () => {
status: 'Skráð',
receivalDate: formatISO(receivalDate, { representation: 'date' }),
basedOn: 'Rannsóknarhagsmunir',
sourceNumber: policeCaseNumbers[0],
sourceNumber: policeCaseNumbers[0].replace(/-/g, ''),
})
})
})
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('CourtService - Create court case', () => {
status: 'Skráð',
receivalDate: formatISO(receivalDate, { representation: 'date' }),
basedOn: 'Rannsóknarhagsmunir',
sourceNumber: policeCaseNumbers[0],
sourceNumber: policeCaseNumbers[0].replace(/-/g, ''),
})
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Module } from '@nestjs/common'
import { forwardRef, Module } from '@nestjs/common'
import { SequelizeModule } from '@nestjs/sequelize'

import { MessageModule } from '@island.is/judicial-system/message'

import { EventLog } from './models/eventLog.model'
import { EventLogController } from './eventLog.controller'
import { EventLogService } from './eventLog.service'

@Module({
imports: [SequelizeModule.forFeature([EventLog])],
imports: [
forwardRef(() => MessageModule),
SequelizeModule.forFeature([EventLog]),
],
providers: [EventLogService],
exports: [EventLogService],
controllers: [EventLogController],
Expand Down
Loading

0 comments on commit da567fa

Please sign in to comment.