-
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): Connect case files to defendant or civil claimant
- Loading branch information
Showing
14 changed files
with
318 additions
and
31 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
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
44 changes: 44 additions & 0 deletions
44
apps/judicial-system/backend/migrations/20241122091513-update-case-file.js
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,44 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.sequelize.transaction(async (t) => { | ||
await queryInterface.addColumn( | ||
'case_file', | ||
'defendant_id', | ||
{ | ||
type: Sequelize.UUID, | ||
references: { | ||
model: 'defendant', | ||
key: 'id', | ||
}, | ||
allowNull: true, | ||
}, | ||
{ transaction: t }, | ||
) | ||
await queryInterface.addColumn( | ||
'case_file', | ||
'civil_claimant_id', | ||
{ | ||
type: Sequelize.UUID, | ||
references: { | ||
model: 'civil_claimant', | ||
key: 'id', | ||
}, | ||
allowNull: true, | ||
}, | ||
{ transaction: t }, | ||
) | ||
}) | ||
}, | ||
down: (queryInterface) => { | ||
return queryInterface.sequelize.transaction(async (t) => { | ||
await queryInterface.removeColumn('case_file', 'civil_claimant_id', { | ||
transaction: t, | ||
}) | ||
await queryInterface.removeColumn('case_file', 'defendant_id', { | ||
transaction: t, | ||
}) | ||
}) | ||
}, | ||
} |
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
55 changes: 55 additions & 0 deletions
55
apps/judicial-system/backend/src/app/modules/file/guards/writeCaseFile.guard.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,55 @@ | ||
import { | ||
BadRequestException, | ||
CanActivate, | ||
ExecutionContext, | ||
Injectable, | ||
InternalServerErrorException, | ||
} from '@nestjs/common' | ||
|
||
import { CaseFileCategory, User } from '@island.is/judicial-system/types' | ||
|
||
import { Case } from '../../case' | ||
|
||
@Injectable() | ||
export class WriteCaseFileGuard implements CanActivate { | ||
canActivate(context: ExecutionContext): boolean { | ||
const request = context.switchToHttp().getRequest() | ||
|
||
const user: User = request.user | ||
const theCase: Case = request.case | ||
const defendant = request.defendant | ||
const civilClaimant = request.civilClaimant | ||
|
||
if (!theCase) { | ||
throw new InternalServerErrorException('Missing case') | ||
} | ||
|
||
if (!user) { | ||
throw new InternalServerErrorException('Missing user') | ||
} | ||
|
||
// The case file category is either in the request body (creating case file) | ||
// or in the case file (deleting case file) | ||
const caseFileCategory: CaseFileCategory = | ||
request.body?.category ?? request.caseFile?.category | ||
|
||
if (!caseFileCategory) { | ||
throw new InternalServerErrorException('Missing case file category') | ||
} | ||
|
||
if ( | ||
caseFileCategory === CaseFileCategory.SENT_TO_PRISON_ADMIN_FILE && | ||
!defendant | ||
) { | ||
throw new BadRequestException('Missing defendant for case file category') | ||
} | ||
|
||
if (caseFileCategory === CaseFileCategory.CIVIL_CLAIM && !civilClaimant) { | ||
throw new BadRequestException( | ||
'Missing civil claimant for case file category', | ||
) | ||
} | ||
|
||
return true | ||
} | ||
} |
Oops, something went wrong.