From 3316b9c267361e2392a2b171123986611027d8be Mon Sep 17 00:00:00 2001 From: scarf Date: Sat, 8 Jul 2023 21:27:50 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20nullable=EC=9D=B4=20=EC=95=84=EB=8B=8C?= =?UTF-8?q?=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=ED=95=84=EB=93=9C=EB=A5=BC=20?= =?UTF-8?q?=ED=95=84=EC=88=98=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/books/books.repository.ts | 54 +++++++++++++------------ backend/src/books/books.type.ts | 2 +- backend/src/entity/entities/Book.ts | 4 +- backend/src/entity/entities/BookInfo.ts | 26 ++++++------ 4 files changed, 45 insertions(+), 41 deletions(-) diff --git a/backend/src/books/books.repository.ts b/backend/src/books/books.repository.ts index 8fb90b03..c1437ac3 100644 --- a/backend/src/books/books.repository.ts +++ b/backend/src/books/books.repository.ts @@ -147,40 +147,44 @@ class BooksRepository extends Repository { .getRawOne(); } - async updateBookInfo(bookInfo: UpdateBookInfo): Promise { - await this.bookInfo.update(bookInfo.id, bookInfo as BookInfo); + async updateBookInfo({ + id, categoryId, ...rest + }: UpdateBookInfo): Promise { + await this.bookInfo.update(id, { + id, + categoryId: Number(categoryId), + ...rest, + }); } async updateBook(book: UpdateBook): Promise { await this.books.update(book.id, book as Book); } - async createBookInfo( - target: CreateBookInfo, - ): Promise { - const bookInfo: BookInfo = { - title: target.title, - author: target.author, - publisher: target.publisher, - publishedAt: target.pubdate, - categoryId: Number(target.categoryId), - isbn: target.isbn, - image: target.image, - }; - return this.bookInfo.save(bookInfo); + async createBookInfo({ + title, author, publisher, pubdate, categoryId, isbn, image, + }: CreateBookInfo): Promise { + return this.bookInfo.save({ + title, + author, + publisher, + publishedAt: pubdate, + categoryId: Number(categoryId), + isbn, + image, + }); } - async createBook( - target: CreateBookInfo, - ): Promise { - const book: Book = { - donator: target.donator, - donatorId: target.donatorId, - callSign: target.callSign, + async createBook({ + donator, donatorId, callSign, infoId, + }: CreateBookInfo): Promise { + await this.books.save({ + donator, + donatorId, + callSign, + infoId, status: 0, - infoId: target.infoId, - }; - await this.books.save(book); + }); } } diff --git a/backend/src/books/books.type.ts b/backend/src/books/books.type.ts index 91b4dd1d..40edabca 100644 --- a/backend/src/books/books.type.ts +++ b/backend/src/books/books.type.ts @@ -42,7 +42,7 @@ export type UpdateBookInfo = { title: string; author: string; publisher: string; - publishedAt: string | Date; + publishedAt: string; image: string; categoryId?: string; } diff --git a/backend/src/entity/entities/Book.ts b/backend/src/entity/entities/Book.ts index f1856249..75629537 100644 --- a/backend/src/entity/entities/Book.ts +++ b/backend/src/entity/entities/Book.ts @@ -11,7 +11,7 @@ import Reservation from './Reservation'; class Book { @PrimaryGeneratedColumn({ type: 'int', name: 'id' }) - id?: number; + id: number; @Column('varchar', { name: 'donator', nullable: true, length: 255 }) donator: string | null; @@ -26,7 +26,7 @@ class Book { name: 'createdAt', default: () => "'CURRENT_TIMESTAMP(6)'", }) - createdAt?: Date; + createdAt: Date; @Column() infoId: number; diff --git a/backend/src/entity/entities/BookInfo.ts b/backend/src/entity/entities/BookInfo.ts index 85d92480..2ee488d4 100644 --- a/backend/src/entity/entities/BookInfo.ts +++ b/backend/src/entity/entities/BookInfo.ts @@ -12,16 +12,16 @@ import SuperTag from './SuperTag'; @Entity('book_info') class BookInfo { @PrimaryGeneratedColumn({ type: 'int', name: 'id' }) - id?: number; + id: number; @Column('varchar', { name: 'title', length: 255 }) - title?: string; + title: string; @Column('varchar', { name: 'author', length: 255 }) - author?: string; + author: string; @Column('varchar', { name: 'publisher', length: 255 }) - publisher?: string; + publisher: string; @Column('varchar', { name: 'isbn', nullable: true, length: 255 }) isbn?: string | null; @@ -36,38 +36,38 @@ class BookInfo { name: 'createdAt', default: () => "'CURRENT_TIMESTAMP(6)'", }) - createdAt?: Date; + createdAt: Date; @Column('datetime', { name: 'updatedAt', default: () => "'CURRENT_TIMESTAMP(6)'", }) - updatedAt?: Date; + updatedAt: Date; @Column('int', { name: 'categoryId' }) - categoryId?: number; + categoryId: number; @OneToMany(() => Book, (book) => book.info) - books?: Book[]; + books: Book[]; @ManyToOne(() => Category, (category) => category.bookInfos, { onDelete: 'NO ACTION', onUpdate: 'NO ACTION', }) @JoinColumn([{ name: 'categoryId', referencedColumnName: 'id' }]) - category?: Category; + category: Category; @OneToMany(() => Likes, (likes) => likes.bookInfo) - likes?: Likes[]; + likes: Likes[]; @OneToMany(() => Reservation, (reservation) => reservation.bookInfo) - reservations?: Reservation[]; + reservations: Reservation[]; @OneToMany(() => Reviews, (reviews) => reviews.bookInfo) - reviews?: Reviews[]; + reviews: Reviews[]; @OneToMany(() => SuperTag, (superTags) => superTags.userId) - superTags?: SuperTag[]; + superTags: SuperTag[]; } export default BookInfo;