|
|
import { Injectable } from '@angular/core'; |
|
|
|
|
|
export interface LegalInfo { |
|
|
witnessStatements: string; |
|
|
confessions: string; |
|
|
evidence: File[]; |
|
|
} |
|
|
|
|
|
export interface PoliceCase { |
|
|
|
|
|
caseId?: string; |
|
|
firRef?: string; |
|
|
occurredFrom?: string; |
|
|
occurredTo?: string; |
|
|
jurisdiction?: string; |
|
|
sceneType?: string; |
|
|
dateTime?: string; |
|
|
status?: 'Open' | 'Under Investigation' | 'Closed'; |
|
|
crime: string; |
|
|
police: { |
|
|
name: string; |
|
|
station: string; |
|
|
address: string; |
|
|
pincode: string; |
|
|
dutyPerson: string; |
|
|
modeOfCrime: string; |
|
|
information?: string; |
|
|
}; |
|
|
accused: { |
|
|
name: string; |
|
|
age: string | number; |
|
|
gender: string; |
|
|
address: string; |
|
|
occupation?: string; |
|
|
}; |
|
|
legal: LegalInfo; |
|
|
victimName?: string; |
|
|
caseCategory?: string; |
|
|
reportedBy?: string; |
|
|
lastUpdated?: string; |
|
|
verifiedBy?: string; |
|
|
} |
|
|
|
|
|
@Injectable({ providedIn: 'root' }) |
|
|
export class CaseStoreService { |
|
|
private readonly storageKey = 'py_detect_police_cases'; |
|
|
private cases: PoliceCase[] = []; |
|
|
|
|
|
constructor() { |
|
|
this.load(); |
|
|
} |
|
|
|
|
|
|
|
|
private getNextCaseId(): string { |
|
|
const max = this.cases |
|
|
.map(c => c.caseId) |
|
|
.map(id => parseInt((id || '').replace('CASE-', ''), 10)) |
|
|
.filter(n => !isNaN(n)) |
|
|
.reduce((a, b) => Math.max(a, b), 0); |
|
|
return `CASE-${(max + 1).toString().padStart(3, '0')}`; |
|
|
} |
|
|
|
|
|
addPoliceCase(c: PoliceCase): void { |
|
|
if (!c.caseId) { |
|
|
c.caseId = this.getNextCaseId(); |
|
|
} |
|
|
c.lastUpdated = new Date().toISOString(); |
|
|
c.verifiedBy = c.verifiedBy || ''; |
|
|
this.cases.unshift(c); |
|
|
this.save(); |
|
|
} |
|
|
|
|
|
|
|
|
getPoliceCases(): PoliceCase[] { |
|
|
return this.cases; |
|
|
} |
|
|
|
|
|
|
|
|
updatePoliceCaseAt(index: number, updated: PoliceCase): void { |
|
|
if (index >= 0 && index < this.cases.length) { |
|
|
updated.lastUpdated = new Date().toISOString(); |
|
|
this.cases[index] = updated; |
|
|
this.save(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
deletePoliceCaseAt(index: number): void { |
|
|
if (index >= 0 && index < this.cases.length) { |
|
|
this.cases.splice(index, 1); |
|
|
this.save(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addFromInfoForm(formValue: any): void { |
|
|
const crime = (formValue && formValue.crime) || {}; |
|
|
const suspect = (formValue && formValue.suspect) || {}; |
|
|
const notes = (formValue && formValue.notes) || {}; |
|
|
const legal = (formValue && formValue.legal) || {}; |
|
|
|
|
|
const mapped: PoliceCase = { |
|
|
caseId: crime.caseId || '', |
|
|
firRef: crime['FIR / Ref #'] || formValue['FIR / Ref #'] || '', |
|
|
occurredFrom: crime['Occurred From'] || formValue['Occurred From'] || '', |
|
|
occurredTo: crime['Occurred To'] || formValue['Occurred To'] || '', |
|
|
jurisdiction: crime['Jurisdiction / PS'] || formValue['Jurisdiction / PS'] || '', |
|
|
sceneType: crime['Scene Type'] || formValue['Scene Type'] || '', |
|
|
dateTime: crime.dateTime || '', |
|
|
status: notes.status || 'Open', |
|
|
crime: crime.crimeType || 'Unknown', |
|
|
police: { |
|
|
name: notes.officerInCharge || '—', |
|
|
station: '—', |
|
|
address: crime.location || '—', |
|
|
pincode: '', |
|
|
dutyPerson: notes.officerInCharge || '—', |
|
|
modeOfCrime: crime.crimeType || '—', |
|
|
information: notes.initialFindings || '' |
|
|
}, |
|
|
accused: { |
|
|
name: suspect.fullName || '—', |
|
|
age: suspect.age || '—', |
|
|
gender: suspect.gender || '—', |
|
|
address: suspect.address || '—', |
|
|
occupation: suspect.alias || '' |
|
|
}, |
|
|
legal: { |
|
|
witnessStatements: legal.witnessStatements || '', |
|
|
confessions: legal.confessions || '', |
|
|
evidence: legal.evidence || [] |
|
|
}, |
|
|
victimName: crime.victimName || formValue['Victim Name'] || '', |
|
|
caseCategory: crime.caseCategory || formValue['Case Category'] || '', |
|
|
reportedBy: crime.reportedBy || formValue['Reported By'] || '', |
|
|
lastUpdated: new Date().toISOString(), |
|
|
verifiedBy: formValue.verifiedBy || '', |
|
|
}; |
|
|
|
|
|
this.addPoliceCase(mapped); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private save(): void { |
|
|
try { localStorage.setItem(this.storageKey, JSON.stringify(this.cases)); } catch { } |
|
|
} |
|
|
|
|
|
|
|
|
private load(): void { |
|
|
try { |
|
|
const raw = localStorage.getItem(this.storageKey); |
|
|
this.cases = raw ? (JSON.parse(raw) as PoliceCase[]) : []; |
|
|
} catch { |
|
|
this.cases = []; |
|
|
} |
|
|
} |
|
|
} |
|
|
|