File size: 4,743 Bytes
463dbc3 0dcd2ca 463dbc3 0dcd2ca 463dbc3 0dcd2ca 463dbc3 0dcd2ca 463dbc3 0dcd2ca 463dbc3 0dcd2ca 463dbc3 0dcd2ca 463dbc3 0dcd2ca 463dbc3 0dcd2ca 463dbc3 0dcd2ca 463dbc3 0dcd2ca 463dbc3 0dcd2ca 463dbc3 6f093ab 463dbc3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
import { Injectable } from '@angular/core';
export interface LegalInfo {
witnessStatements: string;
confessions: string;
evidence: File[]; // Assuming you're collecting file(s) as evidence
}
export interface PoliceCase {
// Optional metadata used by your UI
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; // Add the legal property here
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();
}
/** Create (newest first) */
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();
}
/** Read */
getPoliceCases(): PoliceCase[] {
return this.cases;
}
/** Update by array index */
updatePoliceCaseAt(index: number, updated: PoliceCase): void {
if (index >= 0 && index < this.cases.length) {
updated.lastUpdated = new Date().toISOString();
this.cases[index] = updated;
this.save();
}
}
/** Delete by array index */
deletePoliceCaseAt(index: number): void {
if (index >= 0 && index < this.cases.length) {
this.cases.splice(index, 1);
this.save();
}
}
/**
* Convenience: map Info page reactive-form value to PoliceCase and store it.
* Call with the whole this.form.value from InfopageComponent.
*/
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);
}
/** Persist to localStorage (safe to keep; remove if not needed) */
private save(): void {
try { localStorage.setItem(this.storageKey, JSON.stringify(this.cases)); } catch { }
}
/** Load from localStorage */
private load(): void {
try {
const raw = localStorage.getItem(this.storageKey);
this.cases = raw ? (JSON.parse(raw) as PoliceCase[]) : [];
} catch {
this.cases = [];
}
}
}
|