-
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.
feat(j-s): Add received date and new table state tag for indictment p…
…rison cases (#17279) * feat(j-s): adding interceptor with when prison admin fetches indictment * feat(j-s): Show openend by prison admin date + formatting * fix(j-s): show received tag in prison cases when openendByPrisonAdminDate is populated * refactor(j-s): Use case tags * refactor(j-s): small fixes * chore: nx format:write update dirty files * refactor(j-s): address self-review * fix(j-s): add user role in get by id test * chore: nx format:write update dirty files --------- Co-authored-by: andes-it <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
07f6c77
commit 72a8ce9
Showing
17 changed files
with
187 additions
and
19 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
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.