-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOrganization.ts
More file actions
81 lines (68 loc) · 1.72 KB
/
Organization.ts
File metadata and controls
81 lines (68 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { Transform, Type } from 'class-transformer';
import {
IsEnum,
IsInt,
IsOptional,
IsUrl,
Length,
Matches,
Min,
ValidateNested
} from 'class-validator';
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
import { ListChunk } from '../Base';
import { User, UserBase } from '../User';
@Entity()
export class Organization extends UserBase {
@Length(3)
@Column({ unique: true })
name: string;
@Matches(/^[A-Za-z-]+$/)
@Column({ unique: true })
englishName: string;
@Length(100)
@Column({ nullable: true })
summary?: string;
@IsUrl()
@Column({ nullable: true })
logo?: string;
@IsUrl()
@Column({ nullable: true })
url?: string;
@Type(() => Membership)
@ValidateNested({ each: true })
@IsOptional()
@OneToMany(() => Membership, ({ organization }) => organization, { cascade: true })
members: Membership[];
}
export abstract class OrganizationBase extends UserBase {
@Type(() => Organization)
@Transform(({ value }) => Organization.from(value))
@ValidateNested()
@ManyToOne(() => Organization)
organization: Organization;
}
export class OrganizationListChunk implements ListChunk<Organization> {
@IsInt()
@Min(0)
count: number;
@Type(() => Organization)
@ValidateNested({ each: true })
list: Organization[];
}
export enum MemberRole {
Admin,
Worker
}
@Entity()
export class Membership extends OrganizationBase {
@Type(() => User)
@Transform(({ value }) => User.from(value))
@ValidateNested()
@IsOptional()
@ManyToOne(() => User)
user: User;
@IsEnum(MemberRole)
@Column({ type: 'simple-enum', enum: MemberRole })
roleType: MemberRole;
}