/
user.ts
92 lines (81 loc) · 2.27 KB
/
user.ts
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
82
83
84
85
86
87
88
89
90
91
92
import { BeforeInsert, Column, Entity, Index } from "typeorm"
import { DbAwareColumn } from "../utils/db-aware-column"
import { SoftDeletableEntity } from "../interfaces/models/soft-deletable-entity"
import { generateEntityId } from "../utils/generate-entity-id"
export enum UserRoles {
ADMIN = "admin",
MEMBER = "member",
DEVELOPER = "developer",
}
@Entity()
export class User extends SoftDeletableEntity {
@DbAwareColumn({
type: "enum",
enum: UserRoles,
nullable: true,
default: UserRoles.MEMBER,
})
role: UserRoles
@Index({ unique: true, where: "deleted_at IS NULL" })
@Column()
email: string
@Column({ nullable: true })
first_name: string
@Column({ nullable: true })
last_name: string
@Column({ nullable: true, select: false })
password_hash: string
@Column({ nullable: true })
api_token: string
@DbAwareColumn({ type: "jsonb", nullable: true })
metadata: Record<string, unknown>
@BeforeInsert()
private beforeInsert(): void {
this.id = generateEntityId(this.id, "usr")
}
}
/**
* @schema user
* title: "User"
* description: "Represents a User who can manage store settings."
* x-resourceId: user
* required:
* - email
* properties:
* id:
* type: string
* description: The user's ID
* example: usr_01G1G5V26F5TB3GPAPNJ8X1S3V
* email:
* description: "The email of the User"
* type: string
* format: email
* first_name:
* description: "The first name of the User"
* type: string
* example: Levi
* last_name:
* description: "The last name of the User"
* type: string
* example: Bogan
* api_token:
* description: An API token associated with the user.
* type: string
* example: null
* created_at:
* type: string
* description: "The date with timezone at which the resource was created."
* format: date-time
* updated_at:
* type: string
* description: "The date with timezone at which the resource was updated."
* format: date-time
* deleted_at:
* type: string
* description: "The date with timezone at which the resource was deleted."
* format: date-time
* metadata:
* type: object
* description: An optional key-value map with additional details
* example: {car: "white"}
*/