Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 10x 10x 10x 10x 10x 10x 10x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x | import ABatchNode from '@orchesty/nodejs-sdk/dist/lib/Batch/ABatchNode';
import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
import BatchProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/BatchProcessDto';
export const NAME = 'raynet-crm-get-activities';
export const LAST_RUN_KEY = 'lastRunListActivities';
export const LIMIT = 1000;
export default class RaynetCRMGetActivities extends ABatchNode {
public getName(): string {
return NAME;
}
public async processAction(dto: BatchProcessDto<IInput>): Promise<BatchProcessDto> {
const { from } = dto.getJsonData();
const appInstall = await this.getApplicationInstallFromProcess(dto);
const lastRun = await appInstall.getNonEncryptedSettings()[LAST_RUN_KEY];
const lastRunDate = lastRun ? new Date(lastRun) : new Date(0);
const formattedDate = `${lastRunDate.getFullYear()}-${lastRunDate.getMonth() + 1}-${lastRunDate.getDate()}%20${lastRunDate.getHours()}:${lastRunDate.getMinutes()}`;
const page = Number(dto.getBatchCursor('0'));
const req = await this.getApplication().getRequestDto(
dto,
await this.getApplicationInstallFromProcess(dto),
HttpMethods.GET,
`activity?offset=${page}&limit=${LIMIT}&rowInfo.lastModifiedAt[GE]=${formattedDate}&dateFormat=ISO8601${from ? `&scheduledFrom=${from}` : ''}`,
);
const resp = await this.getSender().send<IResponse>(req, [200]);
const { totalCount } = resp.getJsonBody();
Iif (totalCount && totalCount > LIMIT * (page + 1)) {
dto.setBatchCursor(String(page + 1));
} else {
appInstall.addNonEncryptedSettings({
[LAST_RUN_KEY]: new Date().toISOString(),
});
await this.getDbClient().getApplicationRepository().update(appInstall);
}
return dto.setItemList(resp.getJsonBody().data);
}
}
export interface IInput {
from?: string;
}
/* eslint-disable @typescript-eslint/naming-convention */
export interface IResponse {
success: boolean;
totalCount: number;
data: IOutput[];
}
export interface IOutput {
_entityName: string;
id: number;
title: string;
personal: boolean;
status: string;
priority: string;
scheduledFrom: string;
scheduledTill: string;
description: string;
tags: unknown[];
'rowInfo.createdAt': string;
'rowInfo.createdBy': string;
'rowInfo.updatedAt': string;
securityLevel: {
id: number;
name: string;
};
_version: number;
customFields: unknown;
participants: {
owner: boolean;
role: string;
name: string;
person: number;
}[];
owner: {
id: number;
fullName: string;
};
meetingPlace: string;
companyAddress: unknown;
recurrence: {
id: number,
count: number,
endDate: string,
interval: string,
recurrenceDay: number,
startDate: string
};
}
/* eslint-enable @typescript-eslint/naming-convention */
|