All files / src/Batch BoxListTasksBatch.ts

100% Statements 14/14
50% Branches 1/2
100% Functions 2/2
100% Lines 14/14

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 102 103 104 105 106 107 108 109 110 111 112 113 1143x 3x     3x   3x     3x       1x   1x 1x 1x           1x 1x   1x 1x   1x                                                                                                                                                                        
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 = 'box-list-tasks-batch';
 
export default class BoxListTasksBatch extends ABatchNode {
 
    public getName(): string {
        return NAME;
    }
 
    public async processAction(dto: BatchProcessDto<IInput>): Promise<BatchProcessDto> {
        const { file_id } = dto.getJsonData();
 
        const appInstall = await this.getApplicationInstallFromProcess(dto);
        const url = `files/${file_id}/tasks`;
        const req = await this.getApplication().getRequestDto(
            dto,
            appInstall,
            HttpMethods.GET,
            url,
        );
        const resp = await this.getSender().send<IResponse>(req, [200]);
        const response = resp.getJsonBody();
 
        dto.setItemList(response.entries ?? []);
        dto.removeBatchCursor();
 
        return dto;
    }
 
}
 
/* eslint-disable @typescript-eslint/naming-convention */
 
export interface IInput {
    file_id: string;
}
 
interface IResponse {
    entries: IOutput[];
    total_count: number;
}
 
export interface IOutput {
    id: number;
    type: string;
    item: {
        id: number;
        etag: number;
        type: string;
        sequence_id: number;
        name: string;
        sha1: string;
        file_version: {
            id: number;
            type: string;
            sha1: string;
        };
    };
    due_at: Date;
    action: string;
    message: string;
    task_assignment_collection: {
        total_count: number;
        entries: {
            id: number;
            type: string;
            item: {
                id: number;
                etag: number;
                type: string;
                sequence_id: number;
                name: string;
                sha1: string;
                file_version: {
                    id: number;
                    type: string;
                    sha1: string;
                };
            };
            assigned_to: {
                id: number;
                type: string;
                name: string;
                login: string;
            };
            message: string;
            completed_at: Date;
            assigned_at: Date;
            reminded_at: Date;
            resolution_state: string;
            assigned_by: {
                id: number;
                type: string;
                name: string;
                login: string;
            };
        }[];
    };
    is_completed: boolean;
    created_by: {
        id: number;
        type: string;
        name: string;
        login: string;
    };
    created_at: Date;
    completion_rule: string;
}
 
/* eslint-enable @typescript-eslint/naming-convention */