Настроил использование внешнего апи.

проинтегрировал создание моков
master
Sipachev Igor 3 years ago
parent 5461b2241b
commit 47c51fb5fa
  1. 11
      popup/src/api/Handlers/TokenRequestHandler.ts
  2. 17
      popup/src/api/HttpClient.ts
  3. 7
      popup/src/api/Main/HttpClient.ts
  4. 17
      popup/src/api/Main/Schemas/AddMockSchema.ts
  5. 4
      popup/src/api/Main/Schemas/MocksSchema.ts
  6. 1
      popup/src/api/SchemaInterface.ts
  7. 4
      popup/src/classes/DTO/Registers.ts
  8. 2
      popup/src/components/mocks-tab/script.ts
  9. 6
      popup/src/components/mocks-tab/template.html
  10. 18
      popup/src/components/mocks/script.ts
  11. 4
      popup/src/components/mocks/template.html
  12. 22
      popup/src/components/person-tab/script.ts
  13. 8
      popup/src/components/person-tab/template.html
  14. 2
      popup/src/stubs/config.ts

@ -0,0 +1,11 @@
import { RequestHandler, RequestInterface } from '@/api/HttpClient'
export class TokenRequestHandler extends RequestHandler {
handle = (request: RequestInterface): void => {
request.headers = request.headers || {}
request.headers['x-token'] = 'GxwGRM'
console.log(request, 'DeviceIdHandler')
}
}
export default new TokenRequestHandler()

@ -43,9 +43,10 @@ export class HttpClient {
}
send (schema: SchemaInterface, data: any | null = null): Promise<AxiosResponse> {
console.log(data, 'data')
const requestData = {
method: schema.method as Method,
url: schema.url,
url: this.baseUrl + schema.url,
data: data,
headers: {
'Content-Type': 'application/json;charset=utf-8'
@ -65,7 +66,19 @@ export class HttpClient {
})
const stub = stubResolver.handle(schema.code)
const response = stub || axios(requestData as AxiosRequestConfig)
const axiosData = requestData as AxiosRequestConfig
if (schema.prefix) {
const temp: any = {}
temp[schema.prefix] = axiosData.data
axiosData.data = temp
}
if (axiosData.method === 'GET') {
axiosData.params = axiosData.data
delete axiosData.data
}
const response = stub || axios(axiosData)
return response
.then((response: any) => {

@ -1,11 +1,18 @@
import { HttpClient as BaseClient } from '../../api/HttpClient'
import MocksSchema, { MockConfigurationsRequest } from '../../api/Main/Schemas/MocksSchema'
import { SchemaInterface } from '@/api/SchemaInterface'
import { TokenRequestHandler } from '@/api/Handlers/TokenRequestHandler'
import AddMockSchema, { AddMockConfigurationsRequest } from '@/api/Main/Schemas/AddMockSchema'
export class HttpClient extends BaseClient {
mockConfigurations (data: MockConfigurationsRequest): any {
return this.send(MocksSchema as SchemaInterface, data)
}
addMockConfigurations (data: AddMockConfigurationsRequest): any {
return this.send(AddMockSchema as SchemaInterface, data)
}
}
export default new HttpClient('http://placetgroup.sipachev.sv')
.addHandler(new TokenRequestHandler())

@ -0,0 +1,17 @@
export class MockConfiguration {
personalCode!: string
code!: string
value!: string
active!: string
}
export class AddMockConfigurationsRequest {
items!: MockConfiguration[]
}
export default {
code: 'api_plugin_add_configurations',
method: 'POST',
url: '/plugin/mock-configurations',
prefix: 'mockConfigurations'
}

@ -1,9 +1,9 @@
export class MockConfigurationsRequest {
personalId!: string
personalCode!: string
}
export default {
code: 'api_plugin_get_configurations',
method: 'POST',
method: 'GET',
url: '/plugin/mock-configurations'
}

@ -3,4 +3,5 @@ export interface SchemaInterface {
method: string;
url: string;
stub: any;
prefix?: string;
}

@ -1,4 +1,4 @@
export class Registers {
xteeMta = ''
xteePension = ''
xtee_mta = ''
xtee_pension = ''
}

@ -10,5 +10,5 @@ Vue.use(VueClipboard)
}
})
export default class MocksTab extends Vue {
personalId = ''
personalCode = ''
}

@ -1,10 +1,10 @@
<div>
<label>
Personal id
<input type="text" v-model="personalId"/>
<input type="text" v-model="personalCode"/>
</label>
<div v-if="personalId">
<div v-if="personalCode">
<hr />
<Mocks :personalId="personalId"></Mocks>
<Mocks :personalId="personalCode"></Mocks>
</div>
</div>

@ -2,13 +2,14 @@ import { Component, Prop, Vue } from 'vue-property-decorator'
import VueClipboard from 'vue-clipboard2'
import { Registers } from '@/classes/DTO/Registers'
import httpClient from '@/api/Main/HttpClient'
import { MockConfiguration } from '@/api/Main/Schemas/AddMockSchema'
Vue.use(VueClipboard)
@Component
export default class Mocks extends Vue {
@Prop()
personalId!: string
personalCode!: string
registers = new Registers()
@ -17,7 +18,20 @@ export default class Mocks extends Vue {
}
saveMocks () {
httpClient.mockConfigurations({ personalId: '48907031677' })
const mockConfigurations: MockConfiguration[] = []
for (const serviceCode in this.registers) {
const mockConfiguration = new MockConfiguration()
mockConfiguration.personalCode = this.personalCode
mockConfiguration.code = serviceCode
// @ts-ignore
mockConfiguration.value = this.registers[serviceCode]
if (!mockConfiguration.value) {
continue
}
mockConfiguration.active = 'true'
mockConfigurations.push(mockConfiguration)
}
httpClient.addMockConfigurations({ items: mockConfigurations })
.then((data: any) => {
console.log('saveMocks')
console.log(data)

@ -11,7 +11,7 @@
<!-- 9 - выписка на хороший доход, в выписке есть выплаты, которые не учитываются в подсчёте среднего дохода-->
<label>
XTEE MTA
<select class="option-select" v-model="registers.xteeMta">
<select class="option-select" v-model="registers.xtee_mta">
<option value="">-</option>
<option value="0">Не замокано (делать запрос)</option>
<option value="1">Выписка на хороший доход</option>
@ -28,7 +28,7 @@
<!-- <br /><br />-->
<!-- <label>-->
<!-- XTEE Pension-->
<!-- <select class="option-select" v-model="registers.xteePension">-->
<!-- <select class="option-select" v-model="registers.xtee_pension">-->
<!-- <option value="">-</option>-->
<!-- <option value="0">Не замокано (делать запрос)</option>-->
<!-- <option value="2">Ошибка сервиса. (перезапросы)</option>-->

@ -19,7 +19,7 @@ Vue.use(VueClipboard)
}
})
export default class PersonTab extends Vue {
personalId = ''
personalCode = ''
person = new Person()
copyText = ''
@ -40,21 +40,21 @@ export default class PersonTab extends Vue {
return result
}
copyPersonalId () {
const personalId = personalIdGenerator.generate(this.person)
this.personalId = personalId
this.copy(personalId)
copyPersonalCode () {
const personalCode = personalIdGenerator.generate(this.person)
this.personalCode = personalCode
this.copy(personalCode)
}
copyIban () {
const iban = ibanGenerator.generate(this.person.country)
this.personalId = ''
this.personalCode = ''
this.copy(iban)
}
copyPhone () {
const phone = phoneGenerator.generate(this.person.country)
this.personalId = ''
this.personalCode = ''
this.copy(phone)
}
@ -64,10 +64,10 @@ export default class PersonTab extends Vue {
}
autocomplete () {
const personalId = personalIdGenerator.generate(this.person)
this.personalId = personalId
this.copy(personalId)
this.insertValueToNode(Target.PERSONAL_ID, personalId)
const personalCode = personalIdGenerator.generate(this.person)
this.personalCode = personalCode
this.copy(personalCode)
this.insertValueToNode(Target.PERSONAL_ID, personalCode)
const iban = ibanGenerator.generate(this.person.country)
this.insertValueToNode(Target.IBAN, iban)
const phone = phoneGenerator.generate(this.person.country)

@ -42,9 +42,9 @@
<button>Autocomplete</button>
</div>
<div
@click="copyPersonalId"
@click="copyPersonalCode"
class="form-row__item copy-button" data-clipboard-text="text2">
<button>PersonalId</button>
<button>personalCode</button>
</div>
<div
@click="copyIban"
@ -58,8 +58,8 @@
</div>
</div>
<div class="memory-panel">Memory: {{copyText}}</div>
<div v-if="personalId">
<div v-if="personalCode">
<hr />
<Mocks :personalId="personalId"></Mocks>
<Mocks :personalCode="personalCode"></Mocks>
</div>
</div>

@ -1,4 +1,4 @@
import { FlowEnum } from '@/stubs/FlowEnum'
export const useStub = true
export const useStub = false
export const flow = FlowEnum.base

Loading…
Cancel
Save