-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2014 moved logic to BaseAdmin service
- Loading branch information
Viktor Patraboi
committed
Mar 17, 2023
1 parent
93c6a9d
commit e0cb818
Showing
5 changed files
with
202 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
145 changes: 63 additions & 82 deletions
145
src/app/shared/services/ministry-admin/ministry-admin.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,72 @@ | ||
import { MinistryAdmin, MinistryAdminParameters } from './../../models/ministryAdmin.model'; | ||
import { Observable } from 'rxjs'; | ||
import { HttpClient, HttpParams } from '@angular/common/http'; | ||
|
||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { AdminRoles } from 'shared/enum/admins'; | ||
import { BaseAdminService } from '../base-admin/base-admin'; | ||
import { MinistryAdmin, MinistryAdminParameters } from './../../models/ministryAdmin.model'; | ||
import { SearchResponse } from '../../models/search.model'; | ||
import { PaginationConstants } from '../../constants/constants'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class MinistryAdminService { | ||
private readonly adminTypeUrlPart = ""; | ||
constructor(private http: HttpClient) {} | ||
|
||
private setParams(parameters: MinistryAdminParameters = { 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 MinistryAdmin | ||
*/ | ||
getMinistryAdminProfile(): Observable<MinistryAdmin> { | ||
return this.http.get<MinistryAdmin>(`/api/v1/MinistryAdmin/Profile`); | ||
} | ||
|
||
/** | ||
* This method get Ministry Admin by Id | ||
* * @param adminId: string | ||
*/ | ||
getMinistryAdminById(adminId: string): Observable<MinistryAdmin> { | ||
let params = new HttpParams().set('id', `${adminId}`); | ||
|
||
return this.http.get<MinistryAdmin>(`/api/v1/MinistryAdmin/GetById`, { params }); | ||
} | ||
|
||
/** | ||
* This method get All Ministry Admins | ||
*/ | ||
getAllMinistryAdmin(parameters: MinistryAdminParameters): Observable<SearchResponse<MinistryAdmin[]>> { | ||
const options = { params: this.setParams(parameters) }; | ||
|
||
return this.http.get<SearchResponse<MinistryAdmin[]>>(`/api/v1/MinistryAdmin/GetByFilter`, options); | ||
} | ||
|
||
/** | ||
* This method create Ministry Admin | ||
* @param ministryAdmin: MinistryAdmin | ||
*/ | ||
createMinistryAdmin(ministryAdmin: MinistryAdmin): Observable<MinistryAdmin> { | ||
return this.http.post<MinistryAdmin>(`/api/v1/MinistryAdmin/Create`, ministryAdmin); | ||
} | ||
|
||
/** | ||
* This method delete Ministry Admin by id | ||
* @param adminId: string | ||
*/ | ||
deleteMinistryAdmin(adminId: string): Observable<void> { | ||
let params = new HttpParams().set('ministryAdminId', `${adminId}`); | ||
|
||
return this.http.delete<void>(`/api/v1/MinistryAdmin/Delete`, { params }); | ||
} | ||
|
||
/** | ||
* This method block Ministry Admin | ||
* @param adminId: string | ||
*/ | ||
blockMinistryAdmin(adminId: string, isBlocked: boolean): Observable<void> { | ||
let params = new HttpParams().set('ministryAdminId', `${adminId}`).set('isBlocked', `${isBlocked}`); | ||
|
||
return this.http.put<void>(`/api/v1/MinistryAdmin/Block`, {}, { params }); | ||
export class MinistryAdminService extends BaseAdminService { | ||
constructor(protected http: HttpClient) { | ||
super(http, AdminRoles.ministryAdmin); | ||
} | ||
|
||
/** | ||
* This method update Ministry Admin | ||
* @param ministryAdmin: MinistryAdmin | ||
*/ | ||
updateMinistryAdmin(ministryAdmin: MinistryAdmin): Observable<MinistryAdmin> { | ||
return this.http.put<MinistryAdmin>(`/api/v1/MinistryAdmin/Update`, ministryAdmin); | ||
|
||
/** | ||
* This method get Profile of authorized MinistryAdmin | ||
*/ | ||
public getAdminProfile(): Observable<MinistryAdmin> { | ||
return super.getAdminProfile(); | ||
} | ||
|
||
/** | ||
* This method get Ministry Admin by Id | ||
* * @param adminId: string | ||
*/ | ||
public getAdminById(adminId: string): Observable<MinistryAdmin> { | ||
return super.getAdminById(adminId); | ||
} | ||
|
||
/** | ||
* This method get All Ministry Admins | ||
*/ | ||
public getAllAdmin(parameters: MinistryAdminParameters): Observable<SearchResponse<MinistryAdmin[]>> { | ||
return super.getAllAdmin(parameters); | ||
} | ||
|
||
/** | ||
* This method create Ministry Admin | ||
* @param ministryAdmin: MinistryAdmin | ||
*/ | ||
public createAdmin(ministryAdmin: MinistryAdmin): Observable<MinistryAdmin> { | ||
return super.createAdmin(ministryAdmin); | ||
} | ||
|
||
/** | ||
* This method delete Ministry Admin by id | ||
* @param adminId: string | ||
*/ | ||
public deleteAdmin(adminId: string): Observable<void> { | ||
return super.deleteAdmin(adminId); | ||
} | ||
|
||
/** | ||
* This method block Ministry Admin | ||
* @param adminId: string | ||
*/ | ||
public blockAdmin(adminId: string, isBlocked: boolean): Observable<void> { | ||
return super.blockAdmin(adminId, isBlocked); | ||
} | ||
|
||
/** | ||
* This method update Ministry Admin | ||
* @param ministryAdmin: MinistryAdmin | ||
*/ | ||
public updateAdmin(ministryAdmin: MinistryAdmin): Observable<MinistryAdmin> { | ||
return super.updateAdmin(ministryAdmin); | ||
} | ||
} | ||
} |
72 changes: 27 additions & 45 deletions
72
src/app/shared/services/region-admin/region-admin.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,72 @@ | ||
import { Observable } from 'rxjs'; | ||
import { HttpClient, HttpParams } from '@angular/common/http'; | ||
|
||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { SearchResponse } from '../../models/search.model'; | ||
|
||
import { AdminRoles } from 'shared/enum/admins'; | ||
import { BaseAdminService } from '../base-admin/base-admin'; | ||
import { RegionAdmin, RegionAdminParameters } from '../../models/regionAdmin.model'; | ||
import { PaginationConstants } from '../../constants/constants'; | ||
import { SearchResponse } from '../../models/search.model'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class RegionAdminService { | ||
constructor(private http: HttpClient) { } | ||
|
||
private setParams(parameters: RegionAdminParameters = { 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; | ||
export class RegionAdminService extends BaseAdminService { | ||
constructor(protected http: HttpClient) { | ||
super(http, AdminRoles.regionAdmin); | ||
} | ||
|
||
/** | ||
* This method get Profile of authorized RegionAdmin | ||
*/ | ||
getRegionAdminProfile(): Observable<RegionAdmin> { | ||
return this.http.get<RegionAdmin>('/api/v1/RegionAdmin/Profile'); | ||
getAdminProfile(): Observable<RegionAdmin> { | ||
return <Observable<RegionAdmin>>super.getAdminProfile(); | ||
} | ||
|
||
/** | ||
* This method get Region Admin by Id | ||
* * @param regionAdminId: string | ||
*/ | ||
getRegionAdminById(regionAdminId: string): Observable<RegionAdmin> { | ||
let params = new HttpParams().set('id', `${regionAdminId}`); | ||
|
||
return this.http.get<RegionAdmin>('/api/v1/RegionAdmin/GetById', { params }); | ||
getAdminById(regionAdminId: string): Observable<RegionAdmin> { | ||
return <Observable<RegionAdmin>>super.getAdminById(regionAdminId); | ||
} | ||
|
||
/** | ||
* This method get All Region Admins | ||
*/ | ||
getAllRegionAdmin(parameters: RegionAdminParameters): Observable<SearchResponse<RegionAdmin[]>> { | ||
const options = { params: this.setParams(parameters) }; | ||
|
||
return this.http.get<SearchResponse<RegionAdmin[]>>('/api/v1/RegionAdmin/GetByFilter', options); | ||
getAllAdmin(parameters: RegionAdminParameters): Observable<SearchResponse<RegionAdmin[]>> { | ||
return <Observable<SearchResponse<RegionAdmin[]>>>super.getAllAdmin(parameters); | ||
} | ||
|
||
/** | ||
* This method create Region Admin | ||
* @param RegionAdmin: RegionAdmin | ||
* @param regionAdmin: RegionAdmin | ||
*/ | ||
createRegionAdmin(RegionAdmin: RegionAdmin): Observable<RegionAdmin> { | ||
return this.http.post<RegionAdmin>('/api/v1/RegionAdmin/Create', RegionAdmin); | ||
createAdmin(regionAdmin: RegionAdmin): Observable<RegionAdmin> { | ||
return <Observable<RegionAdmin>>super.createAdmin(regionAdmin); | ||
} | ||
|
||
/** | ||
* This method delete Region Admin by id | ||
* @param RegionAdminId: string | ||
* @param regionAdminId: string | ||
*/ | ||
deleteRegionAdmin(RegionAdminId: string): Observable<void> { | ||
let params = new HttpParams().set('RegionAdminId', `${RegionAdminId}`); | ||
|
||
return this.http.delete<void>('/api/v1/RegionAdmin/Delete', { params }); | ||
deleteAdmin(regionAdminId: string): Observable<void> { | ||
return super.deleteAdmin(regionAdminId); | ||
} | ||
|
||
/** | ||
* This method block Region Admin | ||
* @param RegionAdminId: string | ||
* @param regionAdminId: string | ||
*/ | ||
blockRegionAdmin(RegionAdminId: string, isBlocked: boolean): Observable<void> { | ||
let params = new HttpParams().set('RegionAdminId', `${RegionAdminId}`).set('isBlocked', `${isBlocked}`); | ||
|
||
return this.http.put<void>('/api/v1/RegionAdmin/Block', {}, { params }); | ||
blockAdmin(regionAdminId: string, isBlocked: boolean): Observable<void> { | ||
return super.blockAdmin(regionAdminId, isBlocked); | ||
} | ||
|
||
/** | ||
* This method update Region Admin | ||
* @param RegionAdmin: RegionAdmin | ||
* @param regionAdmin: RegionAdmin | ||
*/ | ||
updateRegionAdmin(RegionAdmin: RegionAdmin): Observable<RegionAdmin> { | ||
return this.http.put<RegionAdmin>('/api/v1/RegionAdmin/Update', RegionAdmin); | ||
updateAdmin(regionAdmin: RegionAdmin): Observable<RegionAdmin> { | ||
return <Observable<RegionAdmin>>super.updateAdmin(regionAdmin); | ||
} | ||
} |
Oops, something went wrong.