add mutation
This commit is contained in:
parent
c1edf10fa9
commit
39755ddf43
4
src/app/data/services/IChangeMerchantNameCommand.ts
Normal file
4
src/app/data/services/IChangeMerchantNameCommand.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export interface IChangeMerchantNameCommand {
|
||||||
|
merchantId: string;
|
||||||
|
newName: string;
|
||||||
|
}
|
5
src/app/data/services/IMerchant.ts
Normal file
5
src/app/data/services/IMerchant.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export interface IMerchant {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
address: string;
|
||||||
|
}
|
@ -1,36 +1,63 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { GraphQLDataSourceService } from '@poweredsoft/ngx-data-apollo';
|
import { GraphQLDataSourceService } from '@poweredsoft/ngx-data-apollo';
|
||||||
import { IDataSource, DataSource } from '@poweredsoft/data';
|
import { IDataSource, DataSource } from '@poweredsoft/data';
|
||||||
|
import { Apollo } from 'apollo-angular';
|
||||||
export interface IMerchant{
|
import { gql } from 'graphql-tag';
|
||||||
id: string,
|
import { of } from 'rxjs';
|
||||||
name: string,
|
import { IChangeMerchantNameCommand } from './IChangeMerchantNameCommand';
|
||||||
address: string
|
import { IMerchant } from './IMerchant';
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class MerchantService {
|
export class MerchantService {
|
||||||
|
constructor(
|
||||||
constructor(private dataSourceGenericService: GraphQLDataSourceService) {
|
private dataSourceGenericService: GraphQLDataSourceService,
|
||||||
|
private apollo: Apollo
|
||||||
dataSourceGenericService
|
) {}
|
||||||
}
|
|
||||||
|
|
||||||
createMerchantDataSource(): IDataSource<IMerchant> {
|
createMerchantDataSource(): IDataSource<IMerchant> {
|
||||||
const optionsBuilder = this.dataSourceGenericService.createDataSourceOptionsBuilder<IMerchant, string>(
|
const builder = this.dataSourceGenericService.createDataSourceOptionsBuilder<
|
||||||
|
IMerchant,
|
||||||
|
string
|
||||||
|
>(
|
||||||
'merchants',
|
'merchants',
|
||||||
'GraphQLAdvanceQueryOfMerchantInput',
|
'GraphQLAdvanceQueryOfMerchantInput',
|
||||||
'id, name, address',
|
'id, name, address',
|
||||||
(model) => model.id,
|
(model) => model.id,
|
||||||
{
|
{
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize: 4
|
pageSize: 4,
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
const options = optionsBuilder.create();
|
|
||||||
|
builder.addMutation<IChangeMerchantNameCommand, string>(
|
||||||
|
'changeMerchantName', //<-- command name
|
||||||
|
'changeMerchantName', //<-- graph ql mutation name
|
||||||
|
|
||||||
|
// implementation of the command.
|
||||||
|
command => {
|
||||||
|
return this.apollo.use('command').mutate<string>({
|
||||||
|
mutation: gql`
|
||||||
|
mutation executeChangeName($command: changeMerchantNameInput) {
|
||||||
|
changeMerchantName(params: $command)
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
variables: {
|
||||||
|
command: command,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// viewModel -> transform to the form model for that command -> IChangeMerchantName
|
||||||
|
e => of(<IChangeMerchantNameCommand>{
|
||||||
|
merchantId: e.model.id,
|
||||||
|
newName: e.model.name,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const options = builder.create();
|
||||||
return new DataSource<IMerchant>(options);
|
return new DataSource<IMerchant>(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user