Bansari Akhani commited on
Commit
1f6a8f9
·
1 Parent(s): c05123c

modified migrations to set field names with underscore snackcase only, apis to syn portfolio, buildings and units data, removed index.js from model, added index.ts file in src/model task - #7658,#7659, #7660

Browse files
src/controllers/propertyware/buildings.controller.ts ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Request, Response } from 'express';
2
+
3
+ import { fetchBuildings } from '../../shared/services/propertyware.service';
4
+ import PwBuildings from '../../models/pwBuildings';
5
+
6
+ export const syncBuildingsData = async (req: Request, res: Response) => {
7
+ try {
8
+
9
+ const buildingsData = await fetchBuildings();
10
+
11
+ console.log(buildingsData);
12
+ const buildingsResponseData = buildingsData.map((Buildings: Record<string, string>) => ({
13
+ pw_id: Buildings.id,
14
+ name: Buildings.name,
15
+ pw_portfolio_id:Buildings.portfolioID
16
+ }));
17
+ console.log(buildingsResponseData);
18
+
19
+ try {
20
+
21
+ const createResult = await PwBuildings.bulkCreate(buildingsResponseData, {
22
+ updateOnDuplicate: ['name', 'pw_portfolio_id'],
23
+ });
24
+
25
+ res.end("Portfolio data synced successfully");
26
+ } catch(error) {
27
+ console.log('Error inserting Buildings');
28
+ console.log(error);
29
+ }
30
+
31
+ } catch (error) {
32
+ console.error('Error fetching Buildings:', error);
33
+ }
34
+ };
src/controllers/propertyware/portfolio.controller.ts ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Request, Response } from 'express';
2
+
3
+ import { fetchPortfolio } from '../../shared/services/propertyware.service';
4
+ import PwPortfolio from './../../models/pwPortfolio';
5
+
6
+ export const syncPortfolioData = async (req: Request, res: Response) => {
7
+ try {
8
+
9
+ const portfolioData = await fetchPortfolio();
10
+
11
+ const portfolioResponseData = portfolioData.map((portfolio: { id: any; name: any; }) => ({
12
+ pw_id: portfolio.id,
13
+ name: portfolio.name,
14
+ }));
15
+
16
+ try {
17
+
18
+ const createResult = await PwPortfolio.bulkCreate(portfolioResponseData, {
19
+ updateOnDuplicate: ['name'],
20
+ });
21
+
22
+ res.end("Portfolio data synced successfully");
23
+
24
+ } catch (error) {
25
+ console.log(error);
26
+ res.end("Error inserting Portfolio");
27
+ }
28
+
29
+ } catch (error) {
30
+ console.error(error);
31
+ res.end("Error fetching Portfolio");
32
+ }
33
+ };
src/controllers/propertyware/units.controller.ts ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Request, Response } from 'express';
2
+
3
+ import { fetchUnits } from '../../shared/services/propertyware.service';
4
+ import PwUnits from './../../models/pwUnits';
5
+
6
+ export const syncUnitsData = async (req: Request, res: Response) => {
7
+ try {
8
+
9
+ const unitsData = await fetchUnits();
10
+
11
+ const unitsResponseData = unitsData.map((unit: Record<string, string>) => ({
12
+ pw_id: unit.id,
13
+ name: unit.name,
14
+ pw_portfolio_id:unit.portfolioID,
15
+ pw_building_id:unit.buildingID
16
+
17
+ }));
18
+
19
+ try {
20
+
21
+ const createResult = await PwUnits.bulkCreate(unitsResponseData, {
22
+ updateOnDuplicate: ['name','pw_portfolio_id', 'pw_building_id'],
23
+ });
24
+
25
+ res.end("Units data synced successfully");
26
+
27
+ } catch (error) {
28
+ console.log(error);
29
+ res.end("Error inserting Units");
30
+ }
31
+
32
+ } catch (error) {
33
+ console.error(error);
34
+ res.end("Error fetching Units");
35
+ }
36
+ };
src/db/migrations/20240710112620-create-roles-table.js CHANGED
@@ -20,11 +20,11 @@ module.exports = {
20
  type: Sequelize.TEXT
21
  },
22
 
23
- createdAt: {
24
  type: Sequelize.DATE
25
  },
26
 
27
- updatedAt: {
28
  type: Sequelize.DATE
29
  }
30
  });
@@ -32,4 +32,4 @@ module.exports = {
32
  async down(queryInterface, Sequelize) {
33
  await queryInterface.dropTable('Roles');
34
  }
35
- };
 
20
  type: Sequelize.TEXT
21
  },
22
 
23
+ created_at: {
24
  type: Sequelize.DATE
25
  },
26
 
27
+ updated_at: {
28
  type: Sequelize.DATE
29
  }
30
  });
 
32
  async down(queryInterface, Sequelize) {
33
  await queryInterface.dropTable('Roles');
34
  }
35
+ };
src/db/migrations/20240710113255-create-user-table.js CHANGED
@@ -35,11 +35,11 @@ module.exports = {
35
  allowNull: false
36
  },
37
 
38
- createdAt: {
39
  type: Sequelize.DATE
40
  },
41
 
42
- updatedAt: {
43
  type: Sequelize.DATE
44
  }
45
  });
 
35
  allowNull: false
36
  },
37
 
38
+ created_at: {
39
  type: Sequelize.DATE
40
  },
41
 
42
+ updated_at: {
43
  type: Sequelize.DATE
44
  }
45
  });
src/db/migrations/20240710114725-create-permissions-table.js CHANGED
@@ -25,12 +25,12 @@ module.exports = {
25
  type: Sequelize.STRING
26
  },
27
 
28
- createdAt: {
29
  allowNull: false,
30
  type: Sequelize.DATE
31
  },
32
 
33
- updatedAt: {
34
  allowNull: false,
35
  type: Sequelize.DATE
36
  }
@@ -39,4 +39,4 @@ module.exports = {
39
  async down(queryInterface, Sequelize) {
40
  await queryInterface.dropTable('Permissions');
41
  }
42
- };
 
25
  type: Sequelize.STRING
26
  },
27
 
28
+ created_at: {
29
  allowNull: false,
30
  type: Sequelize.DATE
31
  },
32
 
33
+ updated_at: {
34
  allowNull: false,
35
  type: Sequelize.DATE
36
  }
 
39
  async down(queryInterface, Sequelize) {
40
  await queryInterface.dropTable('Permissions');
41
  }
42
+ };
src/db/migrations/20240710122848-create-settings.js CHANGED
@@ -18,12 +18,12 @@ module.exports = {
18
  type: Sequelize.TEXT
19
  },
20
 
21
- createdAt: {
22
  allowNull: false,
23
  type: Sequelize.DATE
24
  },
25
 
26
- updatedAt: {
27
  allowNull: false,
28
  type: Sequelize.DATE
29
  }
@@ -32,4 +32,4 @@ module.exports = {
32
  async down(queryInterface, Sequelize) {
33
  await queryInterface.dropTable('Settings');
34
  }
35
- };
 
18
  type: Sequelize.TEXT
19
  },
20
 
21
+ created_at: {
22
  allowNull: false,
23
  type: Sequelize.DATE
24
  },
25
 
26
+ updated_at: {
27
  allowNull: false,
28
  type: Sequelize.DATE
29
  }
 
32
  async down(queryInterface, Sequelize) {
33
  await queryInterface.dropTable('Settings');
34
  }
35
+ };
src/db/migrations/20240711090014-create-pw-portfolio-table.js CHANGED
@@ -12,17 +12,17 @@ module.exports = {
12
  pw_id: {
13
  unique: true,
14
  allowNull: false,
15
- type: Sequelize.INTEGER
16
  },
17
  name: {
18
  allowNull: false,
19
  type: Sequelize.STRING
20
  },
21
- createdAt: {
22
  allowNull: false,
23
  type: Sequelize.DATE
24
  },
25
- updatedAt: {
26
  allowNull: false,
27
  type: Sequelize.DATE
28
  }
@@ -31,4 +31,4 @@ module.exports = {
31
  async down(queryInterface, Sequelize) {
32
  await queryInterface.dropTable('pw_portfolio');
33
  }
34
- };
 
12
  pw_id: {
13
  unique: true,
14
  allowNull: false,
15
+ type: Sequelize.BIGINT
16
  },
17
  name: {
18
  allowNull: false,
19
  type: Sequelize.STRING
20
  },
21
+ created_at: {
22
  allowNull: false,
23
  type: Sequelize.DATE
24
  },
25
+ updated_at: {
26
  allowNull: false,
27
  type: Sequelize.DATE
28
  }
 
31
  async down(queryInterface, Sequelize) {
32
  await queryInterface.dropTable('pw_portfolio');
33
  }
34
+ };
src/db/migrations/20240711100526-create-pw-buildings-table.js CHANGED
@@ -12,25 +12,25 @@ module.exports = {
12
  pw_id: {
13
  unique: true,
14
  allowNull: false,
15
- type: Sequelize.INTEGER
16
  },
17
  name: {
18
  allowNull: false,
19
  type: Sequelize.STRING
20
  },
21
- pw_portfolioID: {
22
  allowNull: false,
23
- type: Sequelize.INTEGER,
24
  references: {
25
  model: 'pw_portfolio',
26
  key: 'pw_id'
27
  },
28
  },
29
- createdAt: {
30
  allowNull: false,
31
  type: Sequelize.DATE
32
  },
33
- updatedAt: {
34
  allowNull: false,
35
  type: Sequelize.DATE
36
  }
@@ -39,4 +39,4 @@ module.exports = {
39
  async down(queryInterface, Sequelize) {
40
  await queryInterface.dropTable('pw_buildings');
41
  }
42
- };
 
12
  pw_id: {
13
  unique: true,
14
  allowNull: false,
15
+ type: Sequelize.BIGINT
16
  },
17
  name: {
18
  allowNull: false,
19
  type: Sequelize.STRING
20
  },
21
+ pw_portfolio_id: {
22
  allowNull: false,
23
+ type: Sequelize.BIGINT,
24
  references: {
25
  model: 'pw_portfolio',
26
  key: 'pw_id'
27
  },
28
  },
29
+ created_at: {
30
  allowNull: false,
31
  type: Sequelize.DATE
32
  },
33
+ updated_at: {
34
  allowNull: false,
35
  type: Sequelize.DATE
36
  }
 
39
  async down(queryInterface, Sequelize) {
40
  await queryInterface.dropTable('pw_buildings');
41
  }
42
+ };
src/db/migrations/20240711103246-create-pw-units-table.js CHANGED
@@ -12,33 +12,33 @@ module.exports = {
12
  pw_id: {
13
  unique: true,
14
  allowNull: false,
15
- type: Sequelize.INTEGER
16
  },
17
  name: {
18
  allowNull: false,
19
  type: Sequelize.STRING
20
  },
21
- pw_portfolioID: {
22
  allowNull: false,
23
- type: Sequelize.INTEGER,
24
  references: {
25
  model: 'pw_portfolio',
26
  key: 'pw_id'
27
  },
28
  },
29
- pw_buildingID: {
30
  allowNull: false,
31
- type: Sequelize.INTEGER,
32
  references: {
33
  model: 'pw_buildings',
34
  key: 'pw_id'
35
  },
36
  },
37
- createdAt: {
38
  allowNull: false,
39
  type: Sequelize.DATE
40
  },
41
- updatedAt: {
42
  allowNull: false,
43
  type: Sequelize.DATE
44
  }
@@ -47,4 +47,4 @@ module.exports = {
47
  async down(queryInterface, Sequelize) {
48
  await queryInterface.dropTable('pw_units');
49
  }
50
- };
 
12
  pw_id: {
13
  unique: true,
14
  allowNull: false,
15
+ type: Sequelize.BIGINT
16
  },
17
  name: {
18
  allowNull: false,
19
  type: Sequelize.STRING
20
  },
21
+ pw_portfolio_id: {
22
  allowNull: false,
23
+ type: Sequelize.BIGINT,
24
  references: {
25
  model: 'pw_portfolio',
26
  key: 'pw_id'
27
  },
28
  },
29
+ pw_building_id: {
30
  allowNull: false,
31
+ type: Sequelize.BIGINT,
32
  references: {
33
  model: 'pw_buildings',
34
  key: 'pw_id'
35
  },
36
  },
37
+ created_at: {
38
  allowNull: false,
39
  type: Sequelize.DATE
40
  },
41
+ updated_at: {
42
  allowNull: false,
43
  type: Sequelize.DATE
44
  }
 
47
  async down(queryInterface, Sequelize) {
48
  await queryInterface.dropTable('pw_units');
49
  }
50
+ };
src/models/index.js DELETED
@@ -1,43 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const Sequelize = require('sequelize');
6
- const process = require('process');
7
- const basename = path.basename(__filename);
8
- const env = process.env.NODE_ENV || 'development';
9
- const config = require(__dirname + '/../db/config/config.js')[env];
10
- const db = {};
11
-
12
- let sequelize;
13
- if (config.use_env_variable) {
14
- sequelize = new Sequelize(process.env[config.use_env_variable], config);
15
- } else {
16
- sequelize = new Sequelize(config.database, config.username, config.password, config);
17
- }
18
-
19
- fs
20
- .readdirSync(__dirname)
21
- .filter(file => {
22
- return (
23
- file.indexOf('.') !== 0 &&
24
- file !== basename &&
25
- file.slice(-3) === '.js' &&
26
- file.indexOf('.test.js') === -1
27
- );
28
- })
29
- .forEach(file => {
30
- const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
31
- db[model.name] = model;
32
- });
33
-
34
- Object.keys(db).forEach(modelName => {
35
- if (db[modelName].associate) {
36
- db[modelName].associate(db);
37
- }
38
- });
39
-
40
- db.sequelize = sequelize;
41
- db.Sequelize = Sequelize;
42
-
43
- module.exports = db;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/{db/models → models}/index.ts RENAMED
@@ -1,6 +1,6 @@
1
  import { Options, Sequelize } from "sequelize";
2
 
3
- import { config } from "db/config/db.config";
4
 
5
  export const sequelize = new Sequelize(
6
  config.database as string,
 
1
  import { Options, Sequelize } from "sequelize";
2
 
3
+ import { config } from "../db/config/db.config";
4
 
5
  export const sequelize = new Sequelize(
6
  config.database as string,
src/models/permissions.ts CHANGED
@@ -6,9 +6,9 @@ import {
6
  CreationOptional,
7
  } from 'sequelize';
8
 
9
- import { sequelize } from '../db/models/index';
10
  import Role from './roles';
11
- import { PermissionInterface } from '../shared/permission.interface';
12
 
13
  class Permission extends Model<InferAttributes<Permission>, InferCreationAttributes<Permission>> implements PermissionInterface {
14
  declare id: CreationOptional<number>;
@@ -54,4 +54,4 @@ Permission.init(
54
 
55
  Permission.belongsTo(Role, { foreignKey: 'role_id', onDelete: 'CASCADE' });
56
 
57
- export default Permission;
 
6
  CreationOptional,
7
  } from 'sequelize';
8
 
9
+ import { sequelize } from './index';
10
  import Role from './roles';
11
+ import { PermissionInterface } from '../shared/interfaces/permission.interface';
12
 
13
  class Permission extends Model<InferAttributes<Permission>, InferCreationAttributes<Permission>> implements PermissionInterface {
14
  declare id: CreationOptional<number>;
 
54
 
55
  Permission.belongsTo(Role, { foreignKey: 'role_id', onDelete: 'CASCADE' });
56
 
57
+ export default Permission;
src/models/pwBuildings.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
  InferCreationAttributes,
6
  CreationOptional,
7
  } from 'sequelize';
8
- import { sequelize } from '../db/models/index';
9
  import PwPortfolio from './pwPortfolio';
10
  import { PwBuildingInterface } from '../shared/interfaces/pwBuilding.interface';
11
  import PwUnit from './pwUnits';
@@ -18,7 +18,7 @@ class PwBuilding
18
  declare id?: CreationOptional<number>;
19
  declare name: string;
20
  declare pw_id: number;
21
- declare pw_portfolioID: number;
22
  }
23
 
24
  PwBuilding.init(
@@ -41,7 +41,7 @@ PwBuilding.init(
41
  allowNull: false,
42
  },
43
 
44
- pw_portfolioID: {
45
  type: DataTypes.INTEGER.UNSIGNED,
46
  allowNull: false,
47
  references: {
@@ -60,7 +60,7 @@ PwBuilding.init(
60
  }
61
  )
62
 
63
- PwBuilding.belongsTo(PwPortfolio, { foreignKey: 'pw_portfolioID' });
64
- PwBuilding.hasMany(PwUnit, { foreignKey: 'pw_buildingID' });
65
 
66
  export default PwBuilding
 
5
  InferCreationAttributes,
6
  CreationOptional,
7
  } from 'sequelize';
8
+ import { sequelize } from './index';
9
  import PwPortfolio from './pwPortfolio';
10
  import { PwBuildingInterface } from '../shared/interfaces/pwBuilding.interface';
11
  import PwUnit from './pwUnits';
 
18
  declare id?: CreationOptional<number>;
19
  declare name: string;
20
  declare pw_id: number;
21
+ declare pw_portfolio_id: number;
22
  }
23
 
24
  PwBuilding.init(
 
41
  allowNull: false,
42
  },
43
 
44
+ pw_portfolio_id: {
45
  type: DataTypes.INTEGER.UNSIGNED,
46
  allowNull: false,
47
  references: {
 
60
  }
61
  )
62
 
63
+ PwBuilding.belongsTo(PwPortfolio, { foreignKey: 'pw_portfolioID', targetKey: 'pw_id' });
64
+ // PwBuilding.hasMany(PwUnit, { foreignKey: 'pw_buildingID', sourceKey: 'pw_id' });
65
 
66
  export default PwBuilding
src/models/pwPortfolio.ts CHANGED
@@ -1,18 +1,14 @@
1
  import {
2
  DataTypes,
3
  Model,
4
- InferAttributes,
5
- InferCreationAttributes,
6
  CreationOptional,
7
  } from 'sequelize';
8
- import { sequelize } from '../db/models/index';
9
  import { PwPortfolioInterface } from '../shared/interfaces/pwPortfolio.interface';
10
  import PwBuilding from './pwBuildings';
11
  import PwUnit from './pwUnits';
12
 
13
- class PwPortfolio
14
- extends Model<InferAttributes<PwPortfolio>, InferCreationAttributes<PwPortfolio>>
15
- implements PwPortfolioInterface
16
  {
17
  declare id?: CreationOptional<number>;
18
  declare name: string;
@@ -50,8 +46,8 @@ PwPortfolio.init(
50
  }
51
  );
52
 
53
- PwPortfolio.hasMany(PwBuilding, { foreignKey: 'pw_portfolioID' });
54
- PwPortfolio.hasMany(PwUnit, { foreignKey: 'pw_portfolioID' });
55
 
56
 
57
  export default PwPortfolio
 
1
  import {
2
  DataTypes,
3
  Model,
 
 
4
  CreationOptional,
5
  } from 'sequelize';
6
+ import { sequelize } from './index';
7
  import { PwPortfolioInterface } from '../shared/interfaces/pwPortfolio.interface';
8
  import PwBuilding from './pwBuildings';
9
  import PwUnit from './pwUnits';
10
 
11
+ class PwPortfolio extends Model<PwPortfolioInterface> implements PwPortfolioInterface
 
 
12
  {
13
  declare id?: CreationOptional<number>;
14
  declare name: string;
 
46
  }
47
  );
48
 
49
+ // PwPortfolio.hasMany(PwBuilding, { foreignKey: 'pw_portfolioID', sourceKey: 'pw_id' });
50
+ // PwPortfolio.hasMany(PwUnit, { foreignKey: 'pw_portfolioID', sourceKey: 'pw_id' });
51
 
52
 
53
  export default PwPortfolio
src/models/pwUnits.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
  InferCreationAttributes,
6
  CreationOptional,
7
  } from 'sequelize';
8
- import { sequelize } from '../db/models/index';
9
  import PwPortfolio from './pwPortfolio';
10
  import { PwUnitInterface } from 'shared/interfaces/pwUnits.interface';
11
  import PwBuilding from './pwBuildings';
@@ -17,8 +17,8 @@ class PwUnit
17
  declare id?: CreationOptional<number>;
18
  declare name: string;
19
  declare pw_id: number;
20
- declare pw_portfolioID: number;
21
- declare pw_buildingID: number;
22
  }
23
 
24
  PwUnit.init(
@@ -41,7 +41,7 @@ PwUnit.init(
41
  allowNull: false,
42
  },
43
 
44
- pw_portfolioID: {
45
  type: DataTypes.INTEGER.UNSIGNED,
46
  allowNull: false,
47
  references: {
@@ -50,7 +50,7 @@ PwUnit.init(
50
  },
51
  },
52
 
53
- pw_buildingID: {
54
  type: DataTypes.INTEGER.UNSIGNED,
55
  allowNull: false,
56
  references: {
@@ -68,8 +68,8 @@ PwUnit.init(
68
  timestamps: true,
69
  }
70
  );
71
-
72
- PwUnit.belongsTo(PwPortfolio, { foreignKey: 'pw_portfolioID' });
73
- PwUnit.belongsTo(PwBuilding, { foreignKey: 'pw_buildingID' });
74
 
75
  export default PwUnit;
 
5
  InferCreationAttributes,
6
  CreationOptional,
7
  } from 'sequelize';
8
+ import { sequelize } from './index';
9
  import PwPortfolio from './pwPortfolio';
10
  import { PwUnitInterface } from 'shared/interfaces/pwUnits.interface';
11
  import PwBuilding from './pwBuildings';
 
17
  declare id?: CreationOptional<number>;
18
  declare name: string;
19
  declare pw_id: number;
20
+ declare pw_portfolio_id: number;
21
+ declare pw_building_id: number;
22
  }
23
 
24
  PwUnit.init(
 
41
  allowNull: false,
42
  },
43
 
44
+ pw_portfolio_id: {
45
  type: DataTypes.INTEGER.UNSIGNED,
46
  allowNull: false,
47
  references: {
 
50
  },
51
  },
52
 
53
+ pw_building_id: {
54
  type: DataTypes.INTEGER.UNSIGNED,
55
  allowNull: false,
56
  references: {
 
68
  timestamps: true,
69
  }
70
  );
71
+ console.log(PwPortfolio);
72
+ PwUnit.belongsTo(PwPortfolio, { foreignKey: 'pw_portfolioID', targetKey: 'pw_id' });
73
+ PwUnit.belongsTo(PwBuilding, { foreignKey: 'pw_buildingID', targetKey: 'pw_id' });
74
 
75
  export default PwUnit;
src/models/roles.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
  InferCreationAttributes,
6
  CreationOptional,
7
  } from 'sequelize';
8
- import { sequelize } from '../db/models/index';
9
  import User from './users';
10
  import Permission from './permissions';
11
  import { RoleInterface } from '../shared/interfaces/role.interface';
 
5
  InferCreationAttributes,
6
  CreationOptional,
7
  } from 'sequelize';
8
+ import { sequelize } from './index';
9
  import User from './users';
10
  import Permission from './permissions';
11
  import { RoleInterface } from '../shared/interfaces/role.interface';
src/models/settings.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
  InferCreationAttributes,
6
  CreationOptional,
7
  } from 'sequelize';
8
- import { sequelize } from '../db/models/index';
9
  import { SettingInterface } from '../shared/interfaces/setting.interface';
10
 
11
  class Setting extends Model<InferAttributes<Setting>, InferCreationAttributes<Setting>> implements SettingInterface {
 
5
  InferCreationAttributes,
6
  CreationOptional,
7
  } from 'sequelize';
8
+ import { sequelize } from './index';
9
  import { SettingInterface } from '../shared/interfaces/setting.interface';
10
 
11
  class Setting extends Model<InferAttributes<Setting>, InferCreationAttributes<Setting>> implements SettingInterface {
src/models/users.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
  InferCreationAttributes,
6
  CreationOptional,
7
  } from 'sequelize';
8
- import { sequelize } from '../db/models/index';
9
  import Role from './roles';
10
  import { UserInterface } from '../shared/interfaces/user.interface';
11
 
 
5
  InferCreationAttributes,
6
  CreationOptional,
7
  } from 'sequelize';
8
+ import { sequelize } from './index';
9
  import Role from './roles';
10
  import { UserInterface } from '../shared/interfaces/user.interface';
11
 
src/routes/index.ts CHANGED
@@ -1,12 +1,16 @@
1
  import express from "express";
2
  import { fetchVendorsData } from "../controllers/propertyware/vendors.controller";
3
  import { fetchGLAccountsData } from "../controllers/propertyware/glAccounts.controller";
4
- import { fetchPortfolioData } from "controllers/propertyware/portfolio.controller";
 
 
5
 
6
  const pwRouter = express.Router();
7
 
8
  pwRouter.get("/pw/glAccounts", fetchGLAccountsData);
9
  pwRouter.get("/pw/vendors", fetchVendorsData);
10
- pwRouter.get("/pw/getPortfolio", fetchPortfolioData);
 
 
11
 
12
  export default pwRouter;
 
1
  import express from "express";
2
  import { fetchVendorsData } from "../controllers/propertyware/vendors.controller";
3
  import { fetchGLAccountsData } from "../controllers/propertyware/glAccounts.controller";
4
+ import { syncPortfolioData } from "../controllers/propertyware/portfolio.controller";
5
+ import { syncBuildingsData } from "../controllers/propertyware/buildings.controller";
6
+ import { syncUnitsData } from "../controllers/propertyware/units.controller";
7
 
8
  const pwRouter = express.Router();
9
 
10
  pwRouter.get("/pw/glAccounts", fetchGLAccountsData);
11
  pwRouter.get("/pw/vendors", fetchVendorsData);
12
+ pwRouter.get("/pw/syncPortfolio", syncPortfolioData);
13
+ pwRouter.get("/pw/syncBuildings", syncBuildingsData);
14
+ pwRouter.get("/pw/syncUnits", syncUnitsData);
15
 
16
  export default pwRouter;
src/shared/interfaces/pwBuilding.interface.ts CHANGED
@@ -2,5 +2,5 @@ export interface PwBuildingInterface {
2
  id?: number;
3
  name: string;
4
  pw_id: number;
5
- pw_portfolioID: number;
6
  }
 
2
  id?: number;
3
  name: string;
4
  pw_id: number;
5
+ pw_portfolio_id: number;
6
  }
src/shared/interfaces/pwUnits.interface.ts CHANGED
@@ -2,6 +2,6 @@ export interface PwUnitInterface {
2
  id?: number;
3
  name: string;
4
  pw_id: number;
5
- pw_portfolioID: number;
6
- pw_buildingID: number;
7
  }
 
2
  id?: number;
3
  name: string;
4
  pw_id: number;
5
+ pw_portfolio_id: number;
6
+ pw_building_id: number;
7
  }
src/shared/services/propertyware.service.ts CHANGED
@@ -13,3 +13,11 @@ export const fetchPortfolio = async (params = []) => {
13
  const response = await apiClientPW.get(`/portfolios`, { params });
14
  return response.data;
15
  };
 
 
 
 
 
 
 
 
 
13
  const response = await apiClientPW.get(`/portfolios`, { params });
14
  return response.data;
15
  };
16
+ export const fetchBuildings = async (params = []) => {
17
+ const response = await apiClientPW.get(`/buildings`, { params });
18
+ return response.data;
19
+ };
20
+ export const fetchUnits = async (params = []) => {
21
+ const response = await apiClientPW.get(`/units`, { params });
22
+ return response.data;
23
+ };