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: isId in option.properties does not work #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions example-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
"concurrently": "^5.2.0",
"dotenv-cli": "^4.0.0",
"nodemon": "^2.0.4",
"prisma": "^3.2.1",
"prisma": "^4.5.0",
"ts-node": "3.3.0",
"typescript": "^4.4.4"
},
"dependencies": {
"@adminjs/express": "^4.0.0",
"@adminjs/prisma": "^1.0.0",
"@prisma/client": "^3.2.1",
"adminjs": "^5.0.0",
"@prisma/client": "^4.5.0",
"adminjs": "^6.6.1",
"express": "^4.17.1",
"express-formidable": "^1.2.0",
"express-session": "^1.17.1",
Expand Down
9 changes: 5 additions & 4 deletions example-app/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ model Post {
someJson Json? @db.JsonB
status Status @default(ACTIVE)
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
author User @relation(fields: [authorId], references: [userId])
authorId String
}

model Profile {
id Int @id @default(autoincrement())
bio String?
user User @relation(fields: [userId], references: [id])
userId Int @unique
user User @relation(fields: [userId], references: [userId])
userId String @unique
}

model User {
id Int @id @default(autoincrement())
userId String @unique @default(uuid())
email String @unique
name String?
posts Post[]
Expand Down
2 changes: 1 addition & 1 deletion example-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const run = async () => {
resource: { model: dmmf.modelMap.Profile, client: prisma },
options: {},
}, {
resource: { model: dmmf.modelMap.User, client: prisma },
resource: { model: dmmf.modelMap.User, client: prisma, key: 'userId' },
options: {},
}],
});
Expand Down
3,333 changes: 1,857 additions & 1,476 deletions example-app/yarn.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"author": "Rafał Dzięgielewski <[email protected]>",
"license": "MIT",
"peerDependencies": {
"@prisma/client": "^4.0.0",
"@prisma/client": "^4.5.0",
"adminjs": ">=6.0.0"
},
"prisma": {
Expand All @@ -44,13 +44,13 @@
"devDependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@prisma/client": "^4.0.0",
"@prisma/client": "^4.5.0",
"@semantic-release/git": "^9.0.0",
"@types/jest": "^27.0.2",
"@types/node": "12.0.10",
"@typescript-eslint/eslint-plugin": "^3.7.0",
"@typescript-eslint/parser": "^3.7.0",
"adminjs": "^6.0.0",
"adminjs": "^6.6.1",
"dotenv-cli": "^4.0.0",
"eslint": "^7.5.0",
"eslint-config-airbnb": "^18.2.0",
Expand All @@ -61,7 +61,7 @@
"husky": "^4.2.5",
"jest": "^27.2.5",
"pg": "^7.12.1",
"prisma": "^4.0.0",
"prisma": "^4.5.0",
"semantic-release": "^17.0.7",
"semantic-release-slack-bot": "^1.6.2",
"ts-jest": "^27.0.5",
Expand Down
8 changes: 2 additions & 6 deletions src/Property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export class Property extends BaseProperty {

private columnPosition: number;

constructor(column: DMMF.Field, columnPosition = 0, enums: Enums) {
constructor(column: DMMF.Field, columnPosition = 0, enums: Enums, isId: boolean) {
const path = column.name;
super({ path });
super({ path, isId });
this.column = column;
this.enums = enums;
this.columnPosition = columnPosition;
Expand All @@ -23,10 +23,6 @@ export class Property extends BaseProperty {
return !this.isId() && this.column.name !== 'createdAt' && this.column.name !== 'updatedAt';
}

public isId(): boolean {
return !!this.column.isId;
}

public name(): string {
return this.column.name;
}
Expand Down
9 changes: 6 additions & 3 deletions src/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ export class Resource extends BaseResource {

private model: DMMF.Model;

private key?: string;

private enums: Enums;

private manager: ModelManager;

private propertiesObject: Record<string, any>;

constructor(args: { model: DMMF.Model, client: PrismaClient }) {
constructor(args: { model: DMMF.Model, client: PrismaClient, key?: string }) {
super(args);

const { model, client } = args;
const { model, client, key } = args;
this.model = model;
this.client = client;
this.key = key;
this.enums = (this.client as any)._baseDmmf.datamodelEnumMap;
this.manager = this.client[lowerCase(model.name)];
this.propertiesObject = this.prepareProperties();
Expand Down Expand Up @@ -154,7 +157,7 @@ export class Resource extends BaseResource {
return memo;
}

const property = new Property(field, Object.keys(memo).length, this.enums);
const property = new Property(field, Object.keys(memo).length, this.enums, this.key ? field.name === this.key : !!field.isId);
memo[property.path()] = property;

return memo;
Expand Down
Loading