-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd5b0c4
commit 18d0cbd
Showing
31 changed files
with
1,057 additions
and
557 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import mongoose from "mongoose"; | ||
import { DataSource } from "typeorm"; | ||
import "reflect-metadata"; | ||
import { Article } from "../features/article/article-entity"; | ||
import { Comment } from "../features/comment/comment-entity"; | ||
import { User } from "../features/user/user-entity"; | ||
|
||
export default async function db(dbConnectionString: string) { | ||
try { | ||
await mongoose.connect(dbConnectionString), | ||
{ | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}; | ||
} catch (err) { | ||
console.error("Error connecting to database"); | ||
process.exit(1); | ||
} | ||
} | ||
export const AppDataSource = new DataSource({ | ||
type: "postgres", | ||
host: "localhost", | ||
port: 6543, | ||
password: "123123", | ||
username: "postgres", | ||
database: "express_app", | ||
synchronize: true, | ||
logging: true, | ||
entities: [Article, Comment, User], | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from "typeorm"; | ||
import { User } from "../user/user-entity"; | ||
|
||
@Entity() | ||
export class Article { | ||
@PrimaryGeneratedColumn("uuid") | ||
id: string; | ||
|
||
@Column({ type: "varchar", length: 300 }) | ||
title: string; | ||
|
||
@Column({ type: "varchar", length: 2000 }) | ||
content: string; | ||
|
||
@OneToOne(() => User) | ||
@JoinColumn() | ||
owner: string; | ||
|
||
@Column({ type: "date" }) | ||
updated_at: Date; | ||
|
||
@Column({ type: "date" }) | ||
created_at: Date; | ||
} |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { AppDataSource } from "../../config/db"; | ||
import { Article } from "./article-entity"; | ||
|
||
export const articleRepository = () => AppDataSource.getRepository(Article); |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import Joi from "joi"; | ||
import { ICreateArticleData, IPatchArticleData } from "./article-types"; | ||
import { ICreateArticleData, IPutArticleData } from "./article-types"; | ||
|
||
export const articleCreateSchema = Joi.object<ICreateArticleData>().keys({ | ||
title: Joi.string().required().min(3).max(100), | ||
content: Joi.string().required().min(3).max(10000), | ||
}); | ||
|
||
export const articlePatchSchema = Joi.object<IPatchArticleData>().keys({ | ||
export const articlePatchSchema = Joi.object<IPutArticleData>().keys({ | ||
title: Joi.string().optional().min(3).max(100), | ||
content: Joi.string().optional().min(3).max(10000), | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from "typeorm"; | ||
import { User } from "../user/user-entity"; | ||
|
||
@Entity() | ||
export class Comment { | ||
@PrimaryGeneratedColumn("uuid") | ||
id: string; | ||
|
||
@Column({ type: "varchar", length: 2000 }) | ||
content: string; | ||
|
||
@OneToOne(() => User) | ||
@JoinColumn() | ||
owner: string; | ||
|
||
@OneToOne(() => Comment, { nullable: true }) | ||
@JoinColumn() | ||
parent: string; | ||
|
||
@OneToOne(() => User) | ||
@JoinColumn() | ||
article: string; | ||
|
||
@Column({ type: "date" }) | ||
updated_at: Date; | ||
|
||
@Column({ type: "date" }) | ||
created_at: Date; | ||
} |
This file contains 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
Oops, something went wrong.