Skip to content

Commit

Permalink
Feature/2014 add region admin (#2038)
Browse files Browse the repository at this point in the history
* #2014 region admin CRUD added


---------

Co-authored-by: Viktor Patraboi <vpatr@softserveinc.com>
  • Loading branch information
okedo and Viktor Patraboi authored Mar 22, 2023
1 parent 8e5f0d7 commit c564e0c
Show file tree
Hide file tree
Showing 25 changed files with 1,071 additions and 280 deletions.
10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
module.exports = {
"moduleNameMapper": {
'^shared/(.*)$': '<rootDir>/src/app/shared/$1',
'^shared-services/(.*)$': '<rootDir>/src/app/shared/services/$1',
'^shared-components/(.*)$': '<rootDir>/src/app/shared/components/$1',
'^shared-enum/(.*)$': '<rootDir>/src/app/shared/enum/$1',
'^shared-models/(.*)$': '<rootDir>/src/app/shared/models/$1',
'^shared-constants/(.*)$': '<rootDir>/src/app/shared/constants/$1',
'^shared-store/(.*)$': '<rootDir>/src/app/shared/store/$1',
'^shared-utils/(.*)$': '<rootDir>/src/app/shared/utils/$1'
},
"preset": "jest-preset-angular",
"setupFilesAfterEnv": [
"<rootDir>/setup-jest.ts"
Expand Down
6 changes: 6 additions & 0 deletions src/app/shared/enum/admins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ export enum AdminRoles {
territorialCommunityAdmin = 'territorialCommunityAdmin'
}

export enum AdminIds {
ministryAdmin = "ministryAdminId",
regionAdmin = "regionAdminId",
territorialCommunityAdmin = "territorialCommunityAdminId"
}

export enum AdminRoleTypes {
ministryAdmin,
regionAdmin,
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/enum/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum Role {
unauthorized = 'unauthorized',
techAdmin = 'techadmin',
ministryAdmin = 'ministryadmin',
regionAdmin = 'regionadmin',
ProviderDeputy = 'ProviderDeputy',
ProviderAdmin = 'ProviderAdmin',
all = 'all',
Expand Down
7 changes: 7 additions & 0 deletions src/app/shared/models/admin-form.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface AdminFormModel {
email: string;
firstName: string;
lastName: string;
middleName: string;
phoneNumber: string;
}
39 changes: 39 additions & 0 deletions src/app/shared/models/admin.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { PaginationParameters } from './queryParameters.model';

export class BaseAdmin {
id?: string;
email: string;
phoneNumber: string;
lastName: string;
middleName?: string;
firstName: string;
accountStatus?: string;
institutionId: string;
institutionTitle?: string;

constructor(info, institutionId: string, id?: string, accountStatus?: string) {
this.email = info.email;
this.phoneNumber = info.phoneNumber;
this.lastName = info.lastName;
this.middleName = info.middleName;
this.firstName = info.firstName;
this.institutionId = institutionId;
this.institutionTitle = info.institutionTitle;
if (id) {
this.id = id;
}
if (accountStatus) {
this.accountStatus = accountStatus;
}
}
}

export interface BaseAdminParameters extends PaginationParameters {
tabTitle?: string;
searchString?: string;
}

export interface BaseAdminBlockData {
adminId: string;
isBlocked: boolean;
}
40 changes: 4 additions & 36 deletions src/app/shared/models/ministryAdmin.model.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
import { PaginationParameters } from './queryParameters.model';
import { BaseAdmin, BaseAdminBlockData, BaseAdminParameters } from './admin.model';

export class MinistryAdmin {
id?: string;
email: string;
phoneNumber: string;
lastName: string;
middleName?: string;
firstName: string;
accountStatus?: string;
institutionId: string;
institutionTitle?: string;
export class MinistryAdmin extends BaseAdmin { }

constructor(info, institutionId: string, id?: string, accountStatus?: string) {
this.email = info.email;
this.phoneNumber = info.phoneNumber;
this.lastName = info.lastName;
this.middleName = info.middleName;
this.firstName = info.firstName;
this.institutionId = institutionId;
this.institutionTitle = info.institutionTitle;
if (id) {
this.id = id;
}
if (accountStatus) {
this.accountStatus = accountStatus;
}
}
}
export interface MinistryAdminParameters extends BaseAdminParameters { }

export interface MinistryAdminParameters extends PaginationParameters {
tabTitle?: string;
searchString?: string;
}

export interface MinistryAdminBlockData {
ministryAdminId: string;
isBlocked: boolean;
}
export interface MinistryAdminBlockData extends BaseAdminBlockData { }
14 changes: 14 additions & 0 deletions src/app/shared/models/regionAdmin.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BaseAdmin, BaseAdminBlockData, BaseAdminParameters } from './admin.model';

export class RegionAdmin extends BaseAdmin {
public catottgId: string;
public catottgName: string;

constructor(info, institutionId: string, regionId: string, id?: string, accountStatus?: string) {
super(info, institutionId, id, accountStatus)
this.catottgId = regionId
}
}

export interface RegionAdminParameters extends BaseAdminParameters { }
export interface RegionAdminBlockData extends BaseAdminBlockData { }
96 changes: 96 additions & 0 deletions src/app/shared/services/base-admin/base-admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Observable } from "rxjs";

import { HttpClient, HttpParams } from "@angular/common/http";

import { BaseAdminParameters, BaseAdmin } from "../../models/admin.model";
import { PaginationConstants } from "../../constants/constants";
import { SearchResponse } from "../../models/search.model";
import { AdminIds, AdminRoles } from "../../enum/admins";

export class BaseAdminService {
protected adminType = "";
constructor(protected http: HttpClient, adminType: AdminRoles) {
this.adminType = adminType;
}

protected get adminBaseUrl(): string {
return `/api/v1/${this.adminType}`;
}

protected setParams(parameters: BaseAdminParameters = { searchString: '' }): HttpParams {
let params = new HttpParams();

if (parameters.searchString) {
params = params.set('SearchString', parameters.searchString);
}

const size = parameters?.size?.toString() || PaginationConstants.TABLE_ITEMS_PER_PAGE;
const from = parameters?.from?.toString() || "0";

params = params.set('Size', size).set('From', from);

return params;
}

/**
* This method get Profile of authorized Admin
*/
protected getAdminProfile(): Observable<BaseAdmin> {
return this.http.get<BaseAdmin>(`${this.adminBaseUrl}/Profile`);
}

/**
* This method get Admin by Id
* * @param adminId: string
*/
protected getAdminById(adminId: string): Observable<BaseAdmin> {
let params = new HttpParams().set('id', `${adminId}`);

return this.http.get<BaseAdmin>(`${this.adminBaseUrl}/GetById`, { params });
}

/**
* This method get All Admins
*/
protected getAllAdmin(parameters: BaseAdminParameters): Observable<SearchResponse<BaseAdmin[]>> {
const options = { params: this.setParams(parameters) };

return this.http.get<SearchResponse<BaseAdmin[]>>(`${this.adminBaseUrl}/GetByFilter`, options);
}

/**
* This method create Admin
* @param baseAdmin: BaseAdmin
*/
protected createAdmin(baseAdmin: BaseAdmin): Observable<BaseAdmin> {
return this.http.post<BaseAdmin>(`${this.adminBaseUrl}/Create`, baseAdmin);
}

/**
* This method delete Admin by id
* @param adminId: string
*/
protected deleteAdmin(adminId: string): Observable<void> {
let params = new HttpParams().set(AdminIds[this.adminType], `${adminId}`);

return this.http.delete<void>(`${this.adminBaseUrl}/Delete`, { params });
}

/**
* This method block Admin
* @param adminId: string
*/
protected blockAdmin(adminId: string, isBlocked: boolean): Observable<void> {
let params = new HttpParams().set(AdminIds[this.adminType], `${adminId}`).set('isBlocked', `${isBlocked}`);

return this.http.put<void>(`${this.adminBaseUrl}/Block`, {}, { params });
}

/**
* This method update Admin
* @param baseAdmin: BaseAdmin
*/
protected updateAdmin(admin: BaseAdmin): Observable<BaseAdmin> {
return this.http.put<BaseAdmin>(`${this.adminBaseUrl}/Update`, admin);
}
}
18 changes: 13 additions & 5 deletions src/app/shared/services/codeficator/codeficator.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';

import { Codeficator, CodeficatorCityDistrict } from '../../models/codeficator.model';
import { CodeficatorCategories } from '../../enum/codeficator-categories';

@Injectable({
providedIn: 'root'
Expand All @@ -13,23 +15,29 @@ export class CodeficatorService {
* This method to get all Codeficators from the database
* @param settlement string
*/
searchCodeficator(settlement: string): Observable<Codeficator[]> {
return this.http.get<Codeficator[]>(`/api/v1/Codeficator/search?Name=${settlement}`);
public searchCodeficator(settlement: string, categories?: CodeficatorCategories[]): Observable<Codeficator[]> {
if(!categories){
return this.http.get<Codeficator[]>(`/api/v1/Codeficator/search?Name=${settlement}`);
} else {
const categoriesParam = categories?.join("");

return this.http.get<Codeficator[]>(`/api/v1/Codeficator/search?Name=${settlement}&Categories=${categoriesParam}`);
}
}

/**
* This method to get Codeficator by id
* @param id number
*/
getCodeficatorById(id: number): Observable<Codeficator> {
public getCodeficatorById(id: number): Observable<Codeficator> {
return this.http.get<Codeficator>(`/api/v1/Codeficator/${id}/parents`);
}

/**
* This method to get all Codeficator City Districts from the database
* @param id number
*/
searchCodeficatorCityDistrict(id: number): Observable<CodeficatorCityDistrict[]> {
public searchCodeficatorCityDistrict(id: number): Observable<CodeficatorCityDistrict[]> {
return this.http.get<CodeficatorCityDistrict[]>(`/api/v1/Codeficator/children?id=${id}`);
}

Expand All @@ -38,7 +46,7 @@ export class CodeficatorService {
* @param lat number
* @param lon number
*/
getNearestByCoordinates(lat: number, lon: number): Observable<Codeficator> {
public getNearestByCoordinates(lat: number, lon: number): Observable<Codeficator> {
let params = new HttpParams().set('Lat', lat.toString()).set('Lon', lon.toString());

return this.http.get<Codeficator>('/api/v1/Codeficator/NearestByCoordinates', { params });
Expand Down
Loading

0 comments on commit c564e0c

Please sign in to comment.