ngx data :)

This commit is contained in:
David Lebee
2019-09-05 00:14:04 -05:00
parent 3efc179756
commit c89cc92d33
10 changed files with 181 additions and 105 deletions
+4 -2
View File
@@ -1,8 +1,10 @@
{
"name": "@poweredsoft/ngx-data",
"version": "0.0.1",
"version": "0.0.6",
"peerDependencies": {
"@angular/common": "^8.2.4",
"@angular/core": "^8.2.4"
"@angular/core": "^8.2.4",
"@poweredsoft/data": "^0.0.14",
"rxjs": "^6.5.3"
}
}
@@ -1,25 +0,0 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NgxDataComponent } from './ngx-data.component';
describe('NgxDataComponent', () => {
let component: NgxDataComponent;
let fixture: ComponentFixture<NgxDataComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ NgxDataComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NgxDataComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -1,19 +0,0 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'lib-ngx-data',
template: `
<p>
ngx-data works!
</p>
`,
styles: []
})
export class NgxDataComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
@@ -1,12 +1,11 @@
import { NgModule } from '@angular/core';
import { NgxDataComponent } from './ngx-data.component';
@NgModule({
declarations: [NgxDataComponent],
declarations: [],
imports: [
],
exports: [NgxDataComponent]
exports: [],
})
export class NgxDataModule { }
@@ -1,12 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { NgxDataService } from './ngx-data.service';
describe('NgxDataService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: NgxDataService = TestBed.get(NgxDataService);
expect(service).toBeTruthy();
});
});
@@ -1,9 +1,65 @@
import { Injectable } from '@angular/core';
import { Injectable } from "@angular/core";
import { HttpClient } from '@angular/common/http';
import { IDataSourceTransportOptions, IDataSourceCommandAdapterOptions } from '@poweredsoft/data';
import { IQueryExecutionResult, IQueryExecutionGroupResult, IQueryCriteria } from '@poweredsoft/data';
import { IDataSourceQueryAdapterOptions } from '@poweredsoft/data';
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class NgxDataService {
export class GenericRestDataSourceService
{
constructor(private http: HttpClient) {
constructor() { }
}
}
createStandardRestTransportOptions<TModel, TKey>(route: string, keyResolver: (model: TModel) => TKey) : IDataSourceTransportOptions<TModel> {
const query: IDataSourceQueryAdapterOptions<TModel> = {
adapter: {
handle: (criteria: IQueryCriteria) => {
const queryRoute = `${route}/read`;
return this.http.post<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>(queryRoute, criteria);
}
}
};
const createCommand: IDataSourceCommandAdapterOptions<TModel> = {
adapter: {
handle: (command: TModel) => {
return this.http.post<TModel>(route, command);
}
}
};
const updateCommand: IDataSourceCommandAdapterOptions<TModel> = {
adapter: {
handle: (command: TModel) => {
const key = keyResolver(command);
const updateRoute = `${route}/${encodeURIComponent(key as any)}`;
return this.http.put<TModel>(updateRoute, command);
}
}
};
const deleteCommand: IDataSourceCommandAdapterOptions<TModel> = {
adapter: {
handle: (command: TModel) => {
const key = keyResolver(command);
const updateRoute = `${route}/${encodeURIComponent(key as any)}`;
return this.http.delete<TModel>(updateRoute);
}
}
};
return {
query: query,
commands: {
'create': createCommand,
'update': updateCommand,
'delete': deleteCommand
}
};
}
}
@@ -3,5 +3,4 @@
*/
export * from './lib/ngx-data.service';
export * from './lib/ngx-data.component';
export * from './lib/ngx-data.module';
-21
View File
@@ -1,21 +0,0 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);