Skip to content

Commit

Permalink
Initial models and Routes - Agencies/Organizations (#13)
Browse files Browse the repository at this point in the history
* chore: initial commit

* chore: add basic models

* Feature/2228 Add Agency, Edit Agency and View Agencies pages (#27)

* 2228 generate Agency model, use redwood scaffold tool to generate CRUD for agency routes, add bootstrap

* feature/2228 add useAuth

* Revert "feature/2228 add useAuth"

This reverts commit a57f995.

* feature/2228 comment out create, edit, view agency routes

* feature/2228 display agencies that belong to tenant

* feature/2228 remove .redwood/ files, comment out Add Agency route

* bring back CRUD routes, display agency id in agency form

* feature/2228 update to named query in AgenciesCell

* enable edit and add agency pages, add reset functionality that clears form (Add new agency) or reverts it to the previous save (Edit), add form validation, styling, override default bootstrap invalid-feedback colors

* feature/2228 add red border around invalid fields when submitting the Agency form

* feature/2228 fix misnamed Agency type in agencies.test.ts

* 22 changing tenant table to organization (#28)

* 22 changing tenant table to organization

* 22 results of "yarn rw g scaffold organization"

* bring back CRUD routes, display agency id in agency form

* feature/2228 update to named query in AgenciesCell

* enable edit and add agency pages, add reset functionality that clears form (Add new agency) or reverts it to the previous save (Edit), add form validation, styling, override default bootstrap invalid-feedback colors

* feature/2228 add red border around invalid fields when submitting the Agency form

* 22 changing tenant table to organization

* 22 fixing merge conflict when pulling in the parent branch 2228

* 22 adding .idea to gitignore and creating .nvmrc

* 22 styling updates to align with #2282

* feature/2228 fix misnamed Agency type in agencies.test.ts

* 22 changing tenant table to organization

* 22 rebasing onto 2228 before merging

* 22 results of "yarn rw g scaffold organization"

* 22 fixing merge conflict when pulling in the parent branch 2228

* 22 adding .idea to gitignore and creating .nvmrc

* 22 styling updates to align with #2282

---------

Co-authored-by: Ed Snodgrass <[email protected]>
Co-authored-by: Weronika Tomaszewska <[email protected]>

---------

Co-authored-by: Ed Snodgrass <[email protected]>
Co-authored-by: Ed Snodgrass <[email protected]>

* 13 linting fixes to merge to main

---------

Co-authored-by: Weronika Tomaszewska <[email protected]>
Co-authored-by: Ed Snodgrass <[email protected]>
Co-authored-by: Ed Snodgrass <[email protected]>
  • Loading branch information
4 people authored Dec 7, 2023
1 parent 8788378 commit fd49812
Show file tree
Hide file tree
Showing 56 changed files with 3,457 additions and 834 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Redwood
.redwood/*

# Logs
logs
*.log
Expand Down Expand Up @@ -124,6 +127,7 @@ dist

# yarn (see https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored)
.pnp.*
.idea
.yarn/*
!.yarn/patches
!.yarn/plugins
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18
v18.18.2
9 changes: 9 additions & 0 deletions api/db/migrations/20231128040217_basic_agency/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- CreateTable
CREATE TABLE "agency" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"abbreviation" TEXT,
"code" TEXT NOT NULL,

CONSTRAINT "agency_pkey" PRIMARY KEY ("id")
);
30 changes: 30 additions & 0 deletions api/db/migrations/20231201164202_added_tenant/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Warnings:
- You are about to drop the `agency` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropTable
DROP TABLE "agency";

-- CreateTable
CREATE TABLE "Agency" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"abbreviation" TEXT,
"code" TEXT NOT NULL,
"tenantId" INTEGER,

CONSTRAINT "Agency_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Tenant" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,

CONSTRAINT "Tenant_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "Agency" ADD CONSTRAINT "Agency_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Warnings:
- You are about to drop the column `tenantId` on the `Agency` table. All the data in the column will be lost.
- You are about to drop the `Tenant` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "Agency" DROP CONSTRAINT "Agency_tenantId_fkey";

-- AlterTable
ALTER TABLE "Agency" DROP COLUMN "tenantId",
ADD COLUMN "organizationId" INTEGER;

-- DropTable
DROP TABLE "Tenant";

-- CreateTable
CREATE TABLE "Organization" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,

CONSTRAINT "Organization_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "Agency" ADD CONSTRAINT "Agency_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE SET NULL ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions api/db/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
196 changes: 13 additions & 183 deletions api/db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,187 +8,17 @@ datasource db {
url = env("DATABASE_URL")
}

model access_tokens {
id Int @id @default(autoincrement())
user_id Int?
passcode String @unique(map: "access_tokens_passcode_unique") @db.VarChar(200)
created_at DateTime @default(now()) @db.Timestamptz(6)
expires DateTime @db.Timestamptz(6)
used Boolean
uses Int @default(0)
users users? @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "access_tokens_user_id_foreign")
}

model agencies {
id Int @id @default(autoincrement())
name String
abbreviation String? @db.VarChar(255)
parent Int?
warning_threshold Int? @default(30)
danger_threshold Int? @default(15)
main_agency_id Int
tenant_id Int
code String
agencies_agencies_main_agency_idToagencies agencies @relation("agencies_main_agency_idToagencies", fields: [main_agency_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "agencies_main_agency_id_foreign")
other_agencies_agencies_main_agency_idToagencies agencies[] @relation("agencies_main_agency_idToagencies")
agencies_agencies_parentToagencies agencies? @relation("agencies_parentToagencies", fields: [parent], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "agencies_parent_foreign")
other_agencies_agencies_parentToagencies agencies[] @relation("agencies_parentToagencies")
tenants_agencies_tenant_idTotenants tenants @relation("agencies_tenant_idTotenants", fields: [tenant_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "agencies_tenant_id_foreign")
projects projects[]
tenants_tenants_main_agency_idToagencies tenants[] @relation("tenants_main_agency_idToagencies")
uploads uploads[]
users users[]
@@unique([tenant_id, code], map: "agencies_tenant_id_code_unique")
@@unique([tenant_id, name], map: "agencies_tenant_id_name_unique")
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
model application_settings {
id Int @id @default(autoincrement())
title String?
current_reporting_period_id Int?
duns_number String?
validation_rule_tags String[]
tenant_id Int
reporting_periods reporting_periods? @relation(fields: [current_reporting_period_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "application_settings_current_reporting_period_id_foreign")
tenants tenants @relation(fields: [tenant_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "application_settings_tenant_id_foreign")
@@ignore
}

model arpa_subrecipients {
id Int @id @default(autoincrement())
tenant_id Int
created_at DateTime @default(now()) @db.Timestamptz(6)
updated_at DateTime? @db.Timestamptz(6)
updated_by Int?
uei String? @db.VarChar(255)
tin String? @db.VarChar(255)
record String?
upload_id String? @db.Uuid
tenants tenants @relation(fields: [tenant_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "arpa_subrecipients_tenant_id_foreign")
users users? @relation(fields: [updated_by], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "arpa_subrecipients_updated_by_foreign")
uploads uploads? @relation(fields: [upload_id], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "arpa_subrecipients_upload_id_foreign")
@@unique([tenant_id, tin], map: "arpa_subrecipients_tenant_id_tin_unique")
@@unique([tenant_id, uei], map: "arpa_subrecipients_tenant_id_uei_unique")
}

model period_summaries {
id Int @id @default(autoincrement())
reporting_period_id Int
project_code String
award_type String
award_number String
current_obligation Decimal @db.Decimal(19, 2)
current_expenditure Decimal @db.Decimal(19, 2)
award_amount Decimal? @db.Decimal(19, 2)
tenant_id Int
reporting_periods reporting_periods @relation(fields: [reporting_period_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "period_summaries_reporting_period_id_foreign")
tenants tenants @relation(fields: [tenant_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "period_summaries_tenant_id_foreign")
projects projects @relation(fields: [tenant_id, project_code], references: [tenant_id, code], onDelete: NoAction, onUpdate: NoAction, map: "period_summaries_tenant_id_project_code_foreign")
}

model projects {
id Int @id @default(autoincrement())
code String
name String
agency_id Int?
status String?
description String?
created_at DateTime @default(now()) @db.Timestamptz(6)
created_by String?
updated_at DateTime? @db.Timestamptz(6)
updated_by String?
created_in_period Int?
tenant_id Int
period_summaries period_summaries[]
agencies agencies? @relation(fields: [agency_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "projects_agency_id_foreign")
reporting_periods reporting_periods? @relation(fields: [created_in_period], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "projects_created_in_period_foreign")
tenants tenants @relation(fields: [tenant_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "projects_tenant_id_foreign")
@@unique([tenant_id, code], map: "projects_tenant_id_code_unique")
@@unique([tenant_id, name], map: "projects_tenant_id_name_unique")
}

model reporting_periods {
id Int @id @default(autoincrement())
name String
start_date DateTime @db.Date
end_date DateTime @db.Date
certified_at DateTime? @db.Timestamptz(6)
certified_by Int?
tenant_id Int
template_filename String? @db.VarChar(255)
application_settings application_settings[] @ignore
period_summaries period_summaries[]
projects projects[]
users users? @relation(fields: [certified_by], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "reporting_periods_certified_by_foreign")
tenants tenants @relation(fields: [tenant_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "reporting_periods_tenant_id_foreign")
uploads uploads[]
@@unique([tenant_id, name], map: "reporting_periods_tenant_id_name_unique")
}

model roles {
id Int @id @default(autoincrement())
name String @unique(map: "roles_name_unique") @db.VarChar(255)
rules Json @db.Json
created_at DateTime @default(now()) @db.Timestamptz(6)
users users[]
}

model tenants {
id Int @id @default(autoincrement())
display_name String? @db.VarChar(255)
main_agency_id Int?
created_at DateTime @default(now()) @db.Timestamptz(6)
updated_at DateTime? @db.Timestamptz(6)
agencies_agencies_tenant_idTotenants agencies[] @relation("agencies_tenant_idTotenants")
application_settings application_settings[] @ignore
arpa_subrecipients arpa_subrecipients[]
period_summaries period_summaries[]
projects projects[]
reporting_periods reporting_periods[]
agencies_tenants_main_agency_idToagencies agencies? @relation("tenants_main_agency_idToagencies", fields: [main_agency_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "tenants_main_agency_id_foreign")
uploads uploads[]
users users[]
}

model uploads {
filename String
created_at DateTime @default(now()) @db.Timestamptz(6)
reporting_period_id Int?
user_id Int?
agency_id Int?
validated_at DateTime? @db.Timestamptz(6)
validated_by Int?
ec_code String? @db.VarChar(255)
tenant_id Int
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
arpa_subrecipients arpa_subrecipients[]
agencies agencies? @relation(fields: [agency_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "uploads_agency_id_foreign")
reporting_periods reporting_periods? @relation(fields: [reporting_period_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "uploads_reporting_period_id_foreign")
tenants tenants @relation(fields: [tenant_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "uploads_tenant_id_foreign")
users_uploads_user_idTousers users? @relation("uploads_user_idTousers", fields: [user_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "uploads_user_id_foreign")
users_uploads_validated_byTousers users? @relation("uploads_validated_byTousers", fields: [validated_by], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "uploads_validated_by_foreign")
}

model users {
id Int @id @default(autoincrement())
email String @unique(map: "users_email_unique") @db.VarChar(255)
name String? @db.VarChar(255)
role_id Int?
created_at DateTime @default(now()) @db.Timestamptz(6)
agency_id Int?
tenant_id Int
access_tokens access_tokens[]
arpa_subrecipients arpa_subrecipients[]
reporting_periods reporting_periods[]
uploads_uploads_user_idTousers uploads[] @relation("uploads_user_idTousers")
uploads_uploads_validated_byTousers uploads[] @relation("uploads_validated_byTousers")
agencies agencies? @relation(fields: [agency_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "users_agency_id_foreign")
roles roles? @relation(fields: [role_id], references: [id], onUpdate: NoAction, map: "users_role_id_foreign")
tenants tenants @relation(fields: [tenant_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "users_tenant_id_foreign")
model Agency {
id Int @id @default(autoincrement())
name String
abbreviation String?
code String
tenant Organization? @relation(fields: [organizationId], references: [id])
organizationId Int?
}

model Organization {
id Int @id @default(autoincrement())
agencies Agency[]
name String
}
33 changes: 33 additions & 0 deletions api/src/graphql/agencies.sdl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export const schema = gql`
type Agency {
id: Int!
name: String!
abbreviation: String
code: String!
organizationId: Int!
}
type Query {
agencies: [Agency!]! @requireAuth
agency(id: Int!): Agency @requireAuth
agenciesByOrganization(organizationId: Int!): [Agency!]! @requireAuth
}
input CreateAgencyInput {
name: String!
abbreviation: String
code: String!
}
input UpdateAgencyInput {
name: String
abbreviation: String
code: String
}
type Mutation {
createAgency(input: CreateAgencyInput!): Agency! @requireAuth
updateAgency(id: Int!, input: UpdateAgencyInput!): Agency! @requireAuth
deleteAgency(id: Int!): Agency! @requireAuth
}
`
30 changes: 30 additions & 0 deletions api/src/graphql/organizations.sdl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const schema = gql`
type Organization {
id: Int!
agencies: [Agency]!
name: String!
}
type Query {
organizations: [Organization!]! @requireAuth
organization(id: Int!): Organization @requireAuth
}
input CreateOrganizationInput {
name: String!
}
input UpdateOrganizationInput {
name: String
}
type Mutation {
createOrganization(input: CreateOrganizationInput!): Organization!
@requireAuth
updateOrganization(
id: Int!
input: UpdateOrganizationInput!
): Organization! @requireAuth
deleteOrganization(id: Int!): Organization! @requireAuth
}
`
11 changes: 11 additions & 0 deletions api/src/services/agencies/agencies.scenarios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Prisma, agency } from '@prisma/client'
import type { ScenarioData } from '@redwoodjs/testing/api'

export const standard = defineScenario<Prisma.agencyCreateArgs>({
agency: {
one: { data: { name: 'String', code: 'String' } },
two: { data: { name: 'String', code: 'String' } },
},
})

export type StandardScenario = ScenarioData<agency, 'agency'>
Loading

0 comments on commit fd49812

Please sign in to comment.