Skip to content

Commit 2498575

Browse files
authored
Merge pull request #450 from chantouchsek/fix/449-fill-method
Make fill method print the same the value from api
2 parents c298ae0 + ddb6b08 commit 2498575

File tree

2 files changed

+9
-37
lines changed

2 files changed

+9
-37
lines changed

src/core/BaseService.ts

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,15 @@ class BaseService {
6161
return this.submit<T>('get', id)
6262
}
6363

64-
post<T>(payload: any): Promise<T>
65-
post<T>(payload: any, config?: AxiosRequestConfig): Promise<T>
6664
post<T>(payload: any, config?: AxiosRequestConfig) {
6765
return this.submit<T>('post', '', payload, config)
6866
}
6967

70-
store<T>(payload: any): Promise<T>
71-
store<T>(payload: any, config?: AxiosRequestConfig): Promise<T>
7268
store<T>(payload: any, config?: AxiosRequestConfig) {
7369
return this.post<T>(payload, config)
7470
}
7571

76-
put<T>(payload: any, config?: AxiosRequestConfig): Promise<T>
77-
put<T>(
78-
id: string | number,
79-
payload: any,
80-
config?: AxiosRequestConfig,
81-
): Promise<T>
82-
put<T>(id: string | number, payload?: any, config?: AxiosRequestConfig) {
72+
put<T>(id: any, payload?: any, config?: AxiosRequestConfig) {
8373
const parameter = id && !isObject(id) ? `/${id}` : ''
8474
const body = isObject(id) ? id : payload
8575
const requestType: Method = hasFiles(body) ? 'post' : 'put'
@@ -89,13 +79,7 @@ class BaseService {
8979
return this.submit<T>(requestType, parameter, body, config)
9080
}
9181

92-
patch<T>(payload: any, config?: AxiosRequestConfig): Promise<T>
93-
patch<T>(
94-
id: string | number,
95-
payload: any,
96-
config?: AxiosRequestConfig,
97-
): Promise<T>
98-
patch<T>(id: string | number, payload?: any, config?: AxiosRequestConfig) {
82+
patch<T>(id: any, payload?: any, config?: AxiosRequestConfig) {
9983
const parameter = id && !isObject(id) ? `/${id}` : ''
10084
const body = isObject(id) ? id : payload
10185
return this.submit<T>('patch', parameter, body, config)
@@ -114,12 +98,12 @@ class BaseService {
11498
}
11599

116100
submit<T = any>(
117-
requestType: Method,
101+
method: Method,
118102
parameter?: string | number,
119103
form?: T,
120104
config?: AxiosRequestConfig,
121105
): Promise<T> {
122-
const method = BaseService.__validateRequestType(requestType)
106+
BaseService.__validateRequestType(method)
123107
this.beforeSubmit()
124108
return new Promise((resolve, reject) => {
125109
const data = hasFiles(form) ? objectToFormData(form) : form
@@ -190,8 +174,6 @@ class BaseService {
190174
return this
191175
}
192176

193-
setParameter(parameter: string): this
194-
setParameter(parameter: string, value?: any): this
195177
setParameter(parameter: string, value?: any): this {
196178
if (!value) {
197179
const options: IParseOptions = Object.assign({}, this.$parsedQs, {
@@ -206,8 +188,6 @@ class BaseService {
206188
return this
207189
}
208190

209-
removeParameters(): this
210-
removeParameters(parameters: any[]): this
211191
removeParameters(parameters = [] as any[]): this {
212192
if (!parameters || !parameters.length) {
213193
this.parameters = []

src/core/Validator.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hasOwnProperty, is, isArray } from '../util'
1+
import { is } from '../util'
22
import get from 'lodash.get'
33
import has from 'lodash.has'
44

@@ -7,10 +7,10 @@ class Validator {
77
public successful: boolean
88
public processing: boolean
99

10-
constructor() {
10+
constructor(errors: Record<string, any> = {}) {
1111
this.processing = false
1212
this.successful = false
13-
this.errors = {}
13+
this.errors = errors
1414
}
1515

1616
add(attribute: string, message: string) {
@@ -23,7 +23,7 @@ class Validator {
2323
}
2424

2525
has(field: string | string[]) {
26-
if (isArray(field)) {
26+
if (Array.isArray(field)) {
2727
return is(Object.keys(this.errors), field)
2828
}
2929
let hasError = has(this.errors, field)
@@ -57,7 +57,7 @@ class Validator {
5757
} else {
5858
value = obj[field]
5959
}
60-
if (isArray(value)) value = value[0]
60+
if (Array.isArray(value)) value = value[0]
6161
return value
6262
}
6363

@@ -99,14 +99,6 @@ class Validator {
9999
}
100100

101101
fill(errors: Record<string, any>) {
102-
for (const error in errors) {
103-
if (!hasOwnProperty(errors, error)) {
104-
continue
105-
}
106-
if (!(errors[error] instanceof Array)) {
107-
errors[error] = [errors[error]]
108-
}
109-
}
110102
this.errors = errors
111103
}
112104

0 commit comments

Comments
 (0)