Skip to content

Commit

Permalink
chore: implemented auto-generation of prisma types
Browse files Browse the repository at this point in the history
  • Loading branch information
gearonix committed Aug 9, 2023
1 parent ec82af2 commit bb9fe45
Show file tree
Hide file tree
Showing 6 changed files with 817 additions and 129 deletions.
2 changes: 1 addition & 1 deletion apps/server/prisma/models/users.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Users model

model users {
model User {
username String @id @database.VarChar(14)
password String @database.VarChar(150)
avatarUrl String? @database.VarChar(100)
Expand Down
47 changes: 35 additions & 12 deletions apps/server/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,41 @@
"sourceRoot": "apps/server/src",
"projectType": "application",
"targets": {
"prisma:generate": {
"command": "npx prisma generate",
"options": {
"cwd": "apps/server"
}
},
"concat-prisma-files": {
"command": "node prisma/concat-prisma-files.js",
"options": {
"cwd": "apps/server"
}
},
"migrate:dev": {
"command": "npx prisma migrate dev",
"options": {
"cwd": "apps/server",
"envFile": ".serve.env"
},
"dependsOn": ["concat-prisma-files"]
},
"migrate:prod": {
"command": "npx prisma migrate deploy",
"options": {
"cwd": "apps/server",
"envFile": ".build.env"
},
"dependsOn": ["concat-prisma-files"]
},
"generate-prisma-types": {
"command": "npx @kalissaac/prisma-typegen ./src/common/types/_prisma.ts ./prisma/schema.prisma",
"options": {
"cwd": "apps/server"
},
"dependsOn": ["migrate:dev"]
},
"build": {
"executor": "@nx/webpack:webpack",
"outputs": ["{options.outputPath}"],
Expand Down Expand Up @@ -61,18 +96,6 @@
"codeCoverage": true
}
}
},
"migrate:dev": {
"command": "node prisma/concat-prisma-files.js && dotenv -e ../../.serve.env -- npx prisma migrate dev",
"options": {
"cwd": "apps/server"
}
},
"migrate:prod": {
"command": "node prisma/concat-prisma-files.js && dotenv -e ../../.build.env -- npx prisma migrate deploy",
"options": {
"cwd": "apps/server"
}
}
},
"tags": []
Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/auth/responses/user.response.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { User } from '@/common/types/_prisma'
import { Field, ObjectType } from '@nestjs/graphql'
import { ApiProperty } from '@nestjs/swagger'

@ObjectType()
export class UserResponse {
export class UserResponse implements Omit<User, 'password'> {
@Field()
@ApiProperty({ description: 'Username (used as userId)' })
username: string
Expand Down
8 changes: 8 additions & 0 deletions apps/server/src/common/types/_prisma.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// AUTO GENERATED FILE BY @kalissaac/prisma-typegen
// DO NOT EDIT

export interface User {
username: string
password: string
avatarUrl?: string
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"@code-gear/config": "workspace:*",
"@commitlint/cli": "^17.7.0",
"@commitlint/config-conventional": "^17.7.0",
"@kalissaac/prisma-typegen": "^0.0.7",
"@nestjs/schematics": "^10.0.1",
"@nestjs/testing": "^10.0.2",
"@nx/cypress": "16.4.0",
Expand Down
Loading

0 comments on commit bb9fe45

Please sign in to comment.