Skip to content

Commit

Permalink
feat: CE-501 Admin page (#852)
Browse files Browse the repository at this point in the history
Co-authored-by: afwilcox <[email protected]>
Co-authored-by: jon-funk <[email protected]>
Co-authored-by: Derek Roberts <[email protected]>
Co-authored-by: Ryan Rondeau <[email protected]>
Co-authored-by: dmitri-korin-bcps <[email protected]>
  • Loading branch information
6 people authored Jan 8, 2025
1 parent aa7590c commit 351fb30
Show file tree
Hide file tree
Showing 48 changed files with 1,574 additions and 592 deletions.
19 changes: 19 additions & 0 deletions backend/src/external_api/css/css.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ExternalApiService } from "../external-api-service";
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
import { get } from "../../helpers/axios-api";
import { ConfigurationService } from "../../v1/configuration/configuration.service";
import { CssUser } from "src/types/css/cssUser";

@Injectable()
export class CssService implements ExternalApiService {
Expand Down Expand Up @@ -64,6 +65,24 @@ export class CssService implements ExternalApiService {
}
};

getUserIdirByEmail = async (email: string): Promise<CssUser[]> => {
try {
const apiToken = await this.authenticate();
const url = `${this.baseUri}/api/v1/${this.env}/idir/users?email=${email}`;
const config: AxiosRequestConfig = {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiToken}`,
},
};
const response = await get(apiToken, url, config);
return response?.data.data;
} catch (error) {
this.logger.error(`exception: unable to get user by email: ${email} - error: ${error}`);
throw new Error(`exception: unable to get user by email: ${email} - error: ${error}`);
}
};

getUserRoles = async (userIdir): Promise<{ name: string; composite: string }[]> => {
try {
const apiToken = await this.authenticate();
Expand Down
11 changes: 11 additions & 0 deletions backend/src/types/css/cssUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface CssUser {
username: string;
firstName: string;
lastName: string;
email: string;
attributes: {
idir_user_guid: string[];
idir_username: string[];
display_name: string[];
};
}
7 changes: 7 additions & 0 deletions backend/src/types/models/general/team-update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface TeamUpdate {
userIdir: string;
adminIdirUsername: string;
agencyCode: string;
teamCode: string | null;
roles: Array<{ name: string }>;
}
26 changes: 26 additions & 0 deletions backend/src/types/models/people/officer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export interface NewOfficer {
user_id: string;
create_user_id: string;
create_utc_timestamp: Date;
update_user_id: string;
update_utc_timestamp: Date;
auth_user_guid: string;
office_guid: string | null;
team_code: string | null;
person_guid: {
first_name: string;
middle_name_1: null;
middle_name_2: null;
last_name: string;
create_user_id: string;
create_utc_timestamp: Date;
update_user_id: string;
updateTimestamp: Date;
};
roles: {
user_roles: Array<{ name: string | undefined }>;
user_idir: string; //Example : fohe4m5pn8clhkxmlho33sn1r7vr7m67@idir
};
coms_enrolled_ind: boolean;
deactivate_ind: boolean;
}
14 changes: 14 additions & 0 deletions backend/src/v1/case_file/case_file.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ import { ConfigurationService } from "../configuration/configuration.service";
import { Configuration } from "../configuration/entities/configuration.entity";
import { Person } from "../person/entities/person.entity";
import { LinkedComplaintXrefService } from "../linked_complaint_xref/linked_complaint_xref.service";
import { TeamService } from "../team/team.service";
import { OfficerTeamXrefService } from "../officer_team_xref/officer_team_xref.service";
import { Team } from "../team/entities/team.entity";
import { OfficerTeamXref } from "../officer_team_xref/entities/officer_team_xref.entity";

describe("Testing: Case File Service", () => {
let service: CaseFileService;
Expand Down Expand Up @@ -208,6 +212,14 @@ describe("Testing: Case File Service", () => {
provide: getRepositoryToken(Person),
useValue: {},
},
{
provide: getRepositoryToken(Team),
useValue: {},
},
{
provide: getRepositoryToken(OfficerTeamXref),
useValue: {},
},
ComplaintUpdatesService,
CaseFileService,
ComplaintService,
Expand All @@ -221,6 +233,8 @@ describe("Testing: Case File Service", () => {
PersonComplaintXrefService,
AttractantHwcrXrefService,
CompMthdRecvCdAgcyCdXrefService,
TeamService,
OfficerTeamXrefService,
{
provide: REQUEST,
useValue: {
Expand Down
24 changes: 24 additions & 0 deletions backend/src/v1/complaint/complaint.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ import { Person } from "../person/entities/person.entity";
import { Configuration } from "../configuration/entities/configuration.entity";
import { LinkedComplaintXrefService } from "../linked_complaint_xref/linked_complaint_xref.service";
import { LinkedComplaintXref } from "../linked_complaint_xref/entities/linked_complaint_xref.entity";
import { TeamService } from "../team/team.service";
import { Team } from "../team/entities/team.entity";
import { OfficerTeamXrefService } from "../officer_team_xref/officer_team_xref.service";
import { OfficerTeamXref } from "../officer_team_xref/entities/officer_team_xref.entity";

describe("Testing: Complaint Service", () => {
let service: ComplaintService;
Expand Down Expand Up @@ -117,6 +121,14 @@ describe("Testing: Complaint Service", () => {
provide: getRepositoryToken(LinkedComplaintXref),
useValue: {},
},
{
provide: getRepositoryToken(Team),
useValue: {},
},
{
provide: getRepositoryToken(OfficerTeamXref),
useValue: {},
},
ComplaintUpdatesService,
ComplaintService,
PersonComplaintXrefService,
Expand All @@ -129,6 +141,8 @@ describe("Testing: Complaint Service", () => {
AttractantHwcrXrefService,
CodeTableService,
CompMthdRecvCdAgcyCdXrefService,
TeamService,
OfficerTeamXrefService,
{
provide: getRepositoryToken(Complaint),
useFactory: MockComplaintsRepositoryV2,
Expand Down Expand Up @@ -410,6 +424,14 @@ describe("Testing: Complaint Service", () => {
provide: getRepositoryToken(LinkedComplaintXref),
useValue: {},
},
{
provide: getRepositoryToken(Team),
useValue: {},
},
{
provide: getRepositoryToken(OfficerTeamXref),
useValue: {},
},
ComplaintUpdatesService,
ComplaintService,
PersonComplaintXrefService,
Expand All @@ -422,6 +444,8 @@ describe("Testing: Complaint Service", () => {
AttractantHwcrXrefService,
CodeTableService,
CompMthdRecvCdAgcyCdXrefService,
TeamService,
OfficerTeamXrefService,
{
provide: getRepositoryToken(Complaint),
useFactory: MockUpdateComplaintsRepository,
Expand Down
14 changes: 14 additions & 0 deletions backend/src/v1/document/document.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ import { CssService } from "../../external_api/css/css.service";
import { Person } from "../person/entities/person.entity";
import { LinkedComplaintXref } from "../linked_complaint_xref/entities/linked_complaint_xref.entity";
import { LinkedComplaintXrefService } from "../linked_complaint_xref/linked_complaint_xref.service";
import { Team } from "../team/entities/team.entity";
import { OfficerTeamXref } from "../officer_team_xref/entities/officer_team_xref.entity";
import { TeamService } from "../team/team.service";
import { OfficerTeamXrefService } from "../officer_team_xref/officer_team_xref.service";

describe("DocumentController", () => {
let controller: DocumentController;
Expand Down Expand Up @@ -206,6 +210,14 @@ describe("DocumentController", () => {
provide: getRepositoryToken(LinkedComplaintXref),
useValue: {},
},
{
provide: getRepositoryToken(Team),
useValue: {},
},
{
provide: getRepositoryToken(OfficerTeamXref),
useValue: {},
},
ComplaintUpdatesService,
ComplaintService,
CodeTableService,
Expand All @@ -217,6 +229,8 @@ describe("DocumentController", () => {
PersonService,
AttractantHwcrXrefService,
CompMthdRecvCdAgcyCdXrefService,
TeamService,
OfficerTeamXrefService,
{
provide: REQUEST,
useValue: {
Expand Down
14 changes: 14 additions & 0 deletions backend/src/v1/document/document.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ import { CssService } from "../../external_api/css/css.service";
import { Person } from "../person/entities/person.entity";
import { LinkedComplaintXrefService } from "../linked_complaint_xref/linked_complaint_xref.service";
import { LinkedComplaintXref } from "../linked_complaint_xref/entities/linked_complaint_xref.entity";
import { Team } from "../team/entities/team.entity";
import { OfficerTeamXref } from "../officer_team_xref/entities/officer_team_xref.entity";
import { TeamService } from "../team/team.service";
import { OfficerTeamXrefService } from "../officer_team_xref/officer_team_xref.service";

describe("DocumentService", () => {
let service: DocumentService;
Expand Down Expand Up @@ -205,6 +209,14 @@ describe("DocumentService", () => {
provide: getRepositoryToken(LinkedComplaintXref),
useValue: {},
},
{
provide: getRepositoryToken(Team),
useValue: {},
},
{
provide: getRepositoryToken(OfficerTeamXref),
useValue: {},
},
ComplaintUpdatesService,
ComplaintService,
CodeTableService,
Expand All @@ -216,6 +228,8 @@ describe("DocumentService", () => {
PersonService,
AttractantHwcrXrefService,
CompMthdRecvCdAgcyCdXrefService,
TeamService,
OfficerTeamXrefService,
{
provide: REQUEST,
useValue: {
Expand Down
3 changes: 3 additions & 0 deletions backend/src/v1/officer/dto/create-officer.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ export class CreateOfficerDto extends PickType(OfficerDto, [
"user_id",
"person_guid",
"office_guid",
"auth_user_guid",
"create_user_id",
"create_utc_timestamp",
"update_user_id",
"update_utc_timestamp",
"coms_enrolled_ind",
"deactivate_ind",
] as const) {}
12 changes: 12 additions & 0 deletions backend/src/v1/officer/dto/officer.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,16 @@ export class OfficerDto {
description: "The keycloak guid for the officer",
})
auth_user_guid: UUID;

@ApiProperty({
example: "true",
description: "An indicator to determine if the officer has access to COMS",
})
coms_enrolled_ind: boolean;

@ApiProperty({
example: "false",
description: "An indicator to determine if the officer has been deactivated",
})
deactivate_ind: boolean;
}
4 changes: 3 additions & 1 deletion backend/src/v1/officer/dto/update-officer.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { PartialType } from "@nestjs/swagger";
import { CreateOfficerDto } from "./create-officer.dto";

export class UpdateOfficerDto extends PartialType(CreateOfficerDto) {}
export class UpdateOfficerDto extends PartialType(CreateOfficerDto) {
user_roles?: string[];
}
7 changes: 7 additions & 0 deletions backend/src/v1/officer/entities/officer.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ export class Officer {
@Column()
coms_enrolled_ind: boolean;

@ApiProperty({
example: false,
description: "Indicates whether an officer has been deactivated",
})
@Column()
deactivate_ind: boolean;

user_roles: string[];
@AfterLoad()
updateUserRoles() {
Expand Down
14 changes: 14 additions & 0 deletions backend/src/v1/officer/officer.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { dataSourceMockFactory } from "../../../test/mocks/datasource";
import { CssService } from "../../external_api/css/css.service";
import { ConfigurationService } from "../configuration/configuration.service";
import { Configuration } from "../configuration/entities/configuration.entity";
import { Team } from "../team/entities/team.entity";
import { TeamService } from "../team/team.service";
import { OfficerTeamXrefService } from "../officer_team_xref/officer_team_xref.service";
import { OfficerTeamXref } from "../officer_team_xref/entities/officer_team_xref.entity";

describe("OfficerController", () => {
let controller: OfficerController;
Expand All @@ -35,6 +39,16 @@ describe("OfficerController", () => {
provide: getRepositoryToken(Office),
useValue: {},
},
TeamService,
{
provide: getRepositoryToken(Team),
useValue: {},
},
OfficerTeamXrefService,
{
provide: getRepositoryToken(OfficerTeamXref),
useValue: {},
},
{
provide: DataSource,
useFactory: dataSourceMockFactory,
Expand Down
10 changes: 8 additions & 2 deletions backend/src/v1/officer/officer.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Put } from "@nestjs/common";
import { OfficerService } from "./officer.service";
import { CreateOfficerDto } from "./dto/create-officer.dto";
import { UpdateOfficerDto } from "./dto/update-officer.dto";
import { Roles } from "../../auth/decorators/roles.decorator";
import { Role } from "../../enum/role.enum";
Expand All @@ -9,6 +8,7 @@ import { ApiTags } from "@nestjs/swagger";
import { UUID } from "crypto";
import { User } from "../../auth/decorators/user.decorator";
import { Token } from "../../auth/decorators/token.decorator";
import { NewOfficer } from "../../types/models/people/officer";

@ApiTags("officer")
@UseGuards(JwtRoleGuard)
Expand All @@ -21,7 +21,7 @@ export class OfficerController {

@Post()
@Roles(Role.COS_OFFICER)
create(@Body() createOfficerDto: CreateOfficerDto) {
create(@Body() createOfficerDto: NewOfficer) {
return this.officerService.create(createOfficerDto);
}

Expand Down Expand Up @@ -61,6 +61,12 @@ export class OfficerController {
return this.officerService.findByPersonGuid(person_guid);
}

@Get("/find-by-email/:email")
@Roles(Role.TEMPORARY_TEST_ADMIN)
findUserByEmail(@Param("email") email: string) {
return this.officerService.findByCssEmail(email);
}

@Patch(":id")
@Roles(Role.COS_OFFICER, Role.CEEB, Role.TEMPORARY_TEST_ADMIN)
update(@Param("id") id: UUID, @Body() updateOfficerDto: UpdateOfficerDto) {
Expand Down
10 changes: 8 additions & 2 deletions backend/src/v1/officer/officer.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ import { TypeOrmModule } from "@nestjs/typeorm";
import { Officer } from "./entities/officer.entity";
import { Person } from "../person/entities/person.entity";
import { Office } from "../office/entities/office.entity";
import { CssModule } from "src/external_api/css/css.module";
import { CssModule } from "../../external_api/css/css.module";
import { TeamService } from "../team/team.service";
import { Team } from "../team/entities/team.entity";
import { OfficerTeamXref } from "../officer_team_xref/entities/officer_team_xref.entity";
import { OfficerTeamXrefService } from "../officer_team_xref/officer_team_xref.service";

@Module({
imports: [
TypeOrmModule.forFeature([Officer]),
TypeOrmModule.forFeature([Person]),
TypeOrmModule.forFeature([Office]),
TypeOrmModule.forFeature([Team]),
TypeOrmModule.forFeature([OfficerTeamXref]),
CssModule,
],
controllers: [OfficerController],
providers: [OfficerService, PersonService, OfficeService],
providers: [OfficerService, PersonService, OfficeService, TeamService, OfficerTeamXrefService],
exports: [OfficerService],
})
export class OfficerModule {}
Loading

0 comments on commit 351fb30

Please sign in to comment.