Проинтегрировал обновление моков

master
Sipachev Igor 3 years ago
parent 47c51fb5fa
commit 2c0d4ba69a
  1. 12
      popup/src/api/HttpClient.ts
  2. 5
      popup/src/api/Main/HttpClient.ts
  3. 11
      popup/src/api/Main/Schemas/ChangeMockValueSchema.ts
  4. 2
      popup/src/components/mocks-tab/template.html
  5. 41
      popup/src/components/mocks/script.ts
  6. 4
      popup/src/components/mocks/template.html

@ -43,11 +43,19 @@ export class HttpClient {
} }
send (schema: SchemaInterface, data: any | null = null): Promise<AxiosResponse> { send (schema: SchemaInterface, data: any | null = null): Promise<AxiosResponse> {
let url = schema.url
const preparedData = data
for (const key in data) {
if (url.indexOf('{' + key + '}') > -1) {
url = url.replace('{' + key + '}', preparedData[key])
delete preparedData[key]
}
}
console.log(data, 'data') console.log(data, 'data')
const requestData = { const requestData = {
method: schema.method as Method, method: schema.method as Method,
url: this.baseUrl + schema.url, url: this.baseUrl + url,
data: data, data: preparedData,
headers: { headers: {
'Content-Type': 'application/json;charset=utf-8' 'Content-Type': 'application/json;charset=utf-8'
} }

@ -3,6 +3,7 @@ import MocksSchema, { MockConfigurationsRequest } from '../../api/Main/Schemas/M
import { SchemaInterface } from '@/api/SchemaInterface' import { SchemaInterface } from '@/api/SchemaInterface'
import { TokenRequestHandler } from '@/api/Handlers/TokenRequestHandler' import { TokenRequestHandler } from '@/api/Handlers/TokenRequestHandler'
import AddMockSchema, { AddMockConfigurationsRequest } from '@/api/Main/Schemas/AddMockSchema' import AddMockSchema, { AddMockConfigurationsRequest } from '@/api/Main/Schemas/AddMockSchema'
import ChangeMockValueSchema, { ChangeMockConfigurationValueRequest } from '@/api/Main/Schemas/ChangeMockValueSchema'
export class HttpClient extends BaseClient { export class HttpClient extends BaseClient {
mockConfigurations (data: MockConfigurationsRequest): any { mockConfigurations (data: MockConfigurationsRequest): any {
@ -12,6 +13,10 @@ export class HttpClient extends BaseClient {
addMockConfigurations (data: AddMockConfigurationsRequest): any { addMockConfigurations (data: AddMockConfigurationsRequest): any {
return this.send(AddMockSchema as SchemaInterface, data) return this.send(AddMockSchema as SchemaInterface, data)
} }
changeMockValueConfiguration (data: ChangeMockConfigurationValueRequest): any {
return this.send(ChangeMockValueSchema as SchemaInterface, data)
}
} }
export default new HttpClient('http://placetgroup.sipachev.sv') export default new HttpClient('http://placetgroup.sipachev.sv')

@ -0,0 +1,11 @@
export class ChangeMockConfigurationValueRequest {
id!: string
value!: string
}
export default {
code: 'api_plugin_change_configuration_value',
method: 'PATCH',
url: '/plugin/mock-configurations/{id}/value',
prefix: 'mockConfigurations'
}

@ -5,6 +5,6 @@
</label> </label>
<div v-if="personalCode"> <div v-if="personalCode">
<hr /> <hr />
<Mocks :personalId="personalCode"></Mocks> <Mocks :personalCode="personalCode"></Mocks>
</div> </div>
</div> </div>

@ -1,4 +1,4 @@
import { Component, Prop, Vue } from 'vue-property-decorator' import { Component, Prop, Vue, Watch } from 'vue-property-decorator'
import VueClipboard from 'vue-clipboard2' import VueClipboard from 'vue-clipboard2'
import { Registers } from '@/classes/DTO/Registers' import { Registers } from '@/classes/DTO/Registers'
import httpClient from '@/api/Main/HttpClient' import httpClient from '@/api/Main/HttpClient'
@ -6,15 +6,51 @@ import { MockConfiguration } from '@/api/Main/Schemas/AddMockSchema'
Vue.use(VueClipboard) Vue.use(VueClipboard)
export enum Mode {
ADD = 'add',
UPDATE = 'update',
}
@Component @Component
export default class Mocks extends Vue { export default class Mocks extends Vue {
@Prop() @Prop()
personalCode!: string personalCode!: string
mode: Mode = Mode.ADD
registers = new Registers() registers = new Registers()
register2Id: Record<string, string> = {}
mounted () { mounted () {
console.log('mounted') console.log('mounted', this.personalCode)
}
@Watch('personalCode', { immediate: true })
onPersonalCodeChanged (value: string, oldValue: string) {
this.mode = Mode.ADD
httpClient.mockConfigurations({ personalCode: this.personalCode })
.then((data: any) => {
for (const mockConfiguration of data.data) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
this.registers[mockConfiguration.code] = mockConfiguration.value
this.register2Id[mockConfiguration.code] = mockConfiguration.id
this.mode = Mode.UPDATE
}
})
}
onXteeMtaChanged () {
if (this.register2Id.xtee_mta === 'undefined') {
return
}
httpClient.changeMockValueConfiguration({
id: this.register2Id.xtee_mta,
value: this.registers.xtee_mta
})
.then((data: any) => {
console.log('updateMock')
console.log(data)
})
} }
saveMocks () { saveMocks () {
@ -23,6 +59,7 @@ export default class Mocks extends Vue {
const mockConfiguration = new MockConfiguration() const mockConfiguration = new MockConfiguration()
mockConfiguration.personalCode = this.personalCode mockConfiguration.personalCode = this.personalCode
mockConfiguration.code = serviceCode mockConfiguration.code = serviceCode
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore // @ts-ignore
mockConfiguration.value = this.registers[serviceCode] mockConfiguration.value = this.registers[serviceCode]
if (!mockConfiguration.value) { if (!mockConfiguration.value) {

@ -11,7 +11,7 @@
<!-- 9 - выписка на хороший доход, в выписке есть выплаты, которые не учитываются в подсчёте среднего дохода--> <!-- 9 - выписка на хороший доход, в выписке есть выплаты, которые не учитываются в подсчёте среднего дохода-->
<label> <label>
XTEE MTA XTEE MTA
<select class="option-select" v-model="registers.xtee_mta"> <select class="option-select" v-model="registers.xtee_mta" @change="onXteeMtaChanged">
<option value="">-</option> <option value="">-</option>
<option value="0">Не замокано (делать запрос)</option> <option value="0">Не замокано (делать запрос)</option>
<option value="1">Выписка на хороший доход</option> <option value="1">Выписка на хороший доход</option>
@ -35,5 +35,5 @@
<!-- </select>--> <!-- </select>-->
<!-- </label>--> <!-- </label>-->
<br /><br /> <br /><br />
<button @click="saveMocks">Сохранить моки</button> <button v-if="'add' === mode" @click="saveMocks">Сохранить моки</button>
</div> </div>

Loading…
Cancel
Save