-
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.
Merge pull request #3 from WildCodeSchool/feature/entities
Ajout entities
- Loading branch information
Showing
11 changed files
with
971 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { BaseEntity, Column, CreateDateColumn, Entity, ManyToMany, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; | ||
import { User } from "@/entities/User"; | ||
import { Resource } from "@/entities/Resource"; | ||
|
||
@Entity() | ||
export class Comment extends BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@ManyToMany(() => User) | ||
user: User; | ||
|
||
@ManyToOne(() => Resource) | ||
resource: Resource; | ||
|
||
@Column( | ||
{ type: "longtext" }) | ||
content: string; | ||
|
||
@CreateDateColumn() | ||
createdAt: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { BaseEntity, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; | ||
import { User } from "@/entities/User"; | ||
|
||
@Entity() | ||
export class Contact extends BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@ManyToOne(() => User) | ||
sourceUser: User; | ||
|
||
@ManyToOne(() => User) | ||
targetUser: 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,15 @@ | ||
import { BaseEntity, Entity, ManyToMany, OneToOne, PrimaryGeneratedColumn } from 'typeorm'; | ||
import { User } from '@/entities/User'; | ||
import { Resource } from '@/entities/Resource'; | ||
|
||
@Entity() | ||
export class Comment extends BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@ManyToMany(() => User) | ||
user: User; | ||
|
||
@OneToOne(() => Resource) | ||
resource: Resource; | ||
} |
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,32 @@ | ||
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm'; | ||
import { User } from '@/entities/User'; | ||
import { Resource } from '@/entities/Resource'; | ||
|
||
export enum Reason { | ||
INNAPROPRIATE = 'inappropriate content', | ||
HARASSMENT = 'harassment', | ||
SPAM = 'spam', | ||
OTHER = 'other', | ||
NONE = 'none', | ||
} | ||
|
||
@Entity() | ||
export class Comment extends BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
user: User; | ||
|
||
@Column() | ||
resource: Resource; | ||
|
||
@Column({ type: 'longtext', nullable: true }) | ||
content: string; | ||
|
||
@Column({ type: 'enum', enum: Reason, default: Reason.NONE }) | ||
reason: Reason; | ||
|
||
@CreateDateColumn() | ||
createdAt: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
BaseEntity, | ||
Column, | ||
CreateDateColumn, | ||
Entity, | ||
ManyToMany, | ||
OneToOne, | ||
PrimaryGeneratedColumn, | ||
} from 'typeorm'; | ||
import { User } from '@/entities/User'; | ||
|
||
export enum FileVisibility { | ||
PRIVATE = 'private', | ||
PUBLIC = 'public', | ||
} | ||
|
||
@Entity() | ||
export class Resource extends BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@OneToOne(() => User) | ||
user: User; | ||
|
||
@Column({ | ||
type: 'varchar', | ||
length: 150, | ||
unique: true, | ||
}) | ||
name: string; | ||
|
||
@Column({ | ||
type: 'varchar', | ||
length: 100, | ||
}) | ||
path: string; | ||
|
||
@Column({ | ||
type: 'varchar', | ||
length: 255, | ||
unique: true, | ||
}) | ||
url: string; | ||
|
||
@Column({ | ||
type: 'enum', | ||
enum: FileVisibility, | ||
default: FileVisibility.PRIVATE, | ||
}) | ||
visibility: FileVisibility; | ||
|
||
@Column({ | ||
type: 'varchar', | ||
length: 320, | ||
nullable: true | ||
}) | ||
description: string; | ||
|
||
@ManyToMany(() => User, (User) => User.resourceAccess) | ||
usersWithAccess: User[]; | ||
|
||
@Column({ nullable: true }) | ||
expireAt: Date; | ||
|
||
@CreateDateColumn() | ||
createdAt: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from "typeorm"; | ||
|
||
@Entity() | ||
export class Subscribtion extends BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@CreateDateColumn() | ||
paidAt: Date; | ||
|
||
@Column() | ||
endAt: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { | ||
BaseEntity, | ||
Column, | ||
CreateDateColumn, | ||
Entity, | ||
ManyToMany, | ||
OneToOne, | ||
PrimaryGeneratedColumn, | ||
} from 'typeorm'; | ||
import { Resource } from '@/entities/Resource'; | ||
|
||
export enum UserRole { | ||
USER = 'user', | ||
ADMIN = 'admin', | ||
} | ||
|
||
@Entity() | ||
export class User extends BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column({ | ||
type: 'varchar', | ||
length: 320, | ||
unique: true, | ||
}) | ||
email: string; | ||
|
||
@Column({ | ||
type: 'varchar', | ||
length: 150, | ||
}) | ||
password: string; | ||
|
||
@CreateDateColumn() | ||
lastLoggedAt: Date; | ||
|
||
@Column({ | ||
type: 'enum', | ||
enum: UserRole, | ||
default: UserRole.USER, | ||
}) | ||
role: UserRole; | ||
|
||
@ManyToMany(() => Resource, (Resource) => Resource.usersWithAccess, { nullable: true }) | ||
resourceAccess: Resource[]; | ||
|
||
@OneToOne(() => User, (user) => user.subscription, { nullable: true }) | ||
subscription: User; | ||
|
||
@CreateDateColumn() | ||
createdAt: 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.