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

Add REST Endpoint for DAC Application Approval with Validation and State Management #148

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Azher2Ali
Copy link

Summary

#117- Introduced a new REST endpoint that allows DAC (Data Access Committee) members to approve applications. This feature ensures robust state transitions, clear validations, and comprehensive user feedback.

Description of Changes

API

  • New Endpoint: POST /applications/{applicationId}/approve

    • Allows DAC to approve applications one at a time.
    • Validates applicationId and approverId as required fields and ensures they are numbers.
    • Updates the state of an application to approved and integrates with the state transition machine.
    • Prevents modifications to approved applications by any user.
  • Response:

    • Provides clear feedback on success or failure of approval.
    • Uses structured error handling with proper HTTP status codes and descriptive messages.
  • Swagger Documentation:

    • Added comprehensive instructions for using the endpoint, including request/response formats and validation criteria.

Service

  • Refined logic to handle state transitions robustly.
  • Ensures the service prevents type-related errors and edge cases during the approval process.
  • Updates application history to include:
    • Timestamp of approval.
    • Information about the approver.

Data Model

  • Added support for storing approval metadata, including the approver’s details and approval timestamp.

Special Instructions

Before running these changes:

  • Ensure all dependencies are up-to-date by running:
    pnpm i
    

@Azher2Ali Azher2Ali linked an issue Jan 14, 2025 that may be closed by this pull request
});
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have the Prettier extension installed? There are whitespace changes here which don't match what I'd expect to see

Copy link
Author

Choose a reason for hiding this comment

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

Missed adding Prettier under my extention list, will surely keep in mind for the next time. Thanks for noticing!

@@ -0,0 +1,23 @@
import { ApplicationStates, ApplicationStateValues } from "@pcgl-daco/data-model/src/types.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

a) new files need the Copyright at the top
b) We have ApplicationStateManager defined at https://github.com/Pan-Canadian-Genome-Library/daco/blob/main/apps/api/src/api/states.ts#L61
which extends functionality https://github.com/eram/typescript-fsm

including the .can method which could essentially perform the same function as this.
I would use the existing class and work within that framework.

Now, there may not be implementation examples for the State Machine yet in the API, except for in the unit tests: https://github.com/Pan-Canadian-Genome-Library/daco/blob/main/apps/api/tests/api/application-state.test.ts

So I can review this with you and show how Jon and I were intending to implement the state machine and action updates

Copy link
Contributor

@demariadaniel demariadaniel left a comment

Choose a reason for hiding this comment

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

Off to a great start, handful of changes to iron out first

@Azher2Ali Azher2Ali added the documentation Improvements or additions to documentation label Jan 16, 2025
applicationId,
approverId,
applicationId,
approverId,
Copy link
Contributor

Choose a reason for hiding this comment

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

approverId is unused here

success: false,
message: 'Application not found.',
errors: 'ApplicationNotFound',
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This can just be (!result.success) { return result }
The success, errors and message will already be populated by getApplicationById

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API documentation Improvements or additions to documentation New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Endpoint to Allow DAC Approve
2 participants