/
index.ts
340 lines (301 loc) · 9.05 KB
/
index.ts
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
import isUrl from 'is-url-superb';
import { Location } from '../Geo';
import { getDetailedPlace, Reference } from '../Places';
import { DetailedPlace } from '../Places/Place';
import * as Dao from './DataAccess';
import { UpdatableReferenceType } from './Event';
const imageSize = '100x100';
export const createPlace = Dao.createPlace;
export const deletePlace = Dao.deletePlace;
export const updatePlaceAddress = async (
placeId: string,
suggested: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
return Dao.updatePlaceAddress(placeId, place.detail.address, suggested, note);
};
export const deletePlaceAddress = async (
placeId: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
if (!place.detail.address) {
throw new Error('Place doesn\'t have address');
}
return Dao.deletePlaceAddress(placeId, place.detail.address, note);
};
export const updatePlaceAdmission = async (
placeId: string,
suggested: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
return Dao.updatePlaceAdmission(placeId, place.detail.admission, suggested, note);
};
export const deletePlaceAdmission = async (
placeId: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
if (!place.detail.admission) {
throw new Error('Place doesn\'t have admission');
}
return Dao.deletePlaceAdmission(placeId, place.detail.admission, note);
};
export const updatePlaceEmail = async (
placeId: string,
suggested: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
return Dao.updatePlaceEmail(placeId, place.detail.email, suggested, note);
};
export const deletePlaceEmail = async (
placeId: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
if (!place.detail.email) {
throw new Error('Place doesn\'t have email');
}
return Dao.deletePlaceEmail(placeId, place.detail.email, note);
};
export const updatePlaceLocation = async (
placeId: string,
suggested: Location,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
return Dao.updatePlaceLocation(placeId, place.location, suggested, note);
};
export const createPlaceName = async (
placeId: string,
languageId: string | null,
suggested: string,
note: string | null
): Promise<string> => {
return Dao.updatePlaceName(
placeId,
languageId,
null,
suggested,
note
);
};
export const updatePlaceName = async (
placeId: string,
languageId: string | null,
suggested: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
return Dao.updatePlaceName(
placeId,
languageId,
languageId ? place.name : place.nameLocal,
suggested,
note
);
};
export const deletePlaceName = async (
placeId: string,
languageId: string | null,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
let name: string = '';
if (languageId) {
if (!place.name) {
throw new Error('Place doesn\'t have name');
}
name = place.name;
} else {
if (!place.nameLocal) {
throw new Error('Place doesn\'t have name');
}
name = place.nameLocal;
}
return Dao.deletePlaceName(
placeId,
languageId,
name,
note
);
};
export const updatePlaceOpeningHours = async (
placeId: string,
suggested: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
return Dao.updatePlaceOpeningHours(placeId, place.detail.openingHoursRaw, suggested, note);
};
export const deletePlaceOpeningHours = async (
placeId: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
if (!place.detail.openingHoursRaw) {
throw new Error('Place doesn\'t have opening hours');
}
return Dao.deletePlaceOpeningHours(placeId, place.detail.openingHoursRaw, note);
};
export const updatePlaceOpeningHoursNote = async (
placeId: string,
suggested: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
return Dao.updatePlaceOpeningHoursNote(placeId, place.detail.openingHoursNote, suggested, note);
};
export const deletePlaceOpeningHoursNote = async (
placeId: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
if (!place.detail.openingHoursNote) {
throw new Error('Place doesn\'t have opening hours');
}
return Dao.deletePlaceOpeningHoursNote(placeId, place.detail.openingHoursNote, note);
};
export const updatePlacePhone = async (
placeId: string,
suggested: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
return Dao.updatePlacePhone(placeId, place.detail.phone, suggested, note);
};
export const deletePlacePhone = async (
placeId: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
if (!place.detail.phone) {
throw new Error('Place doesn\'t have phone');
}
return Dao.deletePlacePhone(placeId, place.detail.phone, note);
};
export const createPlaceReference = async (
placeId: string,
languageId: string | null,
suggestedType: string,
suggestedUrl: string,
note: string | null
): Promise<string> => {
if (!Object.keys(UpdatableReferenceType).includes(suggestedType)) {
throw new Error('Can\'t update this reference type');
}
if (!isUrl(suggestedUrl)) {
throw new Error('Suggested URL is not valid');
}
return Dao.createPlaceReference(placeId, languageId, suggestedType, suggestedUrl, note);
};
export const updatePlaceReference = async (
placeId: string,
languageId: string | null,
referenceId: number,
suggestedUrl: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
const referenceToBeUpdated: Reference | undefined = place.detail.references.find((reference: Reference) => (
reference.id === referenceId
));
if (!referenceToBeUpdated) {
throw new Error('Reference not found');
}
if (!Object.keys(UpdatableReferenceType).includes(referenceToBeUpdated.type)) {
throw new Error('Can\'t update suggested reference type');
}
if (!isUrl(suggestedUrl)) {
throw new Error('Suggested URL is not valid');
}
return Dao.updatePlaceReference(
placeId,
languageId,
referenceToBeUpdated.url,
referenceToBeUpdated.type,
suggestedUrl,
note
);
};
export const deletePlaceReference = async (
placeId: string,
languageId: string | null,
referenceId: number,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
const referenceToBeDeleted: Reference | undefined = place.detail.references.find((reference: Reference) => (
reference.id === referenceId
));
if (!referenceToBeDeleted) {
throw new Error('Reference not found');
}
if (!Object.keys(UpdatableReferenceType).includes(referenceToBeDeleted.type)) {
throw new Error('Can\'t delete suggested reference type');
}
return Dao.deletePlaceReference(
placeId,
languageId,
referenceToBeDeleted.url,
referenceToBeDeleted.type,
note
);
};
export const createPlaceAttribute = async (
placeId: string,
languageId: string | null,
suggestedKey: string,
suggestedValue: string,
note: string | null
): Promise<string> => {
return Dao.createPlaceAttribute(placeId, languageId, suggestedKey, suggestedValue, note);
};
export const updatePlaceAttribute = async (
placeId: string,
languageId: string | null,
originalValue: string,
suggestedKey: string,
suggestedValue: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
if (!place.detail.attributes || !place.detail.attributes[suggestedKey]) {
throw new Error('Attribute not found');
}
return Dao.updatePlaceAttribute(
placeId,
languageId,
originalValue,
suggestedKey,
suggestedValue,
note
);
};
export const deletePlaceAttribute = async (
placeId: string,
languageId: string | null,
attributeKey: string,
note: string | null
): Promise<string> => {
const place: DetailedPlace = await getDetailedPlace(placeId, imageSize);
if (!place.detail.attributes || !place.detail.attributes[attributeKey]) {
throw new Error('Attribute not found');
}
return Dao.deletePlaceAttribute(
placeId,
languageId,
place.detail.attributes[attributeKey],
attributeKey,
note
);
};
export const createPlaceTag = Dao.createPlaceTag;
export const deletePlaceTag = Dao.deletePlaceTag;
export const createPlaceMedia = Dao.createPlaceMedia;
export const getEvents = Dao.getEvents;
export const moderateEvents = Dao.moderateEvents;
export const assignNextEvents = Dao.assignNextEvents;