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/6 API Service Layer #40

Merged
merged 68 commits into from
Nov 28, 2024

Conversation

demariadaniel
Copy link
Contributor

@demariadaniel demariadaniel commented Nov 12, 2024

#6

  • Adds Application Service w/ create, find by id, list many, update, delete functionality
    • this template can be adapted to other Models
  • Includes filtering / sorting as described in ticket
  • Full set of unit tests
  • Separates implementations for connecting to live DB / test-DB
  • Add updatedAt field to Applications
  • Fix a few relation fields

@demariadaniel demariadaniel linked an issue Nov 12, 2024 that may be closed by this pull request
12 tasks
@joneubank joneubank self-requested a review November 27, 2024 14:48
@demariadaniel demariadaniel force-pushed the feat/6-api-service-layer branch from 1c8d677 to 70cfdfb Compare November 28, 2024 15:24
joneubank
joneubank previously approved these changes Nov 28, 2024
Copy link
Contributor

@joneubank joneubank left a comment

Choose a reason for hiding this comment

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

Good stuff!


import { applications } from '../db/schemas/applications.js';

export type ApplicationUpdates = Partial<typeof applications.$inferInsert>;
Copy link
Contributor

Choose a reason for hiding this comment

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

πŸ™Œ

startWith: 1,
increment: 1,
minValue: 1,
maxValue: 9223372036854775807,
Copy link
Contributor

Choose a reason for hiding this comment

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

why this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was generated using drizzle-kit pull so it's the auto-generated upper limit for a BigInt

Copy link

Choose a reason for hiding this comment

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

I think this file and other files generated by drizzle-kit pull are not required, as we're already managing the database schemas using schema files located at src/db/schemas/.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leo and I chatted about this -- there is a disconnect between the DBML schema input (expects an object) and the Drizzle config schema definition (string glob path to schemas folder './schemas/**')

This should be refactored so that both point to the same schema definition, my only hesitation is to limit the scope of this PR. I will update this and the test files in the next branch.

institutionCity: varchar('institution_city', { length: 255 }),
institutionStreetAddress: text('institution_street_address'),
institutionPostalCode: varchar('institution_postal_code', { length: 255 }),
institutionBuilding: varchar('institution_building', { length: 255 }),
Copy link
Contributor

Choose a reason for hiding this comment

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

out of curiosity, whats the default length if not specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If character varying (or varchar) is used without length specifier, the type accepts strings of any length.
https://www.postgresql.org/docs/current/datatype-character.html
https://orm.drizzle.team/docs/column-types/pg#varchar
Drizzle says nothing so referring to PG docs

@@ -6,14 +6,16 @@
"scripts": {
"build": "rimraf ./dist && tsc",
"dev": "tsx watch --env-file=.env ./src/main.ts",
"test": "tsx --env-file=.env.test --test --test-reporter=spec --experimental-test-coverage ./src/tests/**/*",
"test": "npx tsx --test --test-reporter=spec --experimental-test-coverage ./src/tests/**/*",
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't need npx here, tsx is installed in dev dependencies.

Comment on lines +23 to +30
DRAFT = 'DRAFT',
INSTITUTIONAL_REP_REVIEW = 'INSTITUTIONAL_REP_REVIEW',
DAC_REVIEW = 'DAC_REVIEW',
DAC_REVISIONS_REQUESTED = 'DAC_REVISIONS_REQUESTED',
REJECTED = 'REJECTED',
APPROVED = 'APPROVED',
CLOSED = 'CLOSED',
REVOKED = 'REVOKED',
Copy link
Contributor

Choose a reason for hiding this comment

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

Important to use these named enum values if we are using TS enums, so thank you for this update. We can take a moment to review our enum usage in a future change.

};

try {
const application = await db.transaction(async (transaction) => {
Copy link

Choose a reason for hiding this comment

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

πŸ‘

Copy link

Choose a reason for hiding this comment

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

just wondering, should test/ folder be at top level along the src/. also consider changing extension to differentiate the actual code like .test.ts or .spec.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, argo-clinical does have test at the same level as src and we have generally used the .spec convention

I need these changes in main to unblock other work so I can incorporate these suggestions into the next branch

Copy link

@leoraba leoraba left a comment

Choose a reason for hiding this comment

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

LGTM πŸŽ‰

@demariadaniel demariadaniel merged commit eccc7e8 into main Nov 28, 2024
@demariadaniel demariadaniel deleted the feat/6-api-service-layer branch November 28, 2024 20:05
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.

Create Application Service Layer - Initial Simple Actions
4 participants