Initial commit

This commit is contained in:
Silas
2024-09-11 16:40:12 -04:00
commit 6bdf7a32a9
38 changed files with 11219 additions and 0 deletions

32
src/entities/User.ts Normal file
View 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();
}
}
}

View 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
View 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();
}
}
}