File size: 1,343 Bytes
2f053c1
 
 
 
 
 
 
1f6a8f9
2f053c1
6f05a9e
2f053c1
 
 
 
 
 
 
 
 
1f6a8f9
2f053c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e295cd
2f053c1
 
 
 
1f6a8f9
2f053c1
 
 
 
39156c3
2f053c1
 
 
 
 
 
 
 
 
 
e30c136
 
2f053c1
 
 
bda5441
2f053c1
5e295cd
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
import {
  Model,
  DataTypes,
  InferAttributes,
  InferCreationAttributes,
  CreationOptional,
} from 'sequelize';
import { sequelize } from './index';
import PwPortfolio from './pwPortfolio';
import { PwBuildingInterface } from '../shared/interfaces/pwBuilding.interface';


class PwBuilding
  extends Model<InferAttributes<PwBuilding>, InferCreationAttributes<PwBuilding>>
  implements PwBuildingInterface
{
  declare id?: CreationOptional<number>;
  declare name: string;
  declare pw_id: number;
  declare pw_portfolio_id: number;
}

PwBuilding.init(
  {
    id: {
      type: DataTypes.INTEGER.UNSIGNED,
      autoIncrement: true,
      primaryKey: true,
      unique: true,
    },

    name: {
      type: DataTypes.STRING,
      allowNull: false,
    },

    pw_id: {
      unique: true,
      type: DataTypes.INTEGER,
      allowNull: false,
    },

    pw_portfolio_id: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      references: {
        model: PwPortfolio,
        key: 'pw_id',
      },
    },
  },

  {
    sequelize,
    tableName: 'pw_buildings',
    underscored: true,
    freezeTableName: true,
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
  }
)

PwBuilding.belongsTo(PwPortfolio, { foreignKey: 'pw_portfolio_id', targetKey: 'pw_id' });

export default PwBuilding