mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-24 03:10:13 +01:00
saving with admin and public base
This commit is contained in:
parent
06776d15c4
commit
dd1b2763d8
425 changed files with 21493 additions and 11663 deletions
66
src/app/admin/banner/banner.service.ts
Normal file
66
src/app/admin/banner/banner.service.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { delay, map } from 'rxjs/operators';
|
||||
import { Apollo } from 'apollo-angular';
|
||||
import { FIND_UNIQUE_BANNER, LIST_BANNERS } from './graphql/queries';
|
||||
import { Banner } from './banner.model';
|
||||
import { CREATE_BANNER, UPDATE_BANNER } from './graphql/mutations';
|
||||
|
||||
const TOTAL_PAGES = 7;
|
||||
|
||||
export class NewsPost {
|
||||
title: string;
|
||||
link: string;
|
||||
creator: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class BannerService {
|
||||
|
||||
constructor(private http: HttpClient, private readonly apollo: Apollo) {}
|
||||
|
||||
load(page: number, pageSize: number): Observable<NewsPost[]> {
|
||||
const startIndex = ((page - 1) % TOTAL_PAGES) * pageSize;
|
||||
|
||||
return this.http
|
||||
.get<NewsPost[]>('assets/data/news.json')
|
||||
.pipe(
|
||||
map(news => news.splice(startIndex, pageSize)),
|
||||
delay(1500),
|
||||
);
|
||||
}
|
||||
|
||||
listBanners(): Observable<any> {
|
||||
return this.apollo
|
||||
.watchQuery<Banner>({
|
||||
query: LIST_BANNERS(),
|
||||
})
|
||||
.valueChanges
|
||||
}
|
||||
|
||||
findUniqueBanner(id: Banner["id"]): Observable<any> {
|
||||
return this.apollo
|
||||
.watchQuery<Banner>({
|
||||
query: FIND_UNIQUE_BANNER(id),
|
||||
})
|
||||
.valueChanges
|
||||
}
|
||||
|
||||
createBanner(banner: Banner) {
|
||||
console.log(CREATE_BANNER(banner));
|
||||
return this.apollo
|
||||
.mutate<any>({
|
||||
mutation: CREATE_BANNER(banner),
|
||||
});
|
||||
}
|
||||
|
||||
updateBanner(banner: Banner) {
|
||||
console.log(UPDATE_BANNER(banner));
|
||||
return this.apollo
|
||||
.mutate({
|
||||
mutation: UPDATE_BANNER(banner),
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue