-
Notifications
You must be signed in to change notification settings - Fork 0
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/ #22 Application Update methods #80
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e3f3b78
Service Edit method
demariadaniel 637f637
Move Test Files
demariadaniel 501d6f0
Use .test naming convention
demariadaniel ed2be28
Move API test file
demariadaniel 420a74f
Tests for Edit Method
demariadaniel c2ea32e
Remove npx
demariadaniel 7b84efb
DBml / schema updates
demariadaniel 1fb30cd
Use dist folder for config, add first readme update
demariadaniel a44b23c
Setup Router & API + Move logic out of service
demariadaniel 42afe20
Working API Test w/ some reorg
demariadaniel eb27584
Edit for clarity
demariadaniel 04f0dc6
Remove Demo endpoint
demariadaniel ffbe16f
Route + service improvements
demariadaniel ba949f7
Add todo
demariadaniel fc3e38a
Move service type, add error condition
demariadaniel 5002a86
First updates with success/failure
demariadaniel 728572e
Move tests
demariadaniel 5d4915f
Use Success/Failure pattern with getById
demariadaniel 060f027
Add TSDoc
demariadaniel 2783fee
Add getDbInstance type
demariadaniel 596affa
Throw err is no db instance
demariadaniel d3a8b30
Add body parser
demariadaniel b77bb36
Simplify variable declaration
demariadaniel c0079dc
Add Comments + Transaction
demariadaniel cfc1cb6
Merge branch 'main' of https://github.com/Pan-Canadian-Genome-Library…
demariadaniel f08b6a9
Print error message in response
demariadaniel fa1202e
Remove tests from tsconfig
demariadaniel fc7cce3
Add Edit endpoint to Swagger w/ 404
demariadaniel 7ceb7ea
Add Error Todo
demariadaniel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ | |
"scripts": { | ||
"build": "rimraf ./dist && tsc", | ||
"dev": "tsx watch --env-file=.env ./src/main.ts", | ||
"test": "npx tsx --test --test-reporter=spec --experimental-test-coverage ./src/tests/**/*", | ||
"dbml": "tsx ./src/db/dbml.ts", | ||
"test": "tsx --test --test-reporter=spec --experimental-test-coverage ./tests/**/*.test.ts", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feedback from #40 |
||
"start:prod": "node ./dist/src/main.js" | ||
}, | ||
"devDependencies": { | ||
|
@@ -24,6 +25,8 @@ | |
}, | ||
"dependencies": { | ||
"@pcgl-daco/data-model": "workspace:^", | ||
"@types/body-parser": "^1.19.5", | ||
"body-parser": "^1.20.3", | ||
"cors": "^2.8.5", | ||
"drizzle-orm": "^0.35.3", | ||
"express": "^4.21.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2024 The Ontario Institute for Cancer Research. All rights reserved | ||
* | ||
* This program and the accompanying materials are made available under the terms of | ||
* the GNU Affero General Public License v3.0. You should have received a copy of the | ||
* GNU Affero General Public License along with this program. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
import { ApplicationStates } from '@pcgl-daco/data-model/src/types.js'; | ||
import { getDbInstance } from '../db/index.js'; | ||
import applicationService from '../service/application-service.js'; | ||
import { type ApplicationContentUpdates, type ApplicationService } from '../service/types.js'; | ||
import { failure } from '../utils/results.js'; | ||
|
||
/** | ||
* Validates if a given Application state allows edits, then updates the record | ||
* Updated records are returned in state 'DRAFT' | ||
* @param id - Application ID | ||
* @param update - Application Contents details to update | ||
* @returns Success with Application data / Failure with Error | ||
*/ | ||
export const editApplication = async ({ id, update }: { id: number; update: ApplicationContentUpdates }) => { | ||
const database = getDbInstance(); | ||
const service: ApplicationService = applicationService(database); | ||
|
||
const result = await service.getApplicationById({ id }); | ||
|
||
if (!result.success) { | ||
return result; | ||
} | ||
|
||
const { state } = result.data; | ||
|
||
// TODO: Replace w/ state machine https://github.com/Pan-Canadian-Genome-Library/daco/issues/58 | ||
const isEditState = | ||
state === ApplicationStates.DRAFT || | ||
state === ApplicationStates.INSTITUTIONAL_REP_REVIEW || | ||
state === ApplicationStates.DAC_REVIEW; | ||
|
||
if (isEditState) { | ||
const result = await service.editApplication({ id, update }); | ||
return result; | ||
} else { | ||
const message = `Cannot update application with state ${state}`; | ||
console.error(message); | ||
return failure(message); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍