lpg2709 / clickup_api

No oficial module for ClickUp API
https://www.npmjs.com/package/clickup_api
MIT License
6 stars 11 forks source link

param.length > 1, get request goes with no parameter #10

Closed mcannesson closed 11 months ago

mcannesson commented 11 months ago

Hello,

In those component in folder src\components\ image You use "params.length > 1" but "params" is of type object. I'm pretty sure you want to test "param" instead (the generated string from "params"), this cause a request with empty parameters.

Other: Nice to have can you add a parameter to merge all pages of a request? image Here I have a request that exceed 100 tasks, so API returns "last_page": false it would be fantastic if wa have all values in 1 clickup_api request :)

Thanks !

lpg2709 commented 11 months ago

Hi,

Hmm, i see that problem on MR #6, but i forget to fix on other components, sorry man.

I make a better solution for that and apply for all components, this gonna be released on version 1.2.1

About the fetch all task with only one request: I try to keep this package most close to the official API documentation, they make this requests that can return a lot of data with pagination.

Because of the design and focus of the package a can't create this method, this would make more sense for a new package with a better abstraction of the API, something that modulate de API like a object orientation.

You can make a function like:

async function fetchAllTasks(clickup, list_id) {
    var tasks = [];
    var param = {
        list_id,
        "archived": false,
        "page": 0,
    };

    var getedAll = false;
    return new Promise(async (resolve, reject) => {
        while(!getedAll) {
            try{
                var info = await clickup.Tasks.get_tasks(param);
                tasks.push(...info["tasks"])
                if(info["last_page"] === false)
                    param.page += 1;
                else
                    getedAll = true;
            }catch(err){
                reject("Fetch all tasks fail: ", err);
            }
        }
        resolve(tasks);
    });
}

This gonna fetch all the tasks for you, to the end of all pages.

Thanks for your report, i hope to release the 1.2.1 until the Monday.

lpg2709 commented 11 months ago

Fixed on: https://github.com/lpg2709/clickup_api/tree/v1.2.1

mcannesson commented 11 months ago

Thanks for the correction ! Yes I've already done a methods to concat pagination, I understand your point of view about this question and I agree with you.

Thanks for the time.