-
Notifications
You must be signed in to change notification settings - Fork 236
Add public key schema to prisma #785
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1a1926a
Add public key schema
biscuitdey 8e3b962
Add public key domain model
biscuitdey c3107f4
Add public key to bpiStorageAgent
biscuitdey a72ba5c
Merge branch 'main' of https://github.com/eea-oasis/baseline into fea…
biscuitdey 6ccfa84
Add keyType enum to prisma schema
biscuitdey 3fbc6b4
Create migration for keyType enum in prisma schema
biscuitdey b8aed6a
Update publicKey keyType
biscuitdey 02d922d
Search BPI subject by publicKey
biscuitdey 7e865fc
Update bpiSubject search query
biscuitdey c52dd44
Change publicKey to publicKeys
biscuitdey f36f827
Change publicKey to publicKeys
biscuitdey cc5c1c9
Change keyType to publicKeyType
biscuitdey 6f84d1e
Update publicKeys in bpiSubject
biscuitdey 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
27 changes: 27 additions & 0 deletions
27
examples/bri-3/prisma/migrations/20240124083845_add_public_key_to_bpi_subject/migration.sql
This file contains hidden or 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,27 @@ | ||
/* | ||
Warnings: | ||
|
||
- You are about to drop the column `publicKey` on the `BpiSubject` table. All the data in the column will be lost. | ||
|
||
*/ | ||
-- AlterTable | ||
ALTER TABLE "BpiSubject" DROP COLUMN "publicKey"; | ||
|
||
-- CreateTable | ||
CREATE TABLE "PublicKey" ( | ||
"id" TEXT NOT NULL, | ||
"type" TEXT NOT NULL, | ||
"value" TEXT NOT NULL, | ||
"bpiSubjectId" TEXT NOT NULL, | ||
biscuitdey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
CONSTRAINT "PublicKey_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "PublicKey_value_key" ON "PublicKey"("value"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "PublicKey_type_bpiSubjectId_key" ON "PublicKey"("type", "bpiSubjectId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "PublicKey" ADD CONSTRAINT "PublicKey_bpiSubjectId_fkey" FOREIGN KEY ("bpiSubjectId") REFERENCES "BpiSubject"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains hidden or 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 |
---|---|---|
@@ -1,37 +1,56 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { BpiSubject as BpiSubjectPrismaModel, BpiSubjectRole as BpiSubjectRolePrismaModel } from '@prisma/client'; | ||
import { | ||
BpiSubject as BpiSubjectPrismaModel, | ||
BpiSubjectRole as BpiSubjectRolePrismaModel, | ||
PublicKey as PublicKeyPrismaModel, | ||
} from '@prisma/client'; | ||
import { BpiSubject } from '../src/bri/identity/bpiSubjects/models/bpiSubject'; | ||
import { BpiSubjectRole } from '../src/bri/identity/bpiSubjects/models/bpiSubjectRole'; | ||
import { PublicKey } from '../src/bri/identity/bpiSubjects/models/publicKey'; | ||
|
||
// We do mapping from prisma models to domain objects using simple Object.assign | ||
// since automapper is not happy working with types, which is how Prisma generates database entities. | ||
// For these mappings to work, the convention is that the domain objects have the same properties as the | ||
// prisma models. In case there is a need to do something custom during mapping, it can be implemented | ||
// in the appropriate method below. | ||
// prisma models. In case there is a need to do something custom during mapping, it can be implemented | ||
// in the appropriate method below. | ||
|
||
interface IConstructor<T> { | ||
new (...args: any[]): T; | ||
new (...args: any[]): T; | ||
} | ||
|
||
@Injectable() | ||
export class PrismaMapper { | ||
public mapBpiSubjectPrismaModelToDomainObject(source: BpiSubjectPrismaModel): BpiSubject { | ||
const target = this.activator(BpiSubject); | ||
public mapBpiSubjectPrismaModelToDomainObject( | ||
biscuitdey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
source: BpiSubjectPrismaModel, | ||
): BpiSubject { | ||
const target = this.activator(BpiSubject); | ||
|
||
Object.assign(target, source); | ||
Object.assign(target, source); | ||
|
||
return target; | ||
} | ||
return target; | ||
} | ||
|
||
public mapBpiSubjectRolePrismaModelToDomainObject(source: BpiSubjectRolePrismaModel): BpiSubjectRole { | ||
const target = this.activator(BpiSubjectRole); | ||
public mapBpiSubjectRolePrismaModelToDomainObject( | ||
source: BpiSubjectRolePrismaModel, | ||
): BpiSubjectRole { | ||
const target = this.activator(BpiSubjectRole); | ||
|
||
Object.assign(target, source); | ||
Object.assign(target, source); | ||
|
||
return target; | ||
} | ||
return target; | ||
} | ||
|
||
private activator<T>(type: IConstructor<T>): T { | ||
return new type(); | ||
} | ||
} | ||
public mapPublicKeyPrismaModelToDomainObject( | ||
source: PublicKeyPrismaModel, | ||
): PublicKey { | ||
const target = this.activator(PublicKey); | ||
|
||
Object.assign(target, source); | ||
|
||
return target; | ||
} | ||
|
||
private activator<T>(type: IConstructor<T>): T { | ||
return new type(); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
38 changes: 38 additions & 0 deletions
38
examples/bri-3/src/bri/identity/bpiSubjects/models/publicKey.ts
This file contains hidden or 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,38 @@ | ||
import { AutoMap } from '@automapper/classes'; | ||
import { BpiSubject } from './bpiSubject'; | ||
|
||
export class PublicKey { | ||
@AutoMap() | ||
id: string; | ||
|
||
@AutoMap() | ||
type: string; | ||
|
||
@AutoMap() | ||
value: string; | ||
|
||
@AutoMap() | ||
bpiSubjectId: string; | ||
|
||
@AutoMap() | ||
bpiSubject: BpiSubject; | ||
|
||
constructor(id: string, type: string, value: string, bpiSubjectId: string) { | ||
this.id = id; | ||
this.type = type; | ||
this.value = value; | ||
this.bpiSubjectId = bpiSubjectId; | ||
} | ||
|
||
public updateType(newType: string): void { | ||
this.type = newType; | ||
} | ||
|
||
public updateValue(newValue: string): void { | ||
this.value = newValue; | ||
} | ||
|
||
public updateBpiSubjectId(newBpiSubjectId: string): void { | ||
this.bpiSubjectId = newBpiSubjectId; | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.