This repository was archived by the owner on May 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUser.js
More file actions
233 lines (208 loc) · 6.79 KB
/
Copy pathUser.js
File metadata and controls
233 lines (208 loc) · 6.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* BSD 3-Clause License
*
* Copyright (c) 2020, Mapcreator
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import OwnedResourceProxy from '../proxy/OwnedResourceProxy';
import ResourceProxy from '../proxy/ResourceProxy';
import CrudBase from './base/CrudBase';
import Color from './Color';
import Dimension from './Dimension';
import DimensionSet from './DimensionSet';
import Feature from './Feature';
import Font from './Font';
import FontFamily from './FontFamily';
import Job from './Job';
import JobShare from './JobShare';
import JobType from './JobType';
import Language from './Language';
import Layer from './Layer';
import Mapstyle from './Mapstyle';
import MapstyleSet from './MapstyleSet';
import Notification from './Notification';
import Organisation from './Organisation';
import Permission from './Permission';
import Role from './Role';
import Svg from './Svg';
import SvgSet from './SvgSet';
import { makeCancelable } from '../utils/helpers';
export default class User extends CrudBase {
static get resourceName () {
return 'users';
}
/**
* Get all known ips
* @returns {CancelablePromise<string[]>} - List of ip addresses
* @throws {ApiError} - If the api returns errors
*/
ips () {
const url = `${this.url}/ips`;
return makeCancelable(async signal => {
const { data } = await this.api.ky.get(url, { signal }).json();
return data.map(row => row['ip_address']);
});
}
/**
* Get the user's organisation
* @returns {CancelablePromise<Organisation>} - User's organisation
* @throws {ApiError} - If the api returns errors
*/
organisation () {
return new ResourceProxy(this.api, Organisation).get(this.organisationId);
}
/**
* Get the user's language
* @returns {CancelablePromise<Language>} - User's language
* @throws {ApiError} - If the api returns errors
*/
language () {
return new ResourceProxy(this.api, Language).get(this.languageCode);
}
// region Resource listing
/**
* Get the list notifications linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get notifications () {
return this._proxyResourceList(Notification);
}
/**
* Get the list mapstyle sets linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get mapstyleSets () {
return this._proxyResourceList(MapstyleSet);
}
/**
* Get the list mapstyles linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get mapstyles () {
return this._proxyResourceList(Mapstyle);
}
/**
* Get the list dimension sets linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get dimensionSets () {
return this._proxyResourceList(DimensionSet);
}
/**
* Get the list dimensions linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get dimensions () {
return this._proxyResourceList(Dimension);
}
/**
* Get the list font families linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get fontFamilies () {
return this._proxyResourceList(FontFamily);
}
/**
* Get the list fonts linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get fonts () {
return this._proxyResourceList(Font);
}
/**
* Get the list svg sets linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get svgSets () {
return this._proxyResourceList(SvgSet);
}
/**
* Get the list svgs linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get svgs () {
return this._proxyResourceList(Svg);
}
/**
* Get the list colors linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get colors () {
return this._proxyResourceList(Color);
}
/**
* Get the list jobs linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get jobs () {
return this._proxyResourceList(Job);
}
/**
* Get the list features linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get features () {
return this._proxyResourceList(Feature);
}
/**
* Get the list layers linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get layers () {
return this._proxyResourceList(Layer);
}
/**
* Get the list job types linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get jobTypes () {
return this._proxyResourceList(JobType);
}
/**
* Get the list job shares linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get jobShares () {
return this._proxyResourceList(JobShare);
}
/**
* Get the list permissions linked to the user
* @returns {SimpleResourceProxy} - A proxy for accessing the resource
*/
get permissions () {
return this._proxyResourceList(Permission);
}
/**
* Get the list roles linked to the user
* @returns {OwnedResourceProxy} - A proxy for accessing the resource
*/
get roles () {
return new OwnedResourceProxy(this.api, this, Role);
}
// endregion
}