/
helpers.ts
68 lines (63 loc) · 2.07 KB
/
helpers.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
import { ServiceRequestChannel, ServiceRequestStatus } from '../../types';
import { Open311Service, Open311ServiceRequest, Open311ServiceRequestCreatePayload } from './types';
interface ServiceAttributes {
id: string;
name: string;
group: string;
jurisdictionId: string;
}
interface ServiceRequestAttributes {
id: string;
serviceId?: string;
jurisdictionId: string;
description: string;
address: string;
firstName: string;
lastName: string;
email: string;
phone: string;
channel: ServiceRequestChannel;
status: ServiceRequestStatus;
assignedTo: string;
createdAt: Date;
updatedAt: Date;
images: string[];
lat: number;
lon: number
}
export const toOpen311Service = (service: ServiceAttributes): Open311Service => ({
service_code: service.id,
service_name: service.name,
metadata: false,
type: 'realtime',
group: service.group,
});
export const toOpen311ServiceRequest = (serviceRequest: ServiceRequestAttributes): Open311ServiceRequest => ({
service_request_id: serviceRequest.id,
description: serviceRequest.description,
address: serviceRequest.address,
status: serviceRequest.status === 'done' ? 'closed' : 'open',
service_name: '', // TODO: populate field and return service name
service_code: serviceRequest.serviceId || '',
requested_datetime: serviceRequest.createdAt.toISOString(),
updated_datetime: serviceRequest.updatedAt.toISOString(),
address_id: '',
lat: serviceRequest.lat,
long: serviceRequest.lon,
zipcode: '',
media_url: serviceRequest.images?.length > 0 ? serviceRequest.images[0] : '',
});
export const toGovflowServiceRequest = (payload: Open311ServiceRequestCreatePayload): Partial<ServiceRequestAttributes> => ({
jurisdictionId: payload.jurisdiction_id,
serviceId: payload.service_code,
description: payload.description || '',
address: payload.address_string || '',
firstName: payload.first_name,
lastName: payload.last_name,
phone: payload.phone || '',
email: payload.email || '',
channel: '',
lat: payload.lat as number,
lon: payload.long as number,
images: [payload.media_url as string]
});