-
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/web-rss-event-feed-single-digit-dates
- Loading branch information
Showing
37 changed files
with
971 additions
and
247 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
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
63 changes: 63 additions & 0 deletions
63
...stem/backend/src/app/modules/case/interceptors/defendantIndictmentAccessed.interceptor.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,63 @@ | ||
import { | ||
CallHandler, | ||
ExecutionContext, | ||
Injectable, | ||
NestInterceptor, | ||
} from '@nestjs/common' | ||
|
||
import { | ||
DefendantEventType, | ||
isIndictmentCase, | ||
isPrisonAdminUser, | ||
User, | ||
} from '@island.is/judicial-system/types' | ||
|
||
import { DefendantEventLog, DefendantService } from '../../defendant' | ||
import { Case } from '../models/case.model' | ||
|
||
const hasValidOpenByPrisonAdminEvent = ( | ||
defendantEventLogs: DefendantEventLog[], | ||
) => { | ||
const sentToPrisonAdminDate = DefendantEventLog.getDefendantEventLogTypeDate({ | ||
defendantEventLogs, | ||
eventType: DefendantEventType.SENT_TO_PRISON_ADMIN, | ||
}) | ||
const openedByPrisonAdminDate = | ||
DefendantEventLog.getDefendantEventLogTypeDate({ | ||
defendantEventLogs, | ||
eventType: DefendantEventType.OPENED_BY_PRISON_ADMIN, | ||
}) | ||
return ( | ||
sentToPrisonAdminDate && | ||
openedByPrisonAdminDate && | ||
sentToPrisonAdminDate <= openedByPrisonAdminDate | ||
) | ||
} | ||
|
||
@Injectable() | ||
export class DefendantIndictmentAccessedInterceptor implements NestInterceptor { | ||
constructor(private readonly defendantService: DefendantService) {} | ||
|
||
intercept(context: ExecutionContext, next: CallHandler) { | ||
const request = context.switchToHttp().getRequest() | ||
const user: User = request.user | ||
const theCase: Case = request.case | ||
|
||
if (isIndictmentCase(theCase.type) && isPrisonAdminUser(user)) { | ||
const defendantsIndictmentNotOpened = theCase.defendants?.filter( | ||
({ isSentToPrisonAdmin, eventLogs = [] }) => | ||
isSentToPrisonAdmin && !hasValidOpenByPrisonAdminEvent(eventLogs), | ||
) | ||
|
||
// create new events for all defendants that prison admin has not accessed according to defendant event logs | ||
defendantsIndictmentNotOpened?.forEach((defendant) => | ||
this.defendantService.createDefendantEvent({ | ||
caseId: theCase.id, | ||
defendantId: defendant.id, | ||
eventType: DefendantEventType.OPENED_BY_PRISON_ADMIN, | ||
}), | ||
) | ||
} | ||
return next.handle() | ||
} | ||
} |
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
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
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.