diff --git a/src/entities/article-like.entity.ts b/src/entities/article-like.entity.ts new file mode 100644 index 0000000..f8b99d0 --- /dev/null +++ b/src/entities/article-like.entity.ts @@ -0,0 +1,21 @@ +import { Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm"; + +import { ArticleEntity } from "./article.entity"; +import { MemberEntity } from "./member.entity"; + +@Entity("article_likes") +export class ArticleLikeEntity { + @PrimaryColumn({ type: "int" }) + articleId!: number; + + @ManyToOne(() => ArticleEntity, (article) => article.articleLikes) + @JoinColumn({ name: "articleId", referencedColumnName: "id" }) + article!: ArticleEntity; + + @PrimaryColumn({ type: "int" }) + memberId!: number; + + @ManyToOne(() => MemberEntity, (member) => member.articleLikes) + @JoinColumn({ name: "memberId", referencedColumnName: "id" }) + member!: MemberEntity; +} diff --git a/src/entities/article.entity.ts b/src/entities/article.entity.ts new file mode 100644 index 0000000..f676694 --- /dev/null +++ b/src/entities/article.entity.ts @@ -0,0 +1,71 @@ +import { + Column, + CreateDateColumn, + Entity, + JoinColumn, + ManyToOne, + OneToMany, + PrimaryGeneratedColumn, + UpdateDateColumn, +} from "typeorm"; + +import { ArticleLikeEntity } from "./article-like.entity"; +import { CategoryEntity } from "./category.entity"; +import { DistrictEntity } from "./district.entity"; +import { MemberEntity } from "./member.entity"; +import { RegionEntity } from "./region.entity"; + +@Entity("articles") +export class ArticleEntity { + @PrimaryGeneratedColumn({ type: "int" }) + id!: number; + + @Column({ type: "varchar", length: 100 }) + title!: string; + + @Column({ type: "text" }) + content!: string; + + @Column({ type: "datetime" }) + startTime!: Date; + + @Column({ type: "datetime" }) + endTime!: Date; + + @Column({ type: "int" }) + memberId!: number; + + @ManyToOne(() => MemberEntity, (member) => member.articles) + @JoinColumn({ name: "memberId", referencedColumnName: "id" }) + member!: MemberEntity; + + @Column({ type: "int" }) + categoryId!: number; + + @ManyToOne(() => CategoryEntity, (category) => category.articles) + @JoinColumn({ name: "categoryId", referencedColumnName: "id" }) + category!: CategoryEntity; + + @Column({ type: "int" }) + regionId!: number; + + @ManyToOne(() => RegionEntity, (region) => region.articles) + @JoinColumn({ name: "regionId", referencedColumnName: "id" }) + region!: RegionEntity; + + @Column({ type: "int" }) + districtId!: number; + + @ManyToOne(() => DistrictEntity, (district) => district.articles) + @JoinColumn({ name: "districtId", referencedColumnName: "id" }) + district!: DistrictEntity; + + @OneToMany(() => ArticleLikeEntity, (articleLike) => articleLike.article) + articleLikes!: ArticleLikeEntity[]; + + @CreateDateColumn({ type: "timestamp", nullable: false }) + createdAt!: Date; + + @UpdateDateColumn({ type: "timestamp", nullable: false }) + updatedAt!: Date; +} diff --git a/src/entities/block-list.entity.ts b/src/entities/block-list.entity.ts index da0265b..b63cb80 100644 --- a/src/entities/block-list.entity.ts +++ b/src/entities/block-list.entity.ts @@ -8,7 +8,7 @@ import { @Entity("block_list") export class BlockListEntity { - @PrimaryGeneratedColumn() + @PrimaryGeneratedColumn({ type: "int" }) id!: number; @PrimaryColumn({ type: "int" }) diff --git a/src/entities/category.entity.ts b/src/entities/category.entity.ts new file mode 100644 index 0000000..43e0b5e --- /dev/null +++ b/src/entities/category.entity.ts @@ -0,0 +1,15 @@ +import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm"; + +import { ArticleEntity } from "./article.entity"; + +@Entity("category") +export class CategoryEntity { + @PrimaryGeneratedColumn({ type: "int" }) + id!: number; + + @Column({ type: "varchar", length: 50 }) + name!: string; + + @OneToMany(() => ArticleEntity, (article) => article.category) + articles!: ArticleEntity[]; +} diff --git a/src/entities/district.entity.ts b/src/entities/district.entity.ts new file mode 100644 index 0000000..8253945 --- /dev/null +++ b/src/entities/district.entity.ts @@ -0,0 +1,30 @@ +import { + Column, + Entity, + JoinColumn, + ManyToOne, + OneToMany, + PrimaryGeneratedColumn, +} from "typeorm"; + +import { ArticleEntity } from "./article.entity"; +import { RegionEntity } from "./region.entity"; + +@Entity("district") +export class DistrictEntity { + @PrimaryGeneratedColumn({ type: "int" }) + id!: number; + + @Column({ type: "varchar", length: 50 }) + name!: string; + + @Column({ type: "int" }) + regionId!: number; + + @ManyToOne(() => RegionEntity, (region) => region.districts) + @JoinColumn({ name: "regionId", referencedColumnName: "id" }) + region!: RegionEntity; + + @OneToMany(() => ArticleEntity, (article) => article.district) + articles!: ArticleEntity[]; +} diff --git a/src/entities/member.entity.ts b/src/entities/member.entity.ts index 8ee8dd9..2e0c745 100644 --- a/src/entities/member.entity.ts +++ b/src/entities/member.entity.ts @@ -4,13 +4,17 @@ import { Column, CreateDateColumn, Entity, + OneToMany, PrimaryGeneratedColumn, UpdateDateColumn, } from "typeorm"; +import { ArticleLikeEntity } from "./article-like.entity"; +import { ArticleEntity } from "./article.entity"; + @Entity("member") export class MemberEntity { - @PrimaryGeneratedColumn() + @PrimaryGeneratedColumn({ type: "int" }) id!: number; @IsNotEmpty() @@ -52,6 +56,12 @@ export class MemberEntity { @Column({ type: "boolean", default: false }) isEmailVerified!: boolean; + @OneToMany(() => ArticleEntity, (article) => article.member) + articles!: ArticleEntity[]; + + @OneToMany(() => ArticleLikeEntity, (articleLike) => articleLike.member) + articleLikes!: ArticleLikeEntity[]; + @CreateDateColumn({ type: "timestamp", nullable: false }) createdAt!: Date; diff --git a/src/entities/region.entity.ts b/src/entities/region.entity.ts new file mode 100644 index 0000000..84f123d --- /dev/null +++ b/src/entities/region.entity.ts @@ -0,0 +1,19 @@ +import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm"; + +import { ArticleEntity } from "./article.entity"; +import { DistrictEntity } from "./district.entity"; + +@Entity("region") +export class RegionEntity { + @PrimaryGeneratedColumn({ type: "int" }) + id!: number; + + @Column({ type: "varchar", length: 50 }) + name!: string; + + @OneToMany(() => DistrictEntity, (district) => district.region) + districts!: DistrictEntity[]; + + @OneToMany(() => ArticleEntity, (article) => article.region) + articles!: ArticleEntity[]; +} diff --git a/src/repositories/article-likes.repository.ts b/src/repositories/article-likes.repository.ts new file mode 100644 index 0000000..017050a --- /dev/null +++ b/src/repositories/article-likes.repository.ts @@ -0,0 +1,21 @@ +import { Injectable } from "@nestjs/common"; +import { InjectRepository } from "@nestjs/typeorm"; +import { QueryRunner, Repository } from "typeorm"; + +import { ArticleLikeEntity } from "@APP/entities/article-like.entity"; + +@Injectable() +export class ArticleLikesRepository extends Repository { + constructor( + @InjectRepository(ArticleLikeEntity) + private readonly repository: Repository, + ) { + super(repository.target, repository.manager, repository.queryRunner); + } + + getRepository(qr?: QueryRunner) { + return qr + ? qr.manager.getRepository(ArticleLikeEntity) + : this.repository; + } +} diff --git a/src/repositories/articles.repository.ts b/src/repositories/articles.repository.ts new file mode 100644 index 0000000..6f2206f --- /dev/null +++ b/src/repositories/articles.repository.ts @@ -0,0 +1,21 @@ +import { Injectable } from "@nestjs/common"; +import { InjectRepository } from "@nestjs/typeorm"; +import { QueryRunner, Repository } from "typeorm"; + +import { ArticleEntity } from "@APP/entities/article.entity"; + +@Injectable() +export class ArticlesRepository extends Repository { + constructor( + @InjectRepository(ArticleEntity) + private readonly repository: Repository, + ) { + super(repository.target, repository.manager, repository.queryRunner); + } + + getRepository(qr?: QueryRunner) { + return qr + ? qr.manager.getRepository(ArticleEntity) + : this.repository; + } +} diff --git a/src/repositories/block-list.repository.ts b/src/repositories/block-list.repository.ts index 20f3e2a..cac20aa 100644 --- a/src/repositories/block-list.repository.ts +++ b/src/repositories/block-list.repository.ts @@ -1,8 +1,10 @@ +import { Injectable } from "@nestjs/common"; import { InjectRepository } from "@nestjs/typeorm"; import { QueryRunner, Repository } from "typeorm"; import { BlockListEntity } from "@APP/entities/block-list.entity"; +@Injectable() export class BlockListRepository extends Repository { constructor( @InjectRepository(BlockListEntity) @@ -11,7 +13,7 @@ export class BlockListRepository extends Repository { super(repository.target, repository.manager, repository.queryRunner); } - getMembersRepository(qr?: QueryRunner) { + getRepository(qr?: QueryRunner) { return qr ? qr.manager.getRepository(BlockListEntity) : this.repository; diff --git a/src/repositories/categories.repository.ts b/src/repositories/categories.repository.ts new file mode 100644 index 0000000..df27e97 --- /dev/null +++ b/src/repositories/categories.repository.ts @@ -0,0 +1,21 @@ +import { Injectable } from "@nestjs/common"; +import { InjectRepository } from "@nestjs/typeorm"; +import { QueryRunner, Repository } from "typeorm"; + +import { CategoryEntity } from "@APP/entities/category.entity"; + +@Injectable() +export class CategoriesRepository extends Repository { + constructor( + @InjectRepository(CategoryEntity) + private readonly repository: Repository, + ) { + super(repository.target, repository.manager, repository.queryRunner); + } + + getRepository(qr?: QueryRunner) { + return qr + ? qr.manager.getRepository(CategoryEntity) + : this.repository; + } +} diff --git a/src/repositories/districts.repository.ts b/src/repositories/districts.repository.ts new file mode 100644 index 0000000..fd2c44c --- /dev/null +++ b/src/repositories/districts.repository.ts @@ -0,0 +1,21 @@ +import { Injectable } from "@nestjs/common"; +import { InjectRepository } from "@nestjs/typeorm"; +import { QueryRunner, Repository } from "typeorm"; + +import { DistrictEntity } from "@APP/entities/district.entity"; + +@Injectable() +export class DistrictsRepository extends Repository { + constructor( + @InjectRepository(DistrictEntity) + private readonly repository: Repository, + ) { + super(repository.target, repository.manager, repository.queryRunner); + } + + getRepository(qr?: QueryRunner) { + return qr + ? qr.manager.getRepository(DistrictEntity) + : this.repository; + } +} diff --git a/src/repositories/members.repository.ts b/src/repositories/members.repository.ts index 5cd914d..ccd6dce 100644 --- a/src/repositories/members.repository.ts +++ b/src/repositories/members.repository.ts @@ -1,8 +1,10 @@ +import { Injectable } from "@nestjs/common"; import { InjectRepository } from "@nestjs/typeorm"; import { QueryRunner, Repository } from "typeorm"; import { MemberEntity } from "@APP/entities/member.entity"; +@Injectable() export class MembersRepository extends Repository { constructor( @InjectRepository(MemberEntity) @@ -11,7 +13,7 @@ export class MembersRepository extends Repository { super(repository.target, repository.manager, repository.queryRunner); } - getMembersRepository(qr?: QueryRunner) { + getRepository(qr?: QueryRunner) { return qr ? qr.manager.getRepository(MemberEntity) : this.repository; diff --git a/src/repositories/regions.repository.ts b/src/repositories/regions.repository.ts new file mode 100644 index 0000000..63107f9 --- /dev/null +++ b/src/repositories/regions.repository.ts @@ -0,0 +1,21 @@ +import { Injectable } from "@nestjs/common"; +import { InjectRepository } from "@nestjs/typeorm"; +import { QueryRunner, Repository } from "typeorm"; + +import { RegionEntity } from "@APP/entities/region.entity"; + +@Injectable() +export class RegionsRepository extends Repository { + constructor( + @InjectRepository(RegionEntity) + private readonly repository: Repository, + ) { + super(repository.target, repository.manager, repository.queryRunner); + } + + getRepository(qr?: QueryRunner) { + return qr + ? qr.manager.getRepository(RegionEntity) + : this.repository; + } +}