-
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
Conversation
@@ -6,7 +6,7 @@ | |||
"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/**/*", | |||
"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 comment
The reason will be displayed to describe this comment to others. Learn more.
Feedback from #40
apps/api/tests/api/index.test.ts
Outdated
@@ -20,7 +20,7 @@ | |||
import assert from 'node:assert'; | |||
import { after, describe, it } from 'node:test'; | |||
|
|||
import { port } from '../server.js'; | |||
import { port } from '../../src/server.js'; |
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.
test
folder moved out of src
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.
Minor stuff and a suggestion, otherwise lgtm 🔥
apps/api/src/api/application-api.ts
Outdated
const applicationRecord = result.data; | ||
|
||
// Validate Application state will allow updates | ||
// Edits to Applications under review will revert state to 'DRAFT' | ||
const { state } = applicationRecord; |
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.
Variable applicationRecord
doesn't need to be defined here we can deconstruct directly out of result.data
if (result.success) { | ||
res.send(result.data); | ||
} else { | ||
res.status(500).send({ error: `Error updating application with id ${id}` }); | ||
res.status(500).send({ message: result.message, errors: result.errors }); | ||
} |
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.
More of a personal suggestion, I'm a fan of this syntax I find it easier to read and easier to add more error checks in the future if needed:
if (!result.success) {
res.status(500).send({ message: result.message, errors: result.errors });
return;
}
res.send(result.data);
But the current solution works if you wish to proceed.
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.
Yes fair, the else
could be removed. Generally we prefer putting the 'truthy' condition first but your recommendation is still applicable.
Also in the code snippet above I think you copied the Git diff, double res.send's would trigger an error.
Just to be sure I understand you right, you're saying else
is not needed here.
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.
edit: My editor seems to prefer keeping the else
as a type guard to enforce result is failure
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.
Ah yes my bad, there would be a return statement after the correct res
. I have updated it to what my initial thoughts were.
…/daco into feat/22-application-update-methods
|
||
- Drizzle is configured to read the schema from the build directory (`/dist`) due to a known Drizzle Kit issue with ESM imports. Any Drizzle Kit operations (including migrations) require first building the application with `pnpm run build`. | ||
|
||
- A schema dbml (database markup language) file can be generated using the script `pnpm run dbml`. This file is found at `./src/db/schema.dbml`. |
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.
👍
apps/api/tsconfig.json
Outdated
@@ -6,5 +6,5 @@ | |||
"module": "NodeNext", | |||
"moduleResolution": "NodeNext" | |||
}, | |||
"include": ["src", "./drizzle.config.ts"] | |||
"include": ["src", "./drizzle.config.ts", "tests"] |
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.
is there a reason why we are including test
folder in here?
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.
This was an auto update from moving folders around, doesn't need to be included
const applicationRouter = express.Router(); | ||
const jsonParser = bodyParser.json(); | ||
|
||
applicationRouter.post('/application/edit/', jsonParser, async (req, res) => { |
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.
seems this route hasn't been included in the Swagger documentation
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.
Good call -- we just added swagger yesterday. Adding now.
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.
Added /edit Swagger endpoint, tested and working
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.
if (result.success) { | ||
res.send(result.data); | ||
} else { | ||
res.status(500).send({ message: result.message, errors: String(result.errors) }); |
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.
I see this will always return a 500
error code when condition is falsy. However, considering there is a TODO to implement auth and Zod validations, just curious is this also includes the case where id
doesn't exist in the database? would that return 4xx
or 5xx
?
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.
Yes -- if id is not found we're returning a 500
I can update to a 4xx
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.
Added basic updates for 404 handling. We don't have a central error handler setup yet so I've added a TODO as well.
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.
Great updates in this PR. I’ve left a few comments but so far looks good to me.
'400': | ||
description: 'Error editing application - Application not found' | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
'200': | ||
description: 'Application updated' | ||
content: | ||
application/json: | ||
schema: | ||
type: object |
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.
responses schemas can also be defined here using the structures defined by the success
and failure
helpers
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.
Will add in #58
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.
LGTM
Feat: #22: Application Update Methods
Summary
Related Issues
Description of Changes
editApplication
method for updating application contentseditApplication
function which validates application state allows editshttps://github.com/Pan-Canadian-Genome-Library/daco/pull/40/files
Special Instructions
Changes to Drizzle config require running
pnpm run build
to allowdrizzle-kit
operationsdrizzle-kit
now uses/dist
for schema lookupReadiness Checklist
#{TicketNumber}: Description of Changes
api
,ui
,data-model
, etc.)feature
,fix
,chore
,documentation
).env.schema
file and documented in the README