-
Notifications
You must be signed in to change notification settings - Fork 5
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
CPF-101 Update createUser() mutation resolver #112
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0985d8f
CPF-103 remove validated, invalidated and subrecipients relations fro…
Vikariusu 76f6d57
CPF-103 update seed script to include 1 test organization, 1 agency a…
Vikariusu a39b3d0
CPF-103 remove organizationId from api inputs
Vikariusu 132a77e
CPF-103 fix tests to include required fields for User model
Vikariusu 20be4e6
CPF-103 add 'unique' field attribute to user email
Vikariusu 31dfe0d
CPF-103 use unique emails for testing
Vikariusu f6e18c5
CPF-101 update CreateUserInput fields to be required, use Redwood ser…
Vikariusu 9e5bdb4
CPF-101 don't check if logged in user has the same organization as th…
Vikariusu 763a5f3
CPF-101 eslint fixes
Vikariusu ec1c0f0
resolve merge conflicts
Vikariusu 8077128
Merge remote-tracking branch 'origin' into feature/CPF-101-update-cre…
Vikariusu 7fac4fe
bring back .vscode/settings.json
Vikariusu 017b498
Merge branch 'main' into feature/CPF-101-update-create-user-mutation
as1729 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
43 changes: 43 additions & 0 deletions
43
...db/migrations/20240214193745_remove_user_validation_subrecipients_relations/migration.sql
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,43 @@ | ||
/* | ||
Warnings: | ||
|
||
- You are about to drop the column `certifiedById` on the `Subrecipient` table. All the data in the column will be lost. | ||
- You are about to drop the column `invalidatedById` on the `UploadValidation` table. All the data in the column will be lost. | ||
- You are about to drop the column `validatedById` on the `UploadValidation` table. All the data in the column will be lost. | ||
- You are about to drop the column `organizationId` on the `User` table. All the data in the column will be lost. | ||
- Made the column `name` on table `User` required. This step will fail if there are existing NULL values in that column. | ||
- Made the column `agencyId` on table `User` required. This step will fail if there are existing NULL values in that column. | ||
- Made the column `role` on table `User` required. This step will fail if there are existing NULL values in that column. | ||
|
||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "Subrecipient" DROP CONSTRAINT "Subrecipient_certifiedById_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "UploadValidation" DROP CONSTRAINT "UploadValidation_invalidatedById_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "UploadValidation" DROP CONSTRAINT "UploadValidation_validatedById_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "User" DROP CONSTRAINT "User_agencyId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "User" DROP CONSTRAINT "User_organizationId_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Subrecipient" DROP COLUMN "certifiedById"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "UploadValidation" DROP COLUMN "invalidatedById", | ||
DROP COLUMN "validatedById"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "User" DROP COLUMN "organizationId", | ||
ADD COLUMN "isActive" BOOLEAN NOT NULL DEFAULT true, | ||
ALTER COLUMN "name" SET NOT NULL, | ||
ALTER COLUMN "agencyId" SET NOT NULL, | ||
ALTER COLUMN "role" SET NOT NULL; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "User" ADD CONSTRAINT "User_agencyId_fkey" FOREIGN KEY ("agencyId") REFERENCES "Agency"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
8 changes: 8 additions & 0 deletions
8
api/db/migrations/20240216211114_make_user_email_unique/migration.sql
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,8 @@ | ||
/* | ||
Warnings: | ||
|
||
- A unique constraint covering the columns `[email]` on the table `User` will be added. If there are existing duplicate values, this will fail. | ||
|
||
*/ | ||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,8 @@ export const getCurrentUser = async ( | |
console.log(decoded) | ||
return { | ||
id: 1, | ||
organizationId: 1, | ||
organizationId: 1, // TODO: Organization id should be determined via the agency relationship | ||
agencyId: 1, | ||
email: '[email protected]', | ||
roles: ['USDR_ADMIN'], | ||
} | ||
|
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 |
---|---|---|
|
@@ -17,9 +17,11 @@ export const standard = defineScenario<Prisma.SubrecipientCreateArgs>({ | |
updatedAt: '2023-12-09T14:50:18.317Z', | ||
uploadedBy: { | ||
create: { | ||
email: 'String', | ||
name: 'String', | ||
email: '[email protected]', | ||
updatedAt: '2023-12-09T14:50:18.317Z', | ||
organization: { create: { name: 'String' } }, | ||
agency: { create: { name: 'String', code: 'String' } }, | ||
role: 'USDR_ADMIN', | ||
}, | ||
}, | ||
agency: { create: { name: 'String', code: 'String' } }, | ||
|
@@ -73,9 +75,11 @@ export const standard = defineScenario<Prisma.SubrecipientCreateArgs>({ | |
updatedAt: '2023-12-09T14:50:18.317Z', | ||
uploadedBy: { | ||
create: { | ||
email: 'String', | ||
name: 'String', | ||
email: '[email protected]', | ||
updatedAt: '2023-12-09T14:50:18.317Z', | ||
organization: { create: { name: 'String' } }, | ||
agency: { create: { name: 'String', code: 'String' } }, | ||
role: 'USDR_ADMIN', | ||
}, | ||
}, | ||
agency: { create: { name: 'String', code: 'String' } }, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,14 @@ export const standard = defineScenario<Prisma.UploadCreateArgs>({ | |
one: { | ||
data: { | ||
filename: 'String', | ||
uploadedBy: { create: { email: 'String' } }, | ||
uploadedBy: { | ||
create: { | ||
email: '[email protected]', | ||
name: 'String', | ||
role: 'USDR_ADMIN', | ||
agency: { create: { name: 'String', code: 'String' } }, | ||
}, | ||
}, | ||
agency: { create: { name: 'String', code: 'String' } }, | ||
organization: { create: { name: 'String' } }, | ||
reportingPeriod: { | ||
|
@@ -37,7 +44,14 @@ export const standard = defineScenario<Prisma.UploadCreateArgs>({ | |
two: { | ||
data: { | ||
filename: 'String', | ||
uploadedBy: { create: { email: 'String' } }, | ||
uploadedBy: { | ||
create: { | ||
email: '[email protected]', | ||
name: 'String', | ||
role: 'USDR_ADMIN', | ||
agency: { create: { name: 'String', code: 'String' } }, | ||
}, | ||
}, | ||
agency: { create: { name: 'String', code: 'String' } }, | ||
organization: { create: { name: 'String' } }, | ||
reportingPeriod: { | ||
|
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 |
---|---|---|
|
@@ -26,9 +26,8 @@ export const standard = defineScenario< | |
user: { | ||
one: { | ||
data: { | ||
email: 'String', | ||
email: '[email protected]', | ||
name: 'String', | ||
organization: { create: { name: 'String' } }, | ||
agency: { create: { name: 'String', code: 'String' } }, | ||
role: 'ORGANIZATION_ADMIN', | ||
}, | ||
|
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 |
---|---|---|
|
@@ -25,22 +25,20 @@ describe('users', () => { | |
scenario('creates a user', async (scenario: StandardScenario) => { | ||
mockCurrentUser({ | ||
id: scenario.user.one.id, | ||
organizationId: scenario.user.one.organizationId, | ||
email: '[email protected]', | ||
email: scenario.user.one.email, | ||
roles: ['USDR_ADMIN'], | ||
}) | ||
|
||
const result = await createUser({ | ||
input: { | ||
name: scenario.user.one.name, | ||
email: scenario.user.one.email, | ||
email: '[email protected]', | ||
name: 'String', | ||
agencyId: scenario.agency.one.id, | ||
role: 'ORGANIZATION_STAFF', | ||
role: 'USDR_ADMIN', | ||
}, | ||
}) | ||
|
||
expect(result.email).toEqual(scenario.user.one.email) | ||
expect(result.organizationId).toEqual(scenario.organization.one.id) | ||
expect(result.email).toEqual('[email protected]') | ||
}) | ||
|
||
scenario('updates a user', async (scenario: StandardScenario) => { | ||
|
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.
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.
According to the ticket's requirement
isActive
field onCreateUserInput
should be required. However, this means that we either need to passisActive: true
from the frontend (currently the form for creating users doesn't have this field), or make this field optional onCreateUserInput
, allowingschema.prisma
to set it to true by default.If we would rather set it on the frontend, I can make this change.