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 { GraphQLDataSourceService } from '@poweredsoft/ngx-data-apollo';
|
||||
import { IDataSource, DataSource } from '@poweredsoft/data';
|
||||
|
||||
export interface IMerchant{
|
||||
id: string,
|
||||
name: string,
|
||||
address: string
|
||||
}
|
||||
import { Apollo } from 'apollo-angular';
|
||||
import { gql } from 'graphql-tag';
|
||||
import { of } from 'rxjs';
|
||||
import { IChangeMerchantNameCommand } from './IChangeMerchantNameCommand';
|
||||
import { IMerchant } from './IMerchant';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class MerchantService {
|
||||
|
||||
constructor(private dataSourceGenericService: GraphQLDataSourceService) {
|
||||
|
||||
dataSourceGenericService
|
||||
}
|
||||
constructor(
|
||||
private dataSourceGenericService: GraphQLDataSourceService,
|
||||
private apollo: Apollo
|
||||
) {}
|
||||
|
||||
createMerchantDataSource(): IDataSource<IMerchant> {
|
||||
const optionsBuilder = this.dataSourceGenericService.createDataSourceOptionsBuilder<IMerchant, string>(
|
||||
const builder = this.dataSourceGenericService.createDataSourceOptionsBuilder<
|
||||
IMerchant,
|
||||
string
|
||||
>(
|
||||
'merchants',
|
||||
'GraphQLAdvanceQueryOfMerchantInput',
|
||||
'id, name, address',
|
||||
(model) => model.id,
|
||||
{
|
||||
page: 1,
|
||||
pageSize: 4
|
||||
pageSize: 4,
|
||||
},
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user