fix(Generator): 🐛 Fix the issue with mapping default values in the generated Prisma classes.#77
Open
dshk0718 wants to merge 22 commits into
Open
fix(Generator): 🐛 Fix the issue with mapping default values in the generated Prisma classes.#77dshk0718 wants to merge 22 commits into
dshk0718 wants to merge 22 commits into
Conversation
removed step npm test
added tsc
…d fields incorrectly being assigned to a date object like `new Date('1')` for `Int` fields (if the default value was 1 in this case) or not being assigned at all.
Update the PostgreSQL Prisma schema for testing the default values.
Reformat the changed files.
Author
|
@kimjbstar import { Category } from './category'
import { Company } from './company'
import { ProductType, ProductAnotherType } from '@prisma/client'
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
export class Product {
@ApiProperty({ type: Number })
id: number
@ApiProperty({ type: String })
title: string
@ApiProperty({ type: String })
desc: string = 'abc'
@ApiProperty({ type: Object })
images: object
@ApiPropertyOptional({ type: Boolean })
isShown?: boolean = false
@ApiProperty({ type: Number })
stock: number = 0
@ApiProperty({ enum: ProductType, enumName: 'ProductType' })
type: ProductType
@ApiProperty({ enum: ProductAnotherType, enumName: 'ProductAnotherType' })
anotherType: ProductAnotherType = ProductAnotherType.AA
@ApiPropertyOptional({ type: Number })
averageRating?: number
@ApiProperty({ type: Number })
categoryId: number
@ApiProperty({ type: Number })
companyId: number
@ApiProperty({ type: () => Category })
category: Category
@ApiProperty({ type: () => Company })
company: Company
@ApiProperty({ type: Date })
releasedAt: Date = new Date('2024-01-01T00:00:00+00:00')
@ApiProperty({ type: Date })
createdAt: Date = new Date()
@ApiProperty({ type: Date })
updatedAt: Date = new Date()
}As you can see, all the issues that were mentioned in #34, #56, #68, and #76 are fixed with the fixes I am proposing to push. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR Changes Summary
Fix the issue with the default values for the mapped fields incorrectly being assigned to a date object like
new Date('1')forIntfields (if the default value was 1 in this case) or not being assigned at all.Fixes
Inttype in the Prisma schema would get generated asnew Date('1')(in the case the default value was set to1in the Prisma schema for the given field).Inttype with@default(1)#76Proposed Changes
releasedAtto theProductmodel in the PostgreSQL Prisma schema for testing date fields with a fixed date-time value (not using Prisma@default(now())directive or Prisma@updatedAtdirective).undefinedornull, instead of just checking on the truthiness of the default value. Checking only for the truthiness of the default value was causing the default value of0for theInttype fields not to get assigned the default value of0in the generated class.@updatedAtdirective.한국어 번역본
PR 변경 줄거리
매핑된 필드의 기본값이
Int필드의new Date('1')과 (기본값이1인 경우) 같은 날짜 객체에 잘못 할당되었거나 전혀 할당되지 않은 문제를 해결합니다.해결하는 문제 점들
Int유형을 가진 필드의 기본값이new Date('1')로 (기본값이1로 설정된 경우) 할당되는 문제.Inttype with@default(1)#76제안된 변경 사항
@default(now())지시문이나@updatedAt지시문으로 설정되지 않은 경우) 매핑을 테스트하기 위해 PostgreSQL Prisma 스키마의Product모델에 새로운 날짜 필드releaseAt을 추가합니다.undefined또는null이 아닌지 확인하도록 조건 수정을 수행합니다. 기본값의 진실성만 체크하는 경우에는0과 같은 값이 생성된 Prisma 클래스에 할당되지 않습니다.@updatedAt지시문으로 설정된 필드의 기본값이 생성된 Prisma 클래스에서 할당이 되도록 논리를 더합니다.