@@ -2,49 +2,68 @@ import { DataTypes } from 'sequelize'
22import { CustomViewVisibility } from '@crowd/types'
33
44export default ( sequelize ) => {
5- const customView = sequelize . define ( 'customView' , {
6- id : {
7- type : DataTypes . UUID ,
8- defaultValue : DataTypes . UUIDV4 ,
9- primaryKey : true ,
10- } ,
11- name : {
12- type : DataTypes . STRING ,
13- allowNull : false ,
14- validate : {
15- notEmpty : true ,
5+ const customView = sequelize . define (
6+ 'customView' ,
7+ {
8+ id : {
9+ type : DataTypes . UUID ,
10+ defaultValue : DataTypes . UUIDV4 ,
11+ primaryKey : true ,
1612 } ,
17- } ,
18- visibility : {
19- type : DataTypes . ENUM ,
20- values : Object . values ( CustomViewVisibility ) ,
21- allowNull : false ,
22- } ,
23- config : {
24- type : DataTypes . JSONB ,
25- defaultValue : { } ,
26- } ,
27- placement : {
28- type : DataTypes . STRING ,
29- validate : {
30- isIn : [ [ 'member' , 'organization' , 'activity' , 'conversation' ] ] ,
13+ name : {
14+ type : DataTypes . STRING ,
15+ allowNull : false ,
16+ validate : {
17+ notEmpty : true ,
18+ } ,
19+ } ,
20+ visibility : {
21+ type : DataTypes . ENUM ,
22+ values : Object . values ( CustomViewVisibility ) ,
23+ allowNull : false ,
24+ } ,
25+ config : {
26+ type : DataTypes . JSONB ,
27+ defaultValue : { } ,
28+ } ,
29+ placement : {
30+ type : DataTypes . ARRAY ( DataTypes . STRING ) ,
31+ validate : {
32+ isIn : [ [ 'members' , 'organizations' , 'activities' , 'conversations' ] ] ,
33+ } ,
3134 } ,
3235 } ,
33- updatedById : {
34- type : DataTypes . UUID ,
35- allowNull : true ,
36- } ,
37- updatedAt : {
38- type : DataTypes . DATE ,
39- } ,
40- deletedById : {
41- type : DataTypes . UUID ,
42- allowNull : true ,
43- } ,
44- deletedAt : {
45- type : DataTypes . DATE ,
36+ {
37+ indexes : [
38+ {
39+ unqiue : true ,
40+ fields : [ 'id' , 'tenantId' ] ,
41+ where : {
42+ deletedAt : null ,
43+ } ,
44+ } ,
45+ ] ,
46+ timestamps : true ,
47+ paranoid : true ,
4648 } ,
47- } )
49+ )
50+
51+ customView . associate = ( models ) => {
52+ models . customView . belongsTo ( models . tenant , {
53+ as : 'tenantId' ,
54+ foreignKey : {
55+ allowNull : false ,
56+ } ,
57+ } )
58+
59+ models . customView . belongsTo ( models . member , {
60+ as : 'createdById' ,
61+ } )
62+
63+ models . customView . belongsTo ( models . member , {
64+ as : 'updatedById' ,
65+ } )
66+ }
4867
4968 return customView
5069}
0 commit comments