-
Notifications
You must be signed in to change notification settings - Fork 70
/
user.model.ts
124 lines (107 loc) · 2.37 KB
/
user.model.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (c) 2023 Sourcefuse Technologies
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
import {
belongsTo,
hasMany,
hasOne,
model,
property,
} from '@loopback/repository';
import {Gender, UserModifiableEntity} from '@sourceloop/core';
import {IAuthUser} from 'loopback4-authentication';
import {Tenant, TenantWithRelations} from './tenant.model';
import {
UserCredentials,
UserCredentialsWithRelations,
} from './user-credentials.model';
import {UserTenant, UserTenantWithRelations} from './user-tenant.model';
@model({
name: 'users',
description: 'This is signature for user model.',
})
export class User extends UserModifiableEntity<User> implements IAuthUser {
@property({
type: 'string',
id: true,
})
id?: string;
@property({
type: 'string',
required: true,
name: 'first_name',
})
firstName: string;
@property({
type: 'string',
name: 'last_name',
})
lastName: string;
@property({
type: 'string',
name: 'middle_name',
})
middleName?: string;
@property({
type: 'string',
required: true,
})
username: string;
@property({
type: 'string',
})
email?: string;
@property({
type: 'string',
jsonSchema: {
pattern: `^\\+?[1-9]\\d{1,14}$`,
},
})
phone?: string;
@property({
type: 'string',
name: 'auth_client_ids',
})
authClientIds?: string;
@property({
type: 'date',
name: 'last_login',
postgresql: {
column: 'last_login',
},
})
lastLogin?: Date;
@property({
type: 'date',
})
dob: Date;
@property({
type: 'string',
description: `This field takes a single character as input in database.
'M' for male and 'F' for female.`,
jsonSchema: {
enum: ['M', 'F', 'O'],
},
})
gender?: Gender;
@hasOne(() => UserCredentials, {keyTo: 'userId'})
credentials: UserCredentials;
@belongsTo(
() => Tenant,
{keyFrom: 'default_tenant_id', name: 'defaultTenant'},
{
name: 'default_tenant_id',
required: false,
},
)
defaultTenantId: string;
@hasMany(() => UserTenant, {keyTo: 'userId'})
userTenants: UserTenant[];
}
export interface UserRelations {
defaultTenant: TenantWithRelations;
credentials: UserCredentialsWithRelations;
userTenant: UserTenantWithRelations;
}
export type UserWithRelations = User & UserRelations;