new song sync

This commit is contained in:
Benjamin Ifland
2019-03-25 18:04:30 +01:00
parent dc01c60e67
commit 42e9936b6c
9 changed files with 94 additions and 27 deletions

View File

@@ -1,15 +1,16 @@
import { ODataService, ODataQuery } from "odata-v4-ng";
import { Observable } from "rxjs";
import { map, tap } from "rxjs/operators";
import { base } from "./urls";
import { Song } from 'src/app/models/song.model';
import { ODataService, ODataQuery } from 'odata-v4-ng';
import { Observable } from 'rxjs';
import { map, tap } from 'rxjs/operators';
import { base } from './urls';
export class OdataService {
private url: string;
constructor(private odataService: ODataService, private entity: string) {
this.url = base + "/odata/";
this.url = base + '/odata/';
}
public list<TResponse>(properties: string[]): Observable<TResponse[]> {
public list$<TResponse>(properties: string[]): Observable<TResponse[]> {
const query = new ODataQuery(this.odataService, this.url)
.entitySet(this.entity)
.select(properties);
@@ -18,7 +19,7 @@ export class OdataService {
return get;
}
public get<TResponse>(
public get$<TResponse>(
id: number,
properties: string[]
): Observable<TResponse> {
@@ -31,15 +32,30 @@ export class OdataService {
return get;
}
public patch(id: number, control: string, value: any): Observable<boolean> {
public patch$(id: number, control: string, value: any): Observable<boolean> {
const valueSet = { [control]: value };
const query = new ODataQuery(this.odataService, this.url)
.entitySet(this.entity)
.entityKey(id);
const get = query.patch(valueSet).pipe(
map(() => true)
);
const get = query.patch(valueSet).pipe(map(() => true));
return get;
}
public post$<TResponse>(values: any): Observable<TResponse> {
const querry = new ODataQuery(this.odataService, this.url);
const post = querry
.entitySet(this.entity)
.post(values)
.pipe(
tap(_ => console.log(_)),
map(_ => {
const mapped = _.toEntity<TResponse>();
return mapped;
}),
tap(_ => console.log(_))
);
return post;
}
}