@bit-ui-libs/common
Version:
This library was generated with [Nx](https://nx.dev).
107 lines (102 loc) • 2.98 kB
text/typescript
import {
AttachmentClassification,
CreateAttachmentInputData,
DEFAULT_APP_ID,
DeviceTypeEnum,
GeolocationData,
ReferenceType,
RelationTypeEnum,
SubjectDataReferenceItem,
SubjectTypeEnum,
makeSampleGeolocation,
} from '../common';
import { CreateCheckInEventRequest, UpdateCheckInAttachmentRequest } from './check-in-service.interfaces';
import { CheckInProperty } from './interfaces';
export interface MakeCreateCheckInEventRequestOpts {
appId?: string;
reference?: SubjectDataReferenceItem;
deviceId?: string;
deviceName?: string;
deviceType?: DeviceTypeEnum;
geolocation?: GeolocationData;
ipAddress?: string;
attachments?: CreateAttachmentInputData[];
properties?: CheckInProperty[];
auth0Id?: string;
orgId?: string;
subjectType?: SubjectTypeEnum;
parentEvent?: CreateCheckInEventRequest['event'];
approved?: boolean;
categoryId?: string;
}
export function makeCreateCheckInEventRequest(opts?: MakeCreateCheckInEventRequestOpts): CreateCheckInEventRequest {
const date = new Date().toISOString();
const references: SubjectDataReferenceItem[] = [];
if (opts?.reference) references.push(opts.reference);
if (opts?.auth0Id) {
references.push({
type: ReferenceType.AUTH0_IDENTITY,
value: opts.auth0Id,
});
}
return {
application: { id: opts?.appId ?? DEFAULT_APP_ID },
subject: {
// Accepted values for now are only "EMPLOYEE", "DRIVER"
subjectType: opts?.subjectType ?? 'EMPLOYEE',
references,
orgId: opts?.orgId,
},
device: {
date,
deviceType: opts?.deviceType ?? DeviceTypeEnum.PHONE,
deviceId: opts?.deviceId ?? '',
deviceName: opts?.deviceName ?? '',
geolocation: opts?.geolocation ?? makeSampleGeolocation(),
ipAddress: opts?.ipAddress ?? '',
},
event: opts?.parentEvent,
data: {
date,
properties: opts?.properties,
attachments: opts?.attachments,
approved: opts?.approved,
categoryId: opts?.categoryId,
},
};
}
export interface MakeUpdateCheckInAttachmentRequestOpts {
appId?: string;
eventId: string;
geolocation: GeolocationData;
attachmentId: string;
name?: string;
imageBase64: string;
classification: AttachmentClassification;
isMain?: boolean;
eventToken?: string;
relationType?: RelationTypeEnum;
}
export function makeUpdateCheckInAttachmentRequest(
opts: MakeUpdateCheckInAttachmentRequestOpts
): UpdateCheckInAttachmentRequest {
return {
application: { id: opts?.appId ?? DEFAULT_APP_ID },
eventId: opts.eventId,
geolocation: opts.geolocation,
docs: [
{
docId: opts.attachmentId,
data: opts.imageBase64,
docType: 'PHOTO',
classification: opts.classification,
name: opts.name ?? '',
description: '',
mimeType: 'image/png',
isMain: !!opts.isMain,
},
],
eventToken: opts.eventToken,
relationType: opts.relationType,
};
}