bx-rest 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +130 -53
- package/spec/tsconfig.json +15 -0
- package/src/consts/part-name-metods.ts +11 -0
- package/src/functions/isDate.ts +8 -0
- package/src/functions/isEqual.ts +17 -0
- package/src/functions/isValidDate.ts +9 -0
- package/src/functions/serializeJavascript.ts +229 -0
- package/src/rest/user/user.ts +18 -17
- package/src/services/base.ts +2 -2
- package/src/services/http/HttpBX.ts +176 -0
- package/src/services/http/HttpData.ts +3 -3
- package/src/services/http/base/HttpData.ts +5 -4
- package/src/services/http/base/base.ts +4 -3
- package/src/services/http/base/http.ts +2 -2
- package/src/services/http/http.ts +5 -5
- package/src/services/http/sessionKey.ts +18 -27
- package/src/services/map/base.ts +8 -0
- package/src/services/map/rest/user.ts +82 -0
- package/src/services/snack-bar/snack-bar.service.ts +1 -1
- package/src/services/vanilla/JSON.ts +1 -1
- package/src/services/vanilla/iframe.ts +2 -2
- package/src/services/vanilla/localStorage.ts +1 -1
- package/src/services/vanilla//321/201ookies.ts +1 -1
- package/src/store/auth.ts +1 -1
- package/src/store/users.ts +88 -0
- package/src/tsconfig.base.json +4 -10
- package/src/tsconfig.types.json +1 -1
- package/src/typification/rest/api-lib.ts +2 -2
- package/src/typification/rest/batch/batchRequestParam.ts +1 -1
- package/src/typification/rest/user/CustomUserFieldInfo.ts +2 -2
- package/src/typification/rest/user/user.ts +1 -1
- package/src/typification/rest/user/userFilter.ts +17 -0
- package/tools/add-license-to-file.js +30 -0
- package/tools/generate-alias.js +30 -0
- package/tools/subject-benchmark.js +281 -0
- package/tsconfig.json +19 -6
- package/src/services/snack-bar/toast-message/toast-message.component.spec.ts +0 -24
- /package/src/{const → consts}/time.ts +0 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { Observable, throwError, take, mergeMap, forkJoin } from 'rxjs'
|
|
2
|
+
import { catchError, map } from 'rxjs/operators'
|
|
3
|
+
import { Injectable } from '@angular/core'
|
|
4
|
+
import clone from 'just-clone'
|
|
5
|
+
import { iHttpParamSettings } from 'bx-rest/src/typification/rest/settings'
|
|
6
|
+
import BaseHttpServices from 'bx-rest/src/services/http/http'
|
|
7
|
+
import {
|
|
8
|
+
iBatchRequestAnswer, iBatchRequestParam,
|
|
9
|
+
iBatchRequestParamArr,
|
|
10
|
+
iBatchRequestParamHttp, keyBatch
|
|
11
|
+
} from 'bx-rest/src/typification/rest/batch/batchRequestParam'
|
|
12
|
+
import flatten from 'just-flatten-it'
|
|
13
|
+
|
|
14
|
+
@Injectable({
|
|
15
|
+
providedIn: 'root'
|
|
16
|
+
})
|
|
17
|
+
export default class HttpBXServices extends BaseHttpServices {
|
|
18
|
+
|
|
19
|
+
timeNowOnServer() {
|
|
20
|
+
return this.httpGet<{ result?: Date, error?: string }>('server.time').pipe(
|
|
21
|
+
map(v => {
|
|
22
|
+
if (v && v.result) {
|
|
23
|
+
return new Date(v.result)
|
|
24
|
+
}
|
|
25
|
+
return undefined
|
|
26
|
+
}),
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Это пиздец а не метод
|
|
32
|
+
* @param param
|
|
33
|
+
*/
|
|
34
|
+
branch<T, A>(param: iBatchRequestParamArr<T> | iBatchRequestParam<T>[]): Observable<iBatchRequestAnswer<A>[] | undefined> {
|
|
35
|
+
let prepareParam = Object.entries<string>(this.prepareBatch<T>(param))
|
|
36
|
+
const size = 50 // больше не отдаст
|
|
37
|
+
let subarray = [] //массив в который будет выведен результат.
|
|
38
|
+
for (let i = 0; i < Math.ceil(prepareParam.length / size); i++) {
|
|
39
|
+
subarray[i] = prepareParam.slice((i * size), (i * size) + size)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return forkJoin(
|
|
43
|
+
subarray.map(i => {
|
|
44
|
+
return this.httpPost('batch.json', {
|
|
45
|
+
halt: 0,
|
|
46
|
+
cmd: Object.assign({}, ...i.map(x => {
|
|
47
|
+
return {[x[0]]: x[1]}
|
|
48
|
+
}))
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
) as Observable<iBatchRequestAnswer<A>[]>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
prepareBatch<T>(param: iBatchRequestParamArr<T> | iBatchRequestParam<T>[]): iBatchRequestParamHttp {
|
|
55
|
+
let res: iBatchRequestParamHttp = Object.keys(param).reduce(
|
|
56
|
+
(obj, key) => {
|
|
57
|
+
obj[key] = '';
|
|
58
|
+
return obj;
|
|
59
|
+
},
|
|
60
|
+
{} as iBatchRequestParamHttp
|
|
61
|
+
);
|
|
62
|
+
for (let key in param) {
|
|
63
|
+
if(typeof key === 'string' || typeof key === 'number' && param[key].param) {
|
|
64
|
+
res[key] = param[key].name + '?' + this.getHttpParamsGet(param[key].param).toString()
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return res
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
mapBranchResult<T>(res: iBatchRequestAnswer<T>[]){
|
|
71
|
+
return Object.assign([], ...res.map(i => (i.result && i.result.result) ? i.result.result : undefined)) as {[key:keyBatch]: T}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
mapBranchResultWithoutKey<T>(res: iBatchRequestAnswer<T>[]): T[]{
|
|
75
|
+
return flatten<T>(Object.assign([], ...res.map(i => (i.result && i.result.result) ? i.result.result : undefined)))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
post<T>(name: string[],
|
|
79
|
+
params: any = {},
|
|
80
|
+
textError = '',
|
|
81
|
+
settings: iHttpParamSettings = this.defSettings) {
|
|
82
|
+
return this.httpPost<T>(this.getNameMethod(name), params, textError, settings)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get<T>(name: string[],
|
|
86
|
+
params: any = {},
|
|
87
|
+
textError = '',
|
|
88
|
+
settings: iHttpParamSettings = this.defSettings) {
|
|
89
|
+
return this.httpGet<T>(this.getNameMethod(name), params, textError, settings)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
override httpPost<T>(url: string,
|
|
93
|
+
params: any = {},
|
|
94
|
+
textError = '',
|
|
95
|
+
settings: iHttpParamSettings = this.defSettings
|
|
96
|
+
): Observable<T | undefined> {
|
|
97
|
+
return this.session.getAuthParams().pipe(
|
|
98
|
+
mergeMap(auth => {
|
|
99
|
+
if (auth) {
|
|
100
|
+
const paramsClone = clone(params)
|
|
101
|
+
paramsClone[this.session.getKeyAuth()] = auth
|
|
102
|
+
return this.session.getBaseUrl().pipe(mergeMap(v => {
|
|
103
|
+
if (v) {
|
|
104
|
+
return this.http.post<T | undefined>(
|
|
105
|
+
this.prepareBaseAddress(v) + url,
|
|
106
|
+
this.getHttpParamsPost(paramsClone, new FormData(), false, [], settings))
|
|
107
|
+
.pipe(
|
|
108
|
+
take(1),
|
|
109
|
+
catchError(err => {
|
|
110
|
+
if (!textError.length && err.error.error_description) {
|
|
111
|
+
textError = err.error.error_description
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this.snackBar.error('Ошибка: ' + textError)
|
|
115
|
+
return throwError(() => err)
|
|
116
|
+
})
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
return throwError(() => 'get base url error')
|
|
120
|
+
}))
|
|
121
|
+
} else {
|
|
122
|
+
this.snackBar.error('Error: Auth not get')
|
|
123
|
+
return throwError(() => 'auth not get')
|
|
124
|
+
}
|
|
125
|
+
}))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
override httpGet<T>(
|
|
129
|
+
url: string,
|
|
130
|
+
params: any = {},
|
|
131
|
+
textError = '',
|
|
132
|
+
settings: iHttpParamSettings = this.defSettings
|
|
133
|
+
): Observable<T | undefined> {
|
|
134
|
+
return this.session.getAuthParams().pipe(
|
|
135
|
+
mergeMap(auth => {
|
|
136
|
+
if (auth) {
|
|
137
|
+
if (params === null) {
|
|
138
|
+
params = {}
|
|
139
|
+
}
|
|
140
|
+
const paramsClone = clone(params)
|
|
141
|
+
paramsClone[this.session.getKeyAuth()] = auth
|
|
142
|
+
let options = {
|
|
143
|
+
params: this.getHttpParamsGet(paramsClone)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return this.session.getBaseUrl().pipe(
|
|
147
|
+
mergeMap(v => {
|
|
148
|
+
if (v) {
|
|
149
|
+
return this.http.get<T>(this.prepareBaseAddress(v) + url, options).pipe(
|
|
150
|
+
take(1),
|
|
151
|
+
catchError(err => {
|
|
152
|
+
if (!textError.length && err.error.error_description) {
|
|
153
|
+
textError = err.error.error_description
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this.snackBar.error('Ошибка: ' + textError)
|
|
157
|
+
return throwError(() => err)
|
|
158
|
+
}))
|
|
159
|
+
}
|
|
160
|
+
return throwError(() => 'get base url error')
|
|
161
|
+
})
|
|
162
|
+
)
|
|
163
|
+
} else {
|
|
164
|
+
this.snackBar.error('Error: Auth not get')
|
|
165
|
+
return throwError(() => 'auth not get')
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
getNameMethod(arr: string[]) {
|
|
172
|
+
return arr.join('.')
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
}
|
|
176
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseServices } from '
|
|
1
|
+
import { BaseServices } from 'bx-rest/src/services/base'
|
|
2
2
|
import { HttpParams } from '@angular/common/http'
|
|
3
|
-
import { iHttpParamSettings } from '
|
|
4
|
-
import iHttpAnswerBX from '
|
|
3
|
+
import { iHttpParamSettings } from 'bx-rest/src/typification/rest/settings'
|
|
4
|
+
import iHttpAnswerBX from 'bx-rest/src/typification/rest/base/httpAnswerBX'
|
|
5
5
|
|
|
6
6
|
export class HttpData extends BaseServices {
|
|
7
7
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import BaseServices from '
|
|
1
|
+
import { BaseServices } from 'bx-rest/src/services/base'
|
|
2
2
|
import { HttpParams } from '@angular/common/http'
|
|
3
|
-
import { iHttpParamSettings } from '
|
|
4
|
-
import iHttpAnswerBX from '
|
|
3
|
+
import { iHttpParamSettings } from 'bx-rest/src/typification/rest/settings'
|
|
4
|
+
import iHttpAnswerBX from 'bx-rest/src/typification/rest/base/httpAnswerBX'
|
|
5
5
|
|
|
6
6
|
export class HttpData extends BaseServices {
|
|
7
7
|
|
|
8
8
|
defSettings: iHttpParamSettings = {
|
|
9
9
|
timeZone: {
|
|
10
|
-
calc: true
|
|
10
|
+
calc: true,
|
|
11
|
+
levelOut: false
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { iHttpParamSettings } from '
|
|
1
|
+
// import { iHttpParamSettings } from '../../../typification/rest/settings'
|
|
2
|
+
import { iHttpParamSettings } from 'bx-rest/src/typification/rest/settings'
|
|
2
3
|
import { HttpClient } from '@angular/common/http'
|
|
3
|
-
import SnackBarService from '
|
|
4
|
+
import SnackBarService from 'bx-rest/src/services/snack-bar/snack-bar.service'
|
|
4
5
|
import { Observable, of, } from 'rxjs'
|
|
5
|
-
import { HttpData } from '
|
|
6
|
+
import { HttpData } from 'bx-rest/src/services/http/HttpData'
|
|
6
7
|
import { Injectable } from '@angular/core'
|
|
7
8
|
|
|
8
9
|
@Injectable({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Observable, throwError } from 'rxjs'
|
|
2
2
|
import { catchError } from 'rxjs/operators'
|
|
3
3
|
import { HttpParams } from '@angular/common/http'
|
|
4
|
-
import { iHttpParamSettings } from '
|
|
5
|
-
import { BaseHttp } from '
|
|
4
|
+
import { iHttpParamSettings } from 'bx-rest/src/typification/rest/settings'
|
|
5
|
+
import { BaseHttp } from 'bx-rest/src/services/http/base/base'
|
|
6
6
|
|
|
7
7
|
export class BaseHttpServices extends BaseHttp {
|
|
8
8
|
|
|
@@ -2,17 +2,17 @@ import { Observable, throwError, take, mergeMap, forkJoin } from 'rxjs'
|
|
|
2
2
|
import { catchError, map } from 'rxjs/operators'
|
|
3
3
|
import { Injectable } from '@angular/core'
|
|
4
4
|
import { HttpClient } from '@angular/common/http'
|
|
5
|
-
import SnackBarService from '
|
|
6
|
-
import SessionKeyServices from '
|
|
5
|
+
import SnackBarService from 'bx-rest/src/services/snack-bar/snack-bar.service'
|
|
6
|
+
import SessionKeyServices from 'bx-rest/src/services/http/sessionKey'
|
|
7
7
|
import clone from 'just-clone'
|
|
8
|
-
import { iHttpParamSettings } from '
|
|
9
|
-
import BaseHttpServices from '@/services/http/http'
|
|
8
|
+
import { iHttpParamSettings } from 'bx-rest/src/typification/rest/settings'
|
|
10
9
|
import {
|
|
11
10
|
iBatchRequestAnswer, iBatchRequestParam,
|
|
12
11
|
iBatchRequestParamArr,
|
|
13
12
|
iBatchRequestParamHttp, keyBatch
|
|
14
|
-
} from '
|
|
13
|
+
} from 'bx-rest/src/typification/rest/batch/batchRequestParam'
|
|
15
14
|
import flatten from 'just-flatten-it'
|
|
15
|
+
import { BaseHttpServices } from './base/http'
|
|
16
16
|
|
|
17
17
|
@Injectable({
|
|
18
18
|
providedIn: 'root'
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { Injectable } from '@angular/core'
|
|
2
|
-
import Cookies from '
|
|
2
|
+
import Cookies from 'bx-rest/src/services/vanilla/сookies'
|
|
3
3
|
import { Store } from '@ngrx/store'
|
|
4
|
-
import saveApplicationAuth from '
|
|
5
|
-
import { environment as env } from '
|
|
4
|
+
import saveApplicationAuth from 'bx-rest/src/typification/auth/save'
|
|
5
|
+
// import { environment as env } from 'bx-rest/src/environments/environment'
|
|
6
6
|
import { filter, Observable, of, Subscription, take } from 'rxjs'
|
|
7
7
|
import { ActivatedRoute, ParamMap } from '@angular/router'
|
|
8
|
-
import { saveAccessToken, saveApplicationAuthPath } from '
|
|
8
|
+
import { saveAccessToken, saveApplicationAuthPath } from 'bx-rest/src/store/auth'
|
|
9
9
|
import { map } from 'rxjs/operators'
|
|
10
|
-
import { BaseServices } from '
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
10
|
+
import { BaseServices } from 'bx-rest/src/services/base'
|
|
11
|
+
import { LocalStorageServices as LocalStorage } from 'bx-rest/src/services/vanilla/localStorage'
|
|
12
|
+
import { RestServices } from 'bx-rest/src/typification/rest/api-lib'
|
|
13
13
|
|
|
14
14
|
type IKeyAuth = 'sessid' | 'auth' | string
|
|
15
15
|
|
|
16
16
|
@Injectable({
|
|
17
17
|
providedIn: 'root'
|
|
18
18
|
})
|
|
19
|
-
|
|
20
19
|
export default class SessionKeyServices extends BaseServices {
|
|
21
20
|
|
|
22
21
|
authHave = false
|
|
@@ -29,12 +28,12 @@ export default class SessionKeyServices extends BaseServices {
|
|
|
29
28
|
constructor(
|
|
30
29
|
public store: Store<{ auth: saveApplicationAuth }>,
|
|
31
30
|
private route: ActivatedRoute,
|
|
32
|
-
public BxApiLib:
|
|
31
|
+
public BxApiLib: RestServices,
|
|
33
32
|
) {
|
|
34
33
|
super()
|
|
35
34
|
this.authData$ = this.store.select('auth')
|
|
36
35
|
this.authData$.subscribe(authData => {
|
|
37
|
-
if ((authData && !authData.access_token.length
|
|
36
|
+
if ((authData && !authData.access_token.length) || !authData) {
|
|
38
37
|
// получаем токен по собственным каналом (в битриксе приложение trace:apps.trace)
|
|
39
38
|
window.addEventListener('message', (event: MessageEvent) => {
|
|
40
39
|
if (event.origin !== window.origin) { // проверяем что это не наше сообщение (с текущего приложения)
|
|
@@ -129,16 +128,12 @@ export default class SessionKeyServices extends BaseServices {
|
|
|
129
128
|
}
|
|
130
129
|
|
|
131
130
|
})
|
|
132
|
-
} else if (
|
|
131
|
+
} else if (this.getAuth().length) {
|
|
133
132
|
this.authHave = true
|
|
134
133
|
}
|
|
135
134
|
|
|
136
135
|
this.authData = authData
|
|
137
136
|
})
|
|
138
|
-
|
|
139
|
-
if (!env.production) {
|
|
140
|
-
this.authHave = true
|
|
141
|
-
}
|
|
142
137
|
}
|
|
143
138
|
|
|
144
139
|
subscribeAll() {
|
|
@@ -188,27 +183,23 @@ export default class SessionKeyServices extends BaseServices {
|
|
|
188
183
|
}
|
|
189
184
|
|
|
190
185
|
getAuthParams(): Observable<string | undefined> {
|
|
191
|
-
if (env.production && !env.component) {
|
|
186
|
+
// if (env.production && !env.component) {
|
|
192
187
|
return this.authData$.pipe(
|
|
193
188
|
take(1),
|
|
194
189
|
map(v => (v) ? v.access_token : undefined)
|
|
195
190
|
)
|
|
196
|
-
} else {
|
|
197
|
-
|
|
198
|
-
}
|
|
191
|
+
// } else {
|
|
192
|
+
// return of(this.getAuth())
|
|
193
|
+
// }
|
|
199
194
|
}
|
|
200
195
|
|
|
201
196
|
getBaseUrl(): Observable<string | undefined> {
|
|
202
|
-
if (env.public) {
|
|
203
197
|
return this.authData$.pipe(
|
|
204
|
-
map(v => (v && v.domain) ? this.prepareBaseAddress(v.domain,
|
|
198
|
+
map(v => (v && v.domain) ? this.prepareBaseAddress(v.domain, 'b24.trace-studio.com') : undefined)
|
|
205
199
|
)
|
|
206
|
-
} else {
|
|
207
|
-
return of(env.urls.api.bitrix)
|
|
208
|
-
}
|
|
209
200
|
}
|
|
210
201
|
|
|
211
|
-
getHomeUrl(): string {
|
|
212
|
-
|
|
213
|
-
}
|
|
202
|
+
// getHomeUrl(): string {
|
|
203
|
+
// return env.urls.home
|
|
204
|
+
// }
|
|
214
205
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core'
|
|
2
|
+
import BaseMapServices from 'bx-rest/src/services/map/base'
|
|
3
|
+
import { iBXRestUser, iBXRestUserHttp } from 'bx-rest/src/typification/rest/user/user'
|
|
4
|
+
import clone from 'just-clone'
|
|
5
|
+
|
|
6
|
+
@Injectable({
|
|
7
|
+
providedIn: 'root'
|
|
8
|
+
})
|
|
9
|
+
export class BitrixApiUserMapServices extends BaseMapServices {
|
|
10
|
+
|
|
11
|
+
HttpToBX(user: iBXRestUserHttp): iBXRestUser {
|
|
12
|
+
let res: iBXRestUser = Object.assign(clone(user), {
|
|
13
|
+
ID: this.toNumber(user.ID),
|
|
14
|
+
IS_ONLINE: this.toBool(user.IS_ONLINE),
|
|
15
|
+
DATE_REGISTER: this.toDate(user.DATE_REGISTER),
|
|
16
|
+
PERSONAL_BIRTHDAY: this.toDate(user.PERSONAL_BIRTHDAY),
|
|
17
|
+
})
|
|
18
|
+
if (user.LAST_LOGIN) {
|
|
19
|
+
res.LAST_LOGIN = this.toDate(user.LAST_LOGIN)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return res
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
BXtoHttp(user: iBXRestUser): iBXRestUserHttp {
|
|
26
|
+
return Object.assign(clone(user), {
|
|
27
|
+
ID: this.toStr(user.ID),
|
|
28
|
+
IS_ONLINE: this.toBXYorN(user.IS_ONLINE),
|
|
29
|
+
DATE_REGISTER: this.getBXStrTime(user.DATE_REGISTER),
|
|
30
|
+
PERSONAL_BIRTHDAY: this.toStr(user.PERSONAL_BIRTHDAY),
|
|
31
|
+
LAST_LOGIN: this.toStr(user.LAST_LOGIN)
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getFIO(user: iBXRestUser): string {
|
|
36
|
+
let res = ''
|
|
37
|
+
if (!user.LAST_NAME) {
|
|
38
|
+
const SECOND_NAME = (user.SECOND_NAME) ? user.SECOND_NAME : ''
|
|
39
|
+
const NAME = (user.NAME) ? user.NAME : ''
|
|
40
|
+
res = NAME + ' ' + SECOND_NAME
|
|
41
|
+
} else if (!user.NAME) {
|
|
42
|
+
res = user.LAST_NAME
|
|
43
|
+
} else if (!user.SECOND_NAME) {
|
|
44
|
+
res = user.LAST_NAME + ' ' + user.NAME
|
|
45
|
+
} else {
|
|
46
|
+
res = user.LAST_NAME + ' ' + user.NAME + ' ' + user.SECOND_NAME
|
|
47
|
+
}
|
|
48
|
+
return res.trim()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getFI(user: iBXRestUser): string {
|
|
52
|
+
let res = ''
|
|
53
|
+
if (!user.LAST_NAME) {
|
|
54
|
+
const NAME = (user.NAME) ? user.NAME : ''
|
|
55
|
+
res = NAME
|
|
56
|
+
} else if (!user.NAME) {
|
|
57
|
+
res = user.LAST_NAME
|
|
58
|
+
} else {
|
|
59
|
+
res = user.LAST_NAME + ' ' + user.NAME
|
|
60
|
+
}
|
|
61
|
+
return res.trim()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getFIOShort(user: iBXRestUser): string {
|
|
65
|
+
let res = ''
|
|
66
|
+
if (!user.LAST_NAME) {
|
|
67
|
+
const SECOND_NAME = (user.SECOND_NAME) ? user.SECOND_NAME : ''
|
|
68
|
+
const NAME = (user.NAME) ? user.NAME : ''
|
|
69
|
+
res = NAME + ' ' + SECOND_NAME
|
|
70
|
+
} else if (!user.NAME) {
|
|
71
|
+
res = user.LAST_NAME
|
|
72
|
+
} else if (!user.SECOND_NAME) {
|
|
73
|
+
res = user.LAST_NAME + ' ' + user.NAME.charAt(0).toUpperCase() + '.'
|
|
74
|
+
} else {
|
|
75
|
+
res =
|
|
76
|
+
user.LAST_NAME + ' ' +
|
|
77
|
+
user.NAME.charAt(0).toUpperCase() + '.' +
|
|
78
|
+
user.SECOND_NAME.charAt(0).toUpperCase() + '.'
|
|
79
|
+
}
|
|
80
|
+
return res.trim()
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* TODO: логирование
|
|
4
4
|
*/
|
|
5
5
|
import { Injectable } from '@angular/core'
|
|
6
|
-
import { ToastMessageComponent } from '
|
|
6
|
+
import { ToastMessageComponent } from 'bx-rest/src/services/snack-bar/toast-message/toast-message.component'
|
|
7
7
|
import { MatSnackBar } from '@angular/material/snack-bar'
|
|
8
8
|
|
|
9
9
|
@Injectable({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Injectable } from '@angular/core'
|
|
2
|
-
import SessionKeyServices from '
|
|
2
|
+
import SessionKeyServices from 'bx-rest/src/services/http/sessionKey'
|
|
3
3
|
import { map, mergeMap, of } from 'rxjs'
|
|
4
|
-
import SnackBarService from '
|
|
4
|
+
import SnackBarService from 'bx-rest/src/services/snack-bar/snack-bar.service'
|
|
5
5
|
|
|
6
6
|
@Injectable({
|
|
7
7
|
providedIn: 'root'
|
package/src/store/auth.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Action, createReducer, on, props } from '@ngrx/store'
|
|
2
2
|
import { createAction } from '@ngrx/store'
|
|
3
|
-
import saveApplicationAuth from '
|
|
3
|
+
import saveApplicationAuth from 'bx-rest/src/typification/auth/save'
|
|
4
4
|
import clone from 'just-clone'
|
|
5
5
|
export interface saveApplicationAuthPath {
|
|
6
6
|
access_token?: string, // основной авторизационный токен, требуемый для доступа к REST API
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Action, createReducer, on, props } from '@ngrx/store'
|
|
2
|
+
import { createAction } from '@ngrx/store'
|
|
3
|
+
import clone from 'just-clone'
|
|
4
|
+
import { iBXRestUser } from 'bx-rest/src/typification/rest/user/user'
|
|
5
|
+
|
|
6
|
+
export interface storeUsers {
|
|
7
|
+
load: {
|
|
8
|
+
all: boolean,
|
|
9
|
+
department: number[]
|
|
10
|
+
}
|
|
11
|
+
self: iBXRestUser | undefined
|
|
12
|
+
data: iBXRestUser []
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const save = createAction('[Users Component] Save', props<iBXRestUser >())
|
|
16
|
+
export const saveArr = createAction('[Users Component] Save Arr', props<{ arr: iBXRestUser [] }>())
|
|
17
|
+
export const update = createAction('[Users Component] Update', props<iBXRestUser >())
|
|
18
|
+
export const loadAll = createAction('[Users Component] loadAll', props<{ load: true }>())
|
|
19
|
+
export const saveSelf = createAction('[Users Component] saveSelf', props<{ self: iBXRestUser }>())
|
|
20
|
+
export const saveIDLoadedDepartment = createAction('[Users Component] saveIDLoadedDepartment', props<{id: number[]}>())
|
|
21
|
+
|
|
22
|
+
export const initialState: storeUsers = {
|
|
23
|
+
load: {
|
|
24
|
+
all: false,
|
|
25
|
+
department: []
|
|
26
|
+
},
|
|
27
|
+
self: undefined,
|
|
28
|
+
data: []
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const _usersReducer = createReducer(
|
|
32
|
+
initialState,
|
|
33
|
+
on(saveIDLoadedDepartment, (s, data) => {
|
|
34
|
+
let copy = clone(s)
|
|
35
|
+
copy.load.department = [...copy.load.department, ...data.id]
|
|
36
|
+
return copy
|
|
37
|
+
}),
|
|
38
|
+
on(save, (s, data) => {
|
|
39
|
+
const find = s.data.find(v => v.ID === data.ID)
|
|
40
|
+
if (!find) {
|
|
41
|
+
const copy = clone(s)
|
|
42
|
+
copy.data.push(data)
|
|
43
|
+
return copy
|
|
44
|
+
}
|
|
45
|
+
return s
|
|
46
|
+
}),
|
|
47
|
+
on(saveArr, (s, data) => {
|
|
48
|
+
const copy = clone(s)
|
|
49
|
+
if(copy.data && copy.data.length) {
|
|
50
|
+
for (const user of data.arr) {
|
|
51
|
+
const find = copy.data.find(v => v.ID === user.ID)
|
|
52
|
+
if (!find) {
|
|
53
|
+
copy.data.push(user)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
copy.data = [...data.arr]
|
|
58
|
+
}
|
|
59
|
+
return copy
|
|
60
|
+
}),
|
|
61
|
+
on(update, (s, data) => {
|
|
62
|
+
const copy = clone(s)
|
|
63
|
+
let find = copy.data.findIndex(v => v.ID === data.ID)
|
|
64
|
+
if (find !== -1) {
|
|
65
|
+
const copy = clone(s)
|
|
66
|
+
copy.data.splice(find, 1, data);
|
|
67
|
+
// copy.data.push(data)
|
|
68
|
+
return copy
|
|
69
|
+
}
|
|
70
|
+
return s
|
|
71
|
+
}),
|
|
72
|
+
on(loadAll, (s, data) => {
|
|
73
|
+
if (data.load !== s.load.all) {
|
|
74
|
+
const copy = clone(s)
|
|
75
|
+
copy.load.all = data.load
|
|
76
|
+
return copy
|
|
77
|
+
}
|
|
78
|
+
return s
|
|
79
|
+
}),
|
|
80
|
+
on(saveSelf, (s, data) => {
|
|
81
|
+
return { ...s, self: data.self}
|
|
82
|
+
})
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
export function usersReducer(state = initialState, action: Action) {
|
|
87
|
+
return _usersReducer(state, action)
|
|
88
|
+
}
|
package/src/tsconfig.base.json
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"paths": {
|
|
7
|
-
"bx-rest": ["./"],
|
|
8
|
-
"bx-rest/*": ["./*"]
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
"include": ["./**/*.ts"]
|
|
2
|
+
"extends": "../tsconfig.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"./**/*.ts"
|
|
5
|
+
]
|
|
12
6
|
}
|
package/src/tsconfig.types.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Injectable } from '@angular/core'
|
|
2
|
-
import { iRestLib } from '
|
|
2
|
+
import { iRestLib } from 'bx-rest/src/typification/rest/lib'
|
|
3
3
|
|
|
4
4
|
@Injectable({
|
|
5
5
|
providedIn: 'root'
|
|
6
6
|
})
|
|
7
|
-
export class
|
|
7
|
+
export class RestServices {
|
|
8
8
|
BX24: iRestLib | false = false
|
|
9
9
|
|
|
10
10
|
constructor() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iBXRestUserKey } from '
|
|
2
|
-
import { iBXRestYesNo } from '
|
|
1
|
+
import { iBXRestUserKey } from 'bx-rest/src/typification/rest/user/user'
|
|
2
|
+
import { iBXRestYesNo } from 'bx-rest/src/typification/rest/base/YesNo'
|
|
3
3
|
|
|
4
4
|
export interface iCustomUserFieldInfo {
|
|
5
5
|
ID: string,
|