Aw4645 Add admin service
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good

This commit is contained in:
Peter Bastiani 2023-02-09 14:09:47 +01:00
parent e6e10c835e
commit 8c3c40cfe6
2 changed files with 43 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import { SchemaService } from './services/schema.service';
import { FolderService } from './services/folder.service';
import { TimespanService } from './services/timespan.service';
import { ItemService } from './services/item.service';
import { AdminService } from './services/admin.service';
import { EventService } from './services/event.service';
import { TypeaheadService } from './services/typeahead.service';
import { UserService } from './services/user.service';
@ -42,6 +43,7 @@ export {
ItemTypeService,
TimespanService,
ItemService,
AdminService,
EventService,
TypeaheadService,
UserService,

View File

@ -0,0 +1,41 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { IItem } from '../models/item';
import { HttpClient, HttpParams } from "@angular/common/http";
import { AppConfig } from "../shared/app.config";
import {ItemTypeService} from './itemtype.service';
@Injectable({
providedIn: 'root',
})
export class AdminService {
constructor(public httpClient: HttpClient, public appConfig: AppConfig,private itemTypeService:ItemTypeService) {
}
ApiEndpoint() {
return this.appConfig.getConfig("apiEndPoint");
}
getItemList(itemType?: string, dataFilter?: any, level?: number, atItemLocationItemCode?: string, indexed?: boolean, validToday?: boolean): Observable<IItem[]> {
var params = new HttpParams();
if(itemType) params = params.append("it", itemType);
if(dataFilter) params = params.append("df", JSON.stringify(dataFilter));
if(atItemLocationItemCode) params = params.append("ail",atItemLocationItemCode);
if(indexed) params = params.append("ind",indexed?"true":"false");
if (level) params = params.append("lvl", level.toFixed());
if (validToday) params = params.append("vt", validToday ? "true" : "false");
return this.httpClient.get<IItem[]>(`${this.ApiEndpoint()}/api/v1/admin/`, { params: params });
}
postItem(item:IItem): Observable<IItem> {
return this.httpClient.post<IItem>(`${this.ApiEndpoint()}/api/v1/admin`,item);
}
putItem(item:IItem): Observable<IItem> {
return this.httpClient.put<IItem>(`${this.ApiEndpoint()}/api/v1/admin/${item.code}`,item);
}
deleteItem(code: string): Observable<any> {
return this.httpClient.delete<any>(`${this.ApiEndpoint()}/api/v1/admin/${code}`);
}
}