intended-server/src/entities/User.ts

33 lines
667 B
TypeScript

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