Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mask method #101

Merged
merged 2 commits into from
Jun 27, 2023
Merged

feat: mask method #101

merged 2 commits into from
Jun 27, 2023

Conversation

fratzinger
Copy link
Owner

@fratzinger fratzinger commented Jun 27, 2023

This PR adds a first implementation for custom methods.

As of now, my custom methods behave like other regular method. I have a sum method for which I need the find permissions to apply. So I use options.method to 'overwrite' context.method.

Example:

class CustomService extends MemoryService {
  sum(data: any, params: any) {
    return this.find(params);
  }
}

app.use("tests", new CustomService({ ... }), {
  methods: ["find", "get", "create", "update", "patch", "remove", "sum"],
})

const service = app.service("tests");

service.hooks({
  before: {
    sum: [
      authorize({
        method: "find",
        adapter: "@feathersjs/memory",
      }),
    ],
  },
  after: {
    sum: [
      authorize({
        method: "find",
        adapter: "@feathersjs/memory",
      }),
    ],
  },
});

const items = (await service.sum(null, {
  ability: defineAbility(
    (can) => {
      can("read", "tests", { userId: 1 });
    },
    { resolveAction }
  ),
  paginate: false,
}));

@fratzinger fratzinger changed the title Feat/mask method feat: mask method Jun 27, 2023
@fratzinger fratzinger merged commit 8da9b3e into main Jun 27, 2023
@fratzinger fratzinger deleted the feat/mask-method branch June 27, 2023 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant