Skip to content

Commit

Permalink
Rewrites subpoena info diff
Browse files Browse the repository at this point in the history
  • Loading branch information
gudjong committed Dec 3, 2024
1 parent cce02a1 commit 7b92849
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export {
PoliceDocumentType,
PoliceDocument,
SubpoenaInfo,
PoliceService,
} from './police.service'
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { UploadPoliceCaseFileDto } from './dto/uploadPoliceCaseFile.dto'
import { CreateSubpoenaResponse } from './models/createSubpoena.response'
import { PoliceCaseFile } from './models/policeCaseFile.model'
import { PoliceCaseInfo } from './models/policeCaseInfo.model'
import { SubpoenaInfo } from './models/subpoenaInfo.model'
import { UploadPoliceCaseFileResponse } from './models/uploadPoliceCaseFile.response'
import { policeModuleConfig } from './police.config'

Expand All @@ -59,6 +58,14 @@ export interface PoliceDocument {
courtDocument: string
}

export interface SubpoenaInfo {
serviceStatus?: ServiceStatus
comment?: string
servedBy?: string
defenderNationalId?: string
serviceDate?: Date
}

const getChapter = (category?: string): number | undefined => {
if (!category) {
return undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { DefendantService } from '../defendant/defendant.service'
import { Defendant } from '../defendant/models/defendant.model'
import { EventService } from '../event'
import { FileService } from '../file'
import { PoliceService } from '../police'
import { PoliceService, SubpoenaInfo } from '../police'
import { User } from '../user'
import { UpdateSubpoenaDto } from './dto/updateSubpoena.dto'
import { DeliverResponse } from './models/deliver.response'
Expand All @@ -59,6 +59,27 @@ export const include: Includeable[] = [
{ model: Defendant, as: 'defendant' },
]

const subpoenaInfoKeys: Array<keyof SubpoenaInfo> = [
'serviceStatus',
'comment',
'servedBy',
'defenderNationalId',
'serviceDate',
]

const isNewValueSetAndDifferent = (
newValue: unknown,
oldValue: unknown,
): boolean => Boolean(newValue) && newValue !== oldValue

export const isSubpoenaInfoChanged = (
newSubpoenaInfo: SubpoenaInfo,
oldSubpoenaInfo: SubpoenaInfo,
) =>
subpoenaInfoKeys.some((key) =>
isNewValueSetAndDifferent(newSubpoenaInfo[key], oldSubpoenaInfo[key]),
)

@Injectable()
export class SubpoenaService {
constructor(
Expand Down Expand Up @@ -353,7 +374,7 @@ export class SubpoenaService {
user,
)

if (!subpoenaInfo.isSubpoenaInfoChanged(subpoena)) {
if (!isSubpoenaInfoChanged(subpoenaInfo, subpoena)) {
// The subpoena has not changed
return subpoena
}
Expand Down

0 comments on commit 7b92849

Please sign in to comment.