Skip to content

Commit

Permalink
COMPENF-459, COMPENF-841, COMPENF-864, COMPENF-860 (#129)
Browse files Browse the repository at this point in the history
Co-authored-by: afwilcox <[email protected]>
  • Loading branch information
cnesmithsalus and afwilcox authored Sep 19, 2023
1 parent 99571ef commit c1da1de
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ export class AllegationComplaintService {
in_progress_ind: updateAllegationComplaintDto.in_progress_ind,
observed_ind: updateAllegationComplaintDto.observed_ind,
violation_code: updateAllegationComplaintDto.violation_code,
suspect_witnesss_dtl_text: updateAllegationComplaintDto.suspect_witnesss_dtl_text,
};
const updatedValue = await this.allegationComplaintsRepository.update(
{ allegation_complaint_guid },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class AttractantHwcrXrefService {
queryRunner.manager.update(AttractantHwcrXref, updateAttractantHwcrXrefDto.attractant_hwcr_xref_guid, updateAttractantHwcrXrefDto);
}
}
queryRunner.commitTransaction();
await queryRunner.commitTransaction();
}
catch (err) {
this.logger.error(err);
Expand All @@ -100,7 +100,7 @@ export class AttractantHwcrXrefService {
}
finally
{
//await queryRunner.release();
await queryRunner.release();
}
return ;
}
Expand Down
65 changes: 37 additions & 28 deletions backend/src/v1/complaint/complaint.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Injectable, Logger } from '@nestjs/common';
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
import { CreateComplaintDto } from './dto/create-complaint.dto';
import { UpdateComplaintDto } from './dto/update-complaint.dto';
import { Complaint } from './entities/complaint.entity';
import { QueryRunner, Repository } from 'typeorm';
import { DataSource, QueryRunner, Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';

@Injectable()
export class ComplaintService {


constructor(private dataSource: DataSource) {}
private readonly logger = new Logger(ComplaintService.name);

constructor(
) {}


@InjectRepository(Complaint)
private complaintsRepository: Repository<Complaint>;
Expand Down Expand Up @@ -50,29 +48,40 @@ export class ComplaintService {
}

async updateComplex(complaint_identifier: string, updateComplaint: string): Promise<Complaint> {
const updateComplaintDto: UpdateComplaintDto = JSON.parse(updateComplaint);
const updateData =
try
{
const updateComplaintDto: UpdateComplaintDto = JSON.parse(updateComplaint);
let referredByAgencyCode = updateComplaintDto.referred_by_agency_code;
if(referredByAgencyCode !== null && referredByAgencyCode.agency_code === "")
{
complaint_status_code: updateComplaintDto.complaint_status_code,
detail_text: updateComplaintDto.detail_text,
location_detailed_text: updateComplaintDto.location_detailed_text,
cos_geo_org_unit: updateComplaintDto.cos_geo_org_unit,
incident_datetime: updateComplaintDto.incident_datetime,
location_geometry_point: updateComplaintDto.location_geometry_point,
location_summary_text: updateComplaintDto.location_summary_text,
caller_name: updateComplaintDto.caller_name,
caller_email: updateComplaintDto.caller_email,
caller_address: updateComplaintDto.caller_address,
caller_phone_1: updateComplaintDto.caller_phone_1,
caller_phone_2: updateComplaintDto.caller_phone_2,
caller_phone_3: updateComplaintDto.caller_phone_3,
referred_by_agency_code: updateComplaintDto.referred_by_agency_code,
};
const updatedValue = await this.complaintsRepository.update(
{ complaint_identifier },
updateData
);
//queryRunner.manager.save(updatedValue);
referredByAgencyCode = null;
}
const updateData =
{
complaint_status_code: updateComplaintDto.complaint_status_code,
detail_text: updateComplaintDto.detail_text,
location_detailed_text: updateComplaintDto.location_detailed_text,
cos_geo_org_unit: updateComplaintDto.cos_geo_org_unit,
incident_datetime: updateComplaintDto.incident_datetime,
location_geometry_point: updateComplaintDto.location_geometry_point,
location_summary_text: updateComplaintDto.location_summary_text,
caller_name: updateComplaintDto.caller_name,
caller_email: updateComplaintDto.caller_email,
caller_address: updateComplaintDto.caller_address,
caller_phone_1: updateComplaintDto.caller_phone_1,
caller_phone_2: updateComplaintDto.caller_phone_2,
caller_phone_3: updateComplaintDto.caller_phone_3,
referred_by_agency_code: referredByAgencyCode,
};
const updatedValue = await this.complaintsRepository.update(
{ complaint_identifier },
updateData
);
}
catch (err) {
this.logger.error(err);
throw new BadRequestException(err);
}
return this.findOne(complaint_identifier);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ export class PersonComplaintXrefService {
): Promise<PersonComplaintXref> {
this.logger.debug(`Assigning Complaint ${complaintIdentifier}`);
const queryRunner = this.dataSource.createQueryRunner();
let newPersonComplaintXref: PersonComplaintXref;
let unassignedPersonComplaintXref: PersonComplaintXref;

await queryRunner.connect();
await queryRunner.startTransaction();
let newPersonComplaintXref: PersonComplaintXref;
let unassignedPersonComplaintXref: PersonComplaintXref;

try {
// unassign complaint if it's already assigned to an officer
unassignedPersonComplaintXref = await this.findByComplaint(
Expand All @@ -110,6 +111,7 @@ export class PersonComplaintXrefService {
unassignedPersonComplaintXref.active_ind = false;
await queryRunner.manager.save(unassignedPersonComplaintXref);
}
this.logger.debug("test9");
// create a new complaint assignment record
newPersonComplaintXref = await this.create(createPersonComplaintXrefDto);
this.logger.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { PersonComplaintXref } from "../../../types/complaints/person-complaint-
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import { Coordinates } from "../../../types/app/coordinate-type";
import { AgencyCode } from "../../../types/code-tables/agency-code";

type ComplaintParams = {
id: string;
Expand Down Expand Up @@ -686,13 +687,13 @@ function handleViolationTypeChange(selectedOption: Option | null) {
else
{
setSecondaryPhoneMsg("");
if(value !== undefined && complaintType === COMPLAINT_TYPES.HWCR)
if(complaintType === COMPLAINT_TYPES.HWCR)
{
let hwcrComplaint: HwcrComplaint = cloneDeep(updateComplaint) as HwcrComplaint;
hwcrComplaint.complaint_identifier.caller_phone_2 = (value !== undefined ? value : "");
setUpdateComplaint(hwcrComplaint);
}
else if(value !== undefined && complaintType === COMPLAINT_TYPES.ERS)
else if (complaintType === COMPLAINT_TYPES.ERS)
{
let allegationComplaint: AllegationComplaint = cloneDeep(updateComplaint) as AllegationComplaint;
allegationComplaint.complaint_identifier.caller_phone_2 = (value !== undefined ? value : "");
Expand Down Expand Up @@ -756,25 +757,61 @@ function handleViolationTypeChange(selectedOption: Option | null) {
function handleReferredByChange(selectedOption: Option | null) {
if(selectedOption !== null && selectedOption !== undefined)
{
const emptyOption: AgencyCode = {
agency_code: "",
short_description: "",
long_description: "",
display_order: 0,
active_ind: true,
create_user_id: "",
create_timestamp: "",
update_user_id: "",
update_timestamp: "",
};
if(complaintType === COMPLAINT_TYPES.HWCR)
{
let hwcrComplaint: HwcrComplaint = cloneDeep(updateComplaint) as HwcrComplaint;
axios.get(`${config.API_BASE_URL}/v1/agency-code/` + selectedOption.value).then((response) => {
hwcrComplaint.complaint_identifier.referred_by_agency_code = response.data;
if(selectedOption.value !== "")
{
axios.get(`${config.API_BASE_URL}/v1/agency-code/` + selectedOption.value).then((response) => {
hwcrComplaint.complaint_identifier.referred_by_agency_code = response.data;
setUpdateComplaint(hwcrComplaint);
});
}
else
{
hwcrComplaint.complaint_identifier.referred_by_agency_code = emptyOption;
setUpdateComplaint(hwcrComplaint);
});
}
}
else if(complaintType === COMPLAINT_TYPES.ERS)
{
let allegationComplaint: AllegationComplaint = cloneDeep(updateComplaint) as AllegationComplaint;
axios.get(`${config.API_BASE_URL}/v1/agency-code/` + selectedOption.value).then((response) => {
allegationComplaint.complaint_identifier.referred_by_agency_code = response.data;
if(selectedOption.value !== "")
{
axios.get(`${config.API_BASE_URL}/v1/agency-code/` + selectedOption.value).then((response) => {
allegationComplaint.complaint_identifier.referred_by_agency_code = response.data;
setUpdateComplaint(allegationComplaint);
});
}
else
{
allegationComplaint.complaint_identifier.referred_by_agency_code = emptyOption;
setUpdateComplaint(allegationComplaint);
});
}
}
}
}

function handleSuspectDetailsChange(value: string) {
if(complaintType === COMPLAINT_TYPES.ERS)
{
let allegationComplaint: AllegationComplaint = updateComplaint as AllegationComplaint;
allegationComplaint.suspect_witnesss_dtl_text = value;
setUpdateComplaint(allegationComplaint);
}
}

return (

<div className="comp-complaint-details">
Expand Down Expand Up @@ -814,6 +851,7 @@ function handleViolationTypeChange(selectedOption: Option | null) {
handleViolationInProgessChange={handleViolationInProgessChange}
handleViolationObservedChange={handleViolationObservedChange}
handleViolationTypeChange={handleViolationTypeChange}
handleSuspectDetailsChange={handleSuspectDetailsChange}
/>
}
{ !readOnly &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ interface ComplaintDetailsProps {
handleViolationInProgessChange: Function,
handleViolationObservedChange: Function,
handleViolationTypeChange: Function,
handleSuspectDetailsChange: Function,
}

export const ComplaintDetailsEdit: FC<ComplaintDetailsProps> = ({
Expand Down Expand Up @@ -121,6 +122,7 @@ export const ComplaintDetailsEdit: FC<ComplaintDetailsProps> = ({
handleViolationInProgessChange,
handleViolationObservedChange,
handleViolationTypeChange,
handleSuspectDetailsChange,
}) => {
const {
details,
Expand Down Expand Up @@ -784,6 +786,7 @@ export const ComplaintDetailsEdit: FC<ComplaintDetailsProps> = ({
id="complaint-description-textarea-id"
defaultValue={complaint_witness_details}
rows={4}
onChange={e => handleSuspectDetailsChange(e.target.value)}
/>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/store/reducers/code-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const codeTableSlice = createSlice({
return { value, label, description } as CodeTable;
}
);
data.unshift({value: "", label: "", description: ""});
return { ...state, agencyCodes: data };
},
setComplaintStatusCodes: (
Expand Down Expand Up @@ -170,6 +171,7 @@ export const fetchCodeTables = (): AppThunk => async (dispatch) => {
dispatch(toggleLoading(true));

try {
console.log(JSON.stringify(agencyCodes));
if (!from(agencyCodes).any()) {
dispatch(fetchAgencyCodes());
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/types/complaints/allegation-complaint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface AllegationComplaint {
violation_code: ViolationCode;
in_progress_ind: string | boolean;
observed_ind: boolean;
suspect_witnesss_dtl_text?: string
suspect_witnesss_dtl_text: string;
update_timestamp: string;
allegation_complaint_guid: string
}

0 comments on commit c1da1de

Please sign in to comment.