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

[UPD] update OpenSPP adaptor with new functions #435

Merged
merged 6 commits into from
Nov 17, 2023

Conversation

nhatnm0612
Copy link
Contributor

Summary

Update OpenSPP adaptor with new functions

Details

Including these new functions as requested:

  • createIndividual: create new individual
  • updateIndividual: update existing individual
  • createGroup: create new group
  • updateGroup: update existing group
  • addToGroup: add individual to group with(out) role
  • removeFromGroup: end membership of individual to group

Issues

Requests From My Company

Review Checklist

Before merging, the reviewer should check the following items:

  • Does the PR do what it claims to do?
  • If this is a new adaptor, has the migration tool been run and the
    migration guide followed?
  • Are there any unit tests? Should there be?
  • Is there a changeset associated with this PR? Should there be? Note that
    dev only changes don't need a changeset.

Copy link
Collaborator

@josephjclark josephjclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi again! I've left a couple of suggestions for you to think about. I would address the const and callback thing for sure, maybe think a little bit more about error handling and validation - that stuff is up to you really.

packages/openspp/src/Adaptor.js Outdated Show resolved Hide resolved
packages/openspp/src/Adaptor.js Outdated Show resolved Hide resolved
}
return nextState;
} catch (err) {
console.log(`✗ Error: ${err}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I gave you bad advice before - I'm not sure what I was thinking now!

You may not always want to return state if there's an error. It depends on the error really. Sometimes it's fine to throw the error and let the job "crash". You should only trap the error if it's non-fatal or the next operation should still run.

In this case, if there's a validation error on the data, the job will carry on running. That might not be what you want - it might be better for the job to die, and alert the team that action needs to be taken.

packages/openspp/src/Adaptor.js Outdated Show resolved Hide resolved
if (res.length > 0) {
let groupMembershipIds = res.map( i => i.id );
let now = new Date();
let sppDateTimeNowString =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am reluctant to suggest this because I think it's broken in the CLI and it's not really a pattern I'm keen to support... but the common adaptor exports a dateFns objects. dateFns has a format function which is really useful for this stuff: https://date-fns.org/v2.16.1/docs/format

If it works it'll let you do something like this:

 let sppDateTimeNowString = format (new Date(), 'y-M-d H:m:s')`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done replacing

@@ -3,3 +3,14 @@
## 1.0.0

- Create OpenSPP adaptor

## 1.0.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First off can you put the most recent changes first in the log?

Secondly, for future reference, next time you want to update the version, please run pnpm changeset from the repo root. That'll ask you some questions and generate a changelog for you. There should be more details in the main readme.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 😄

@josephjclark
Copy link
Collaborator

@nhatnm0612 I think this is looking great - can I just check you're happy with the error handling for now? You can always raise a PR to change it later, of course :)

If you're happy we'll take it on and try and get a release out today.

@josephjclark josephjclark changed the base branch from main to release/openspp November 17, 2023 09:18
@nhatnm0612
Copy link
Contributor Author

@nhatnm0612 I think this is looking great - can I just check you're happy with the error handling for now? You can always raise a PR to change it later, of course :)

If you're happy we'll take it on and try and get a release out today.

I am please with this error handling for now, we users now are technical people anyway. I will change these error handling in the future if needed @josephjclark

it is a pleasure working with you, there were lots of things that I learnt from you guys 😄

@josephjclark josephjclark merged commit 4e0cdc6 into OpenFn:release/openspp Nov 17, 2023
1 check passed
@nhatnm0612
Copy link
Contributor Author

@josephjclark can I push 1 more update? I found an error with dateFns format, please wait. I never met this before coz the time I test these function is not expose that error

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.

2 participants