51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import {
|
|
Column,
|
|
CreateDateColumn,
|
|
Entity,
|
|
Index,
|
|
JoinColumn,
|
|
ManyToOne,
|
|
PrimaryColumn,
|
|
} from 'typeorm';
|
|
import { UserEntity } from '../auth/user.entity';
|
|
import { ListTemplateEntity } from './list-template.entity';
|
|
|
|
export type ListTemplateShareRole = 'collaborator';
|
|
|
|
@Entity('list_template_shares')
|
|
@Index(['templateId', 'userId'], { unique: true })
|
|
export class ListTemplateShareEntity {
|
|
@PrimaryColumn({ type: 'varchar', length: 36 })
|
|
id!: string;
|
|
|
|
@Index()
|
|
@Column({ type: 'varchar', length: 36 })
|
|
templateId!: string;
|
|
|
|
@Index()
|
|
@Column({ type: 'varchar', length: 36 })
|
|
userId!: string;
|
|
|
|
@Column({ type: 'varchar', length: 32, default: 'collaborator' })
|
|
role!: ListTemplateShareRole;
|
|
|
|
@CreateDateColumn({
|
|
type: 'datetime',
|
|
precision: 3,
|
|
default: () => 'CURRENT_TIMESTAMP(3)',
|
|
})
|
|
createdAt!: Date;
|
|
|
|
@ManyToOne(() => ListTemplateEntity, (template) => template.shares, {
|
|
onDelete: 'CASCADE',
|
|
})
|
|
@JoinColumn({ name: 'templateId' })
|
|
template?: ListTemplateEntity;
|
|
|
|
@ManyToOne(() => UserEntity, (user) => user.sharedTemplates, {
|
|
onDelete: 'CASCADE',
|
|
})
|
|
@JoinColumn({ name: 'userId' })
|
|
user?: UserEntity;
|
|
}
|