@wg-npm/survey-service-api 0.1.272 → 0.2.0

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.
@@ -1,311 +1,203 @@
1
- import {
2
- PlanModel,
3
- PlanStatisticsModel,
4
- QuestionModel,
5
- ResponseModel,
6
- ResponseStatisticsModel,
7
- SurveyModel,
8
- TemplateModel
9
- } from "@wg-npm/survey-core"
10
- import { AsyncSurveyService, BlockingSurveyService, SurveyServiceOptions } from './survey-service'
11
- import { AxiosInstance } from "axios";
12
- import { createHttpFunction } from "./axios";
13
- import applyConverters from "axios-case-converter";
14
-
15
-
16
- export class AsyncSurveyServiceImpl implements AsyncSurveyService {
17
- http: AxiosInstance;
18
- exhttp: AxiosInstance;
19
-
20
- constructor(options: SurveyServiceOptions) {
21
- this.http = applyConverters(
22
- createHttpFunction(options.baseUrl, options.version)
23
- );
24
- if (options.httpDecorator) {
25
- this.http = options.httpDecorator(this.http);
26
- }
27
-
28
- this.exhttp = createHttpFunction("", "")
1
+ import { PlanModel, PlanStatisticsModel, BaseQuestionModel, ResponseModel, ResponseStatisticsModel, SurveyModel } from '@wg-npm/survey-core';
2
+ import { SurveyService, SurveyServiceOptions } from './survey-service';
3
+ import { AxiosInstance } from 'axios';
4
+ import { createHttpFunction } from './axios';
5
+ import applyConverters from 'axios-case-converter';
6
+
7
+ export class SurveyServiceImpl implements SurveyService {
8
+ http: AxiosInstance;
9
+ exhttp: AxiosInstance;
10
+
11
+ constructor(options: SurveyServiceOptions) {
12
+ this.http = applyConverters(createHttpFunction(options.baseUrl, options.version));
13
+ if (options.httpDecorator) {
14
+ this.http = options.httpDecorator(this.http);
29
15
  }
30
16
 
31
- loadTemplate(id: string): Promise<TemplateModel> {
32
- return this.http
33
- .get(`/templates/${id}`)
34
- .then(response => response.data);
35
- }
36
-
37
- loadTemplates(params: any): Promise<TemplateModel> {
38
- return this.http
39
- .get(`/templates`, { params: params })
40
- .then(response => response.data);
41
- }
42
-
43
- createTemplate(survey: TemplateModel): Promise<TemplateModel> {
44
- return this.http
45
- .post("/templates", survey)
46
- .then(response => response.data);
47
- }
48
-
49
- updateTemplate(survey: TemplateModel): Promise<TemplateModel> {
50
- return this.http
51
- .put("/templates", survey)
52
- .then(response => response.data);
53
- }
54
-
55
- deleteTemplate(id: string): Promise<void> {
56
- return this.http.delete(`/templates/${id}`);
57
- }
58
-
59
- loadSurvey(id: string): Promise<SurveyModel> {
60
- return this.http.get(`/surveys/${id}`).then(response => response.data);
61
- }
62
-
63
- loadSurveys(params: any): Promise<SurveyModel> {
64
- return this.http
65
- .get(`/surveys`, { params: params })
66
- .then(response => response.data);
67
- }
68
-
69
- createSurvey(survey: SurveyModel): Promise<SurveyModel> {
70
- return this.http
71
- .post("/surveys", survey)
72
- .then(response => response.data);
73
- }
74
-
75
- updateSurvey(survey: SurveyModel): Promise<SurveyModel> {
76
- return this.http
77
- .put("/surveys", survey)
78
- .then(response => response.data);
79
- }
80
-
81
- deleteSurvey(id: string): Promise<void> {
82
- return this.http.delete(`/surveys/${id}`);
83
- }
84
-
85
- createQuestion(surveyId: string,
86
- question: QuestionModel): Promise<QuestionModel> {
87
- return this.http
88
- .post(`/templates/${surveyId}/question`, question)
89
- .then(response => response.data);
90
- }
91
-
92
- createQuestions(surveyId: string, questions: Array<QuestionModel>): Promise<QuestionModel> {
93
- return this.http
94
- .post(`/templates/${surveyId}/questions`, questions)
95
- .then(response => response.data);
96
- }
97
-
98
- updateQuestion(surveyId: string,
99
- question: QuestionModel): Promise<QuestionModel> {
100
- return this.http
101
- .put(`/templates/${surveyId}/questions/${question.id}`, question)
102
- .then(response => response.data);
103
- }
104
-
105
- updateQuestionsOptions(surveyId: string, questions: Array<QuestionModel>): Promise<QuestionModel> {
106
- return this.http
107
- .put(`/surveys/${surveyId}/questions/options`, questions)
108
- .then(response => response.data);
109
- }
110
-
111
- moveQuestion(surveyId: string,
112
- questionId: string,
113
- index: number): Promise<void> {
114
- return Promise.resolve(
115
- this.http.put(
116
- `/templates/${surveyId}/questions/${questionId}/move`,
117
- { index: index }
118
- )
119
- );
120
- }
121
-
122
- deleteQuestion(surveyId: string, questionId: string): Promise<void> {
123
- return Promise.resolve(
124
- this.http.delete(`/templates/${surveyId}/questions/${questionId}`)
125
- );
126
- }
127
-
128
- loadResponse(id: string): Promise<ResponseModel> {
129
- return this.http
130
- .get(`/responses/${id}`)
131
- .then(response => response.data);
132
- }
133
-
134
- dispatchResponse(surveyId: string,
135
- response: ResponseModel): Promise<ResponseModel> {
136
- return this.http
137
- .post(`/surveys/${surveyId}/responses`, response)
138
- .then(response => response.data);
139
- }
140
-
141
- updateResponse(response: ResponseModel): Promise<ResponseModel> {
142
- return this.http
143
- .put(`/responses/${response.id}`, response)
144
- .then(response => response.data);
145
- }
146
-
147
- loadMyPlans(params: any): Promise<ResponseModel> {
148
- return this.http
149
- .get(`/plans/me`, { params: params })
150
- .then(response => response.data);
151
- }
152
-
153
- loadPlans(params: any): Promise<PlanModel> {
154
- return this.http
155
- .get(`/plans`, { params: params })
156
- .then(response => response.data);
157
- }
158
-
159
- loadPlanById(planId: string, params: any): Promise<PlanModel> {
160
- return this.http
161
- .get(`/plan/${planId}`, { params: params })
162
- .then(response => response.data);
163
- }
164
-
165
- loadPlanWithFiltersById(planId: string, PlanStatisticsModel: PlanStatisticsModel): Promise<PlanStatisticsModel> {
166
- return this.http
167
- .post(`/plan/${planId}`, { ...PlanStatisticsModel })
168
- .then(response => response.data);
169
- }
170
-
171
- loadPlanWithFiltersByIdAndTargetId(planId: string,
172
- targetId: string,
173
- PlanStatisticsModel: PlanStatisticsModel): Promise<PlanStatisticsModel> {
174
- return this.http
175
- .post(`/plan/${planId}/targets/${targetId}`, { ...PlanStatisticsModel })
176
- .then(response => response.data);
177
- }
178
-
179
- createPlan(plan: PlanModel): Promise<PlanModel> {
180
- return this.http.post("/plans", plan).then(response => response.data);
181
- }
17
+ this.exhttp = createHttpFunction('', '');
18
+ }
19
+
20
+ loadSurvey(id: string): Promise<SurveyModel> {
21
+ return this.http.get(`/surveys/${id}`).then(response => response.data);
22
+ }
182
23
 
183
- updatePlan(plan: PlanModel): Promise<PlanModel> {
184
- return this.http.put("/plans", plan).then(response => response.data);
185
- }
186
-
187
- deletePlan(id: string): Promise<void> {
188
- return this.http.delete(`/plans/${id}`);
189
- }
190
-
191
- dispatchResponses(surveyId: string,
192
- respondentId: string,
193
- targets: Array<string>): Promise<ResponseModel> {
194
- return this.http.post(
195
- `/surveys/${surveyId}/respondents/${respondentId}/responses`,
196
- { targets: targets }
197
- );
198
- }
199
-
200
- loadResponses(params: any): Promise<ResponseModel> {
201
- return this.http
202
- .get(`/responses`, { params: params })
203
- .then(response => response.data);
204
- }
205
-
206
- loadResponsesPost(data: any): Promise<ResponseModel> {
207
- return this.http
208
- .post(`/responses`, { ...data })
209
- .then(response => response.data);
210
- }
211
-
212
- loadStatisticsByAll(surveyId: string, statistics: ResponseStatisticsModel): Promise<ResponseStatisticsModel> {
213
- return this.http.get(`/statistics/${surveyId}`, { params: { ...statistics, statisticsBy: 'ALL' } })
214
- .then(response => response.data)
215
- }
216
-
217
- loadStatisticsBySurvey(surveyId: string, statistics: ResponseStatisticsModel): Promise<ResponseStatisticsModel> {
218
- return this.http.get(`/statistics/${surveyId}`, { params: { ...statistics, statisticsBy: 'SURVEY' } })
219
- .then(response => response.data)
220
- }
221
-
222
- loadStatisticsByTargets(surveyId: string, statistics: ResponseStatisticsModel): Promise<ResponseStatisticsModel> {
223
- return this.http.get(`/statistics/${surveyId}`, { params: { ...statistics, statisticsBy: 'TARGET' } })
224
- .then(response => response.data)
225
- }
226
-
227
- loadStatisticsWithFiltersByAll(surveyId: string,
228
- statistics: ResponseStatisticsModel): Promise<ResponseStatisticsModel> {
229
- return this.http.post(`/statistics/${surveyId}`, { ...statistics, statisticsBy: 'ALL' })
230
- .then(response => response.data)
231
- }
232
-
233
- loadStatisticsWithFiltersBySurvey(surveyId: string,
234
- statistics: ResponseStatisticsModel): Promise<ResponseStatisticsModel> {
235
- return this.http.post(`/statistics/${surveyId}`, { ...statistics, statisticsBy: 'SURVEY' })
236
- .then(response => response.data)
237
- }
238
-
239
- loadStatisticsWithFiltersByTargets(surveyId: string,
240
- statistics: ResponseStatisticsModel): Promise<ResponseStatisticsModel> {
241
- return this.http.post(`/statistics/${surveyId}`, { ...statistics, statisticsBy: 'TARGET' })
242
- .then(response => response.data)
243
- }
244
-
245
- loadStatisticsBySurveyAndTarget(data: any) {
246
- return this.http.post(`/statistics/targets`, data)
247
- .then(response => response.data)
248
- }
249
-
250
- loadRespondents(params: any): Promise<PlanModel> {
251
- return this.http
252
- .get(`/respondents`, { params: params })
253
- .then(response => response.data);
254
- }
255
-
256
- loadRespondentbyPlanAndTarget(params: any): Promise<PlanModel> {
257
- return this.http
258
- .get(`/respondents/target`, { params: params })
259
- .then(response => response.data);
260
- }
261
-
262
- loadRespondentbyPlanAndTargetAndRespondentIds(planId: string, targetId: string, respondentIds: Array<number>): Promise<ResponseModel> {
263
- return this.http.post(`/respondents/target`, { planId, targetId, respondentIds })
264
- .then(response => response.data)
265
- }
266
-
267
- get(url: string, params: any): Promise<Object> {
268
- return this.exhttp.get(url, { params: params })
269
- .then(response => response.data)
270
- }
271
-
272
- updatePlanStatistics(params: any): Promise<ResponseStatisticsModel> {
273
- return this.http.put('/statistics', params)
274
- .then(response => response.data)
275
- }
276
-
277
- exportPlanStatisticsRawData(params: any): Promise<ResponseStatisticsModel> {
278
- return this.http.put('/statistics/exportRawData', params)
279
- .then(response => response.data)
280
- }
281
- }
282
-
283
- export class BlockingSurveyServiceImpl implements BlockingSurveyService {
284
- asyncSurveyService: AsyncSurveyService;
285
-
286
- constructor(asyncSurveyService: AsyncSurveyService) {
287
- this.asyncSurveyService = asyncSurveyService;
288
- }
289
-
290
- loadSurvey(id: string): SurveyModel {
291
- let survey: SurveyModel = new SurveyModel();
292
- survey.id = id;
293
- return survey;
294
- }
295
-
296
- createQuestion(surveyId: string, question: QuestionModel): QuestionModel {
297
- let q: QuestionModel = new QuestionModel();
298
- return q;
299
- }
300
-
301
- updateQuestion(surveyId: string, question: QuestionModel): QuestionModel {
302
- let q: QuestionModel = new QuestionModel();
303
- return q;
304
- }
305
-
306
- moveQuestion(surveyId: string, questionId: string, index: number): void {
307
- }
308
-
309
- deleteQuestion(surveyId: string, questionId: string): void {
310
- }
24
+ loadSurveys(params: any): Promise<SurveyModel[]> {
25
+ return this.http.get(`/surveys`, { params: params }).then(response => response.data);
26
+ }
27
+
28
+ createSurvey(survey: SurveyModel): Promise<SurveyModel> {
29
+ return this.http.post('/surveys', survey).then(response => response.data);
30
+ }
31
+
32
+ updateSurvey(survey: SurveyModel): Promise<SurveyModel> {
33
+ return this.http.put('/surveys', survey).then(response => response.data);
34
+ }
35
+
36
+ deleteSurvey(id: string): Promise<void> {
37
+ return this.http.delete(`/surveys/${id}`);
38
+ }
39
+
40
+ createQuestion(surveyId: string, question: BaseQuestionModel): Promise<BaseQuestionModel> {
41
+ return this.http.post(`/surveys/${surveyId}/question`, question).then(response => response.data);
42
+ }
43
+
44
+ createQuestions(surveyId: string, questions: Array<BaseQuestionModel>): Promise<BaseQuestionModel> {
45
+ return this.http.post(`/surveys/${surveyId}/questions`, questions).then(response => response.data);
46
+ }
47
+
48
+ updateQuestion(surveyId: string, question: BaseQuestionModel): Promise<BaseQuestionModel> {
49
+ return this.http.put(`/surveys/${surveyId}/questions/${question.id}`, question).then(response => response.data);
50
+ }
51
+
52
+ updateQuestionsOptions(surveyId: string, questions: Array<BaseQuestionModel>): Promise<BaseQuestionModel> {
53
+ return this.http.put(`/surveys/${surveyId}/questions/options`, questions).then(response => response.data);
54
+ }
55
+
56
+ moveQuestion(surveyId: string, questionId: string, index: number): Promise<void> {
57
+ return Promise.resolve(this.http.put(`/surveys/${surveyId}/questions/${questionId}/move`, { index: index }));
58
+ }
59
+
60
+ deleteQuestion(surveyId: string, questionId: string): Promise<void> {
61
+ return Promise.resolve(this.http.delete(`/surveys/${surveyId}/questions/${questionId}`));
62
+ }
63
+
64
+ loadResponse(id: string): Promise<ResponseModel> {
65
+ return this.http.get(`/responses/${id}`).then(response => response.data);
66
+ }
67
+
68
+ dispatchResponse(surveyId: string, response: ResponseModel): Promise<ResponseModel> {
69
+ return this.http.post(`/surveys/${surveyId}/responses`, response).then(response => response.data);
70
+ }
71
+
72
+ updateResponse(response: ResponseModel): Promise<ResponseModel> {
73
+ return this.http.put(`/responses/${response.id}`, response).then(response => response.data);
74
+ }
75
+
76
+ loadMyPlans(params: any): Promise<ResponseModel> {
77
+ return this.http.get(`/plans/me`, { params: params }).then(response => response.data);
78
+ }
79
+
80
+ loadPlans(params: any): Promise<PlanModel> {
81
+ return this.http.get(`/plans`, { params: params }).then(response => response.data);
82
+ }
83
+
84
+ loadPlanById(planId: string, params: any): Promise<PlanModel> {
85
+ return this.http.get(`/plan/${planId}`, { params: params }).then(response => response.data);
86
+ }
87
+
88
+ loadPlanWithFiltersById(planId: string, PlanStatisticsModel: PlanStatisticsModel): Promise<PlanStatisticsModel> {
89
+ return this.http.post(`/plan/${planId}`, { ...PlanStatisticsModel }).then(response => response.data);
90
+ }
91
+
92
+ loadPlanWithFiltersByIdAndTargetId(
93
+ planId: string,
94
+ targetId: string,
95
+ PlanStatisticsModel: PlanStatisticsModel
96
+ ): Promise<PlanStatisticsModel> {
97
+ return this.http.post(`/plan/${planId}/targets/${targetId}`, { ...PlanStatisticsModel }).then(response => response.data);
98
+ }
99
+
100
+ createPlan(plan: PlanModel): Promise<PlanModel> {
101
+ return this.http.post('/plans', plan).then(response => response.data);
102
+ }
103
+
104
+ updatePlan(plan: PlanModel): Promise<PlanModel> {
105
+ return this.http.put('/plans', plan).then(response => response.data);
106
+ }
107
+
108
+ deletePlan(id: string): Promise<void> {
109
+ return this.http.delete(`/plans/${id}`);
110
+ }
111
+
112
+ dispatchResponses(surveyId: string, respondentId: string, targets: Array<string>): Promise<ResponseModel> {
113
+ return this.http.post(`/surveys/${surveyId}/respondents/${respondentId}/responses`, { targets: targets });
114
+ }
115
+
116
+ loadResponses(params: any): Promise<ResponseModel> {
117
+ return this.http.get(`/responses`, { params: params }).then(response => response.data);
118
+ }
119
+
120
+ loadResponsesPost(data: any): Promise<ResponseModel> {
121
+ return this.http.post(`/responses`, { ...data }).then(response => response.data);
122
+ }
123
+
124
+ loadStatisticsByAll(surveyId: string, statistics: ResponseStatisticsModel): Promise<ResponseStatisticsModel> {
125
+ return this.http
126
+ .get(`/statistics/${surveyId}`, {
127
+ params: {
128
+ ...statistics,
129
+ statisticsBy: 'ALL',
130
+ },
131
+ })
132
+ .then(response => response.data);
133
+ }
134
+
135
+ loadStatisticsBySurvey(surveyId: string, statistics: ResponseStatisticsModel): Promise<ResponseStatisticsModel> {
136
+ return this.http
137
+ .get(`/statistics/${surveyId}`, {
138
+ params: {
139
+ ...statistics,
140
+ statisticsBy: 'SURVEY',
141
+ },
142
+ })
143
+ .then(response => response.data);
144
+ }
145
+
146
+ loadStatisticsByTargets(surveyId: string, statistics: ResponseStatisticsModel): Promise<ResponseStatisticsModel> {
147
+ return this.http
148
+ .get(`/statistics/${surveyId}`, {
149
+ params: {
150
+ ...statistics,
151
+ statisticsBy: 'TARGET',
152
+ },
153
+ })
154
+ .then(response => response.data);
155
+ }
156
+
157
+ loadStatisticsWithFiltersByAll(surveyId: string, statistics: ResponseStatisticsModel): Promise<ResponseStatisticsModel> {
158
+ return this.http
159
+ .post(`/statistics/${surveyId}`, {
160
+ ...statistics,
161
+ statisticsBy: 'ALL',
162
+ })
163
+ .then(response => response.data);
164
+ }
165
+
166
+ loadStatisticsWithFiltersBySurvey(surveyId: string, statistics: ResponseStatisticsModel): Promise<ResponseStatisticsModel> {
167
+ return this.http
168
+ .post(`/statistics/${surveyId}`, {
169
+ ...statistics,
170
+ statisticsBy: 'SURVEY',
171
+ })
172
+ .then(response => response.data);
173
+ }
174
+
175
+ loadStatisticsWithFiltersByTargets(surveyId: string, statistics: ResponseStatisticsModel): Promise<ResponseStatisticsModel> {
176
+ return this.http
177
+ .post(`/statistics/${surveyId}`, {
178
+ ...statistics,
179
+ statisticsBy: 'TARGET',
180
+ })
181
+ .then(response => response.data);
182
+ }
183
+
184
+ loadStatisticsBySurveyAndTarget(data: any) {
185
+ return this.http.post(`/statistics/targets`, data).then(response => response.data);
186
+ }
187
+
188
+ loadRespondents(params: any): Promise<PlanModel> {
189
+ return this.http.get(`/respondents`, { params: params }).then(response => response.data);
190
+ }
191
+
192
+ loadRespondentByPlanAndTarget(params: any): Promise<PlanModel> {
193
+ return this.http.get(`/respondents/target`, { params: params }).then(response => response.data);
194
+ }
195
+
196
+ get(url: string, params: any): Promise<Object> {
197
+ return this.exhttp.get(url, { params: params }).then(response => response.data);
198
+ }
199
+
200
+ updatePlanStatistics(params: any): Promise<ResponseStatisticsModel> {
201
+ return this.http.put('/statistics', params).then(response => response.data);
202
+ }
311
203
  }