Initial commit
This commit is contained in:
32
src/entities/User.ts
Normal file
32
src/entities/User.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { CollectionOf, MaxLength, Property, Required } from "@tsed/schema";
|
||||
import { BeforeInsert, Column, Entity, OneToMany, PrimaryColumn } from "typeorm";
|
||||
import { Link } from "./link/Link";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
@PrimaryColumn("uuid")
|
||||
@Property()
|
||||
id: string;
|
||||
|
||||
@Column({ length: 100 })
|
||||
@MaxLength(100)
|
||||
@Required()
|
||||
service: string;
|
||||
|
||||
@Column({ length: 100 })
|
||||
@MaxLength(100)
|
||||
@Required()
|
||||
serviceUsername: string;
|
||||
|
||||
@OneToMany(() => Link, (link) => link.user)
|
||||
@CollectionOf(() => Link)
|
||||
links: Link[];
|
||||
|
||||
@BeforeInsert()
|
||||
generateId() {
|
||||
if (!this.id) {
|
||||
this.id = uuidv4();
|
||||
}
|
||||
}
|
||||
}
|
13
src/entities/link/CreateLinkDTO.ts
Normal file
13
src/entities/link/CreateLinkDTO.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Property, Required, MaxLength } from "@tsed/schema";
|
||||
|
||||
export class CreateLinkDto {
|
||||
@Property()
|
||||
@Required()
|
||||
@MaxLength(100)
|
||||
service: string;
|
||||
|
||||
@Property()
|
||||
@Required()
|
||||
@MaxLength(100)
|
||||
serviceUsername: string;
|
||||
}
|
36
src/entities/link/Link.ts
Normal file
36
src/entities/link/Link.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { MaxLength, Property, Required } from "@tsed/schema";
|
||||
import { Column, Entity, ManyToOne, PrimaryColumn, JoinColumn, BeforeInsert } from "typeorm";
|
||||
import { User } from "../User";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
@Entity()
|
||||
export class Link {
|
||||
@PrimaryColumn("uuid")
|
||||
@Property()
|
||||
id: string;
|
||||
|
||||
@Column({ length: 100 })
|
||||
@MaxLength(100)
|
||||
@Required()
|
||||
service: string;
|
||||
|
||||
@Column({ length: 100 })
|
||||
@MaxLength(100)
|
||||
@Required()
|
||||
serviceUsername: string;
|
||||
|
||||
@ManyToOne(() => User, (user) => user.links, { onDelete: "SET NULL", onUpdate: "CASCADE" })
|
||||
@JoinColumn({ name: "userId" })
|
||||
user: User;
|
||||
|
||||
@Column({ type: "uuid", nullable: true })
|
||||
@Property()
|
||||
userId: string | null;
|
||||
|
||||
@BeforeInsert()
|
||||
generateId() {
|
||||
if (!this.id) {
|
||||
this.id = uuidv4();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user