jhonderson / actual-http-api

Basic Actual Budget API exposed through HTTP endpoints
MIT License
40 stars 9 forks source link

Return Hidden Category Bool #5

Closed ioslife closed 8 months ago

ioslife commented 9 months ago

If a category is hidden, there should be a boolean that is returned stating so.


{
    "id": "d57f2054-030c-4a67-bf5d-d33fe0e14169",
    "name": "Hidden Category",
    "is_income": false,
    "group_id": "b7477b4f-7d27-4cb9-8b72-a174aa08a510",
    "budgeted": 1000,
    "spent": -1000,
    "balance": 0,
    "carryover": false
    "is_hidden": true

}
jhonderson commented 9 months ago

Hello,

Since this project is just a wrapper of Actual NodeJS api, this feature needs to be requested on Actual NodeJS api GitHub project, as a feature request.

You can request it an hope it gets prioritized by the team, or you can submit the change yourself. It seems to be a small change in the component mapping the internal representation of the categories to the external representation: here for categories, and here for category groups.

Example of change:

export const categoryModel = {
  ...models.categoryModel,

  toExternal(category) {
    return {
      id: category.id,
      name: category.name,
      is_income: category.is_income ? true : false,
      hidden: category.hidden ? true : false,
      group_id: category.cat_group,
    };
  },

  fromExternal(category) {
    const { group_id: _, ...result } = category;
    if ('is_income' in category) {
      result.is_income = category.is_income ? 1 : 0;
    }
    if ('hidden' in category) {
      result.hidden = category.hidden ? 1 : 0;
    }
    if ('group_id' in category) {
      result.cat_group = category.group_id;
    }
    return result;
  },
};

export const categoryGroupModel = {
  ...models.categoryGroupModel,

  toExternal(group) {
    return {
      id: group.id,
      name: group.name,
      is_income: group.is_income ? true : false,
      hidden: group.hidden ? true : false,
      categories: group.categories.map(categoryModel.toExternal),
    };
  },

  fromExternal(group) {
    const result = { ...group };
    if ('is_income' in group) {
      result.is_income = group.is_income ? 1 : 0;
    }
    if ('hidden' in group) {
      result.hidden = group.hidden ? 1 : 0;
    }
    if ('categories' in group) {
      result.categories = group.categories.map(categoryModel.fromExternal);
    }
    return result;
  },
};

Once the feature is applied and released, I can update this project to reflect the changes.

ioslife commented 9 months ago

Made a PR this morning – https://github.com/actualbudget/actual/pull/2062

ioslife commented 9 months ago

@jhonderson merged! https://github.com/actualbudget/actual/pull/2062#pullrequestreview-1784678031

jhonderson commented 8 months ago

Great! I’ll update this once they release the new version of their nodejs library

jhonderson commented 8 months ago

@ioslife I just released a new version which should include your changes. Feel free to close once you confirm this.

ioslife commented 8 months ago

Nice! Thanks! I think it works, though now I can't get the whole local server working properly to verify hah. Swagger looks good though.

ioslife commented 8 months ago

Unknown error while interacting with Actual Api. See server logs for more information Error: This file is encrypted with an old unsupported key style. Recreate the key on a device where the file is available, or use an older version of Actual to download it.

jhonderson commented 8 months ago

I have seen this error before when interacting with an encrypted budget without providing an encryption password, or when interacting with a unencrypted budget while providing an encryption password. Please try with a new unencrypted budget to see how it goes

ioslife commented 8 months ago

Hmmmmm. My budget isn't currently encrypted and I didn't set any encryption key

jhonderson commented 8 months ago

Got it, could you please share the curl command ? Swagger can generate it

ioslife commented 8 months ago

Hah! I figured it out. Postman was sending

image

oops.

ioslife commented 8 months ago

Looks good! Closing!