@nutrien-br/liborgs 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/.nvmrc +1 -0
  2. package/lib/index.d.mts +290 -0
  3. package/lib/index.d.ts +290 -0
  4. package/lib/index.js +949 -0
  5. package/lib/index.mjs +912 -0
  6. package/package.json +41 -0
  7. package/src/core/entity/CreditSourceSchema.ts +15 -0
  8. package/src/core/entity/schFinancial/CreditAnalysisResultSchema.ts +17 -0
  9. package/src/core/entity/schFinancial/CreditSourceLimitHistorySchema.ts +32 -0
  10. package/src/core/entity/schFinancial/RateRulesSchema.ts +21 -0
  11. package/src/core/entity/schFinancial/SolicitationNfSchema.ts +12 -0
  12. package/src/core/entity/schFinancial/SolicitationRateSchema.ts +23 -0
  13. package/src/core/entity/schFinancial/SolicitationRevenueSchema.ts +12 -0
  14. package/src/core/entity/schFinancial/SolicitationSchema.ts +23 -0
  15. package/src/core/entity/schOrgs/CompanySchema.ts +16 -0
  16. package/src/core/entity/schOrgs/PersonSchema.ts +24 -0
  17. package/src/index.ts +2 -0
  18. package/src/infra/config/params.ts +17 -0
  19. package/src/infra/database/Database.ts +33 -0
  20. package/src/infra/database/migrate.ts +52 -0
  21. package/src/infra/database/migrations/01_create_table_credit_source.migration.ts +49 -0
  22. package/src/infra/database/seed.ts +35 -0
  23. package/src/infra/database/seeds/01_create_seed_credit_source.seed.ts +55 -0
  24. package/src/infra/database/strategies/IDatabaseStrategy.ts +5 -0
  25. package/src/infra/database/strategies/PostgresStrategy.ts +17 -0
  26. package/src/infra/database/strategies/SqliteStrategy.ts +14 -0
  27. package/src/infra/database/umzug-migration.type.ts +9 -0
  28. package/src/infra/database/umzug.ts +30 -0
  29. package/src/infra/models/initModels.ts +58 -0
  30. package/src/infra/models/schFinancial/CreditAnalysisResult.ts +82 -0
  31. package/src/infra/models/schFinancial/CreditSource.ts +46 -0
  32. package/src/infra/models/schFinancial/CreditSourceLimitHistory.ts +91 -0
  33. package/src/infra/models/schFinancial/RateRules.ts +45 -0
  34. package/src/infra/models/schFinancial/Solicitation.ts +91 -0
  35. package/src/infra/models/schFinancial/SolicitationNf.ts +74 -0
  36. package/src/infra/models/schFinancial/SolicitationRate.ts +72 -0
  37. package/src/infra/models/schFinancial/SolicitationRevenue.ts +72 -0
  38. package/src/infra/models/schFinancial/__tests__/creditSource.spec.ts +20 -0
  39. package/src/infra/models/schFinancial/__tests__/creditSourceLimitHistory.spec.ts +37 -0
  40. package/src/infra/models/schFinancial/__tests__/rateRules.spec.ts +37 -0
  41. package/src/infra/models/schFinancial/__tests__/solicitation.spec.ts +44 -0
  42. package/src/infra/models/schOrgs/Company.ts +75 -0
  43. package/src/infra/models/schOrgs/Person.ts +107 -0
  44. package/src/infra/models/schOrgs/__tests__/company.spec.ts +20 -0
  45. package/src/infra/models/schOrgs/__tests__/person.spec.ts +41 -0
  46. package/src/utils/initMock.ts +57 -0
  47. package/src/utils/mocks/mockCompanies.ts +27 -0
  48. package/src/utils/mocks/mockCreditAnalysisResult.ts +28 -0
  49. package/src/utils/mocks/mockCreditSourceLimitHistory.ts +26 -0
  50. package/src/utils/mocks/mockCreditSources.ts +24 -0
  51. package/src/utils/mocks/mockPerson.ts +23 -0
  52. package/src/utils/mocks/mockRateRules.ts +18 -0
  53. package/src/utils/mocks/mockSolicitation.ts +9 -0
  54. package/src/utils/mocks/mockSolicitationNf.ts +11 -0
  55. package/src/utils/mocks/mockSolicitationRate.ts +11 -0
  56. package/src/utils/mocks/mockSolicitationRevenue.ts +12 -0
  57. package/tsconfig.json +29 -0
  58. package/tsup.config.js +14 -0
  59. package/vitest.config.ts +43 -0
@@ -0,0 +1,82 @@
1
+ import {
2
+ CreationOptional,
3
+ DataTypes,
4
+ Model,
5
+ Sequelize,
6
+ NonAttribute
7
+ } from "sequelize";
8
+ import { CreditAnalysisResultEntity, CreateCreditAnalysisResultEntity } from "src/core/entity/schFinancial/CreditAnalysisResultSchema";
9
+ import { Solicitation, CreditSource } from "../initModels";
10
+
11
+ export class CreditAnalysisResult extends Model<
12
+ CreditAnalysisResultEntity,
13
+ CreateCreditAnalysisResultEntity
14
+ > {
15
+ declare careId: CreationOptional<number>;
16
+ declare careExternalId: string;
17
+ declare careRequestedLimit: number | null;
18
+ declare careApprovedLimit: number | null;
19
+ declare careDateSolicitation: CreationOptional<Date>;
20
+ declare careResponseDate: Date | null;
21
+ declare careResponse: CreationOptional<boolean>;
22
+ declare careRequestId: string;
23
+ declare soliId: number;
24
+ declare csrcId: number;
25
+
26
+ declare solicitation?: NonAttribute<Solicitation>;
27
+ declare creditSource?: NonAttribute<CreditSource>;
28
+
29
+ init(sequelize: Sequelize): void {
30
+ CreditAnalysisResult.init({
31
+ careId: {
32
+ type: DataTypes.INTEGER,
33
+ autoIncrement: true,
34
+ primaryKey: true,
35
+ },
36
+ careExternalId: {
37
+ type: DataTypes.STRING(255),
38
+ allowNull: false,
39
+ },
40
+ careRequestedLimit: {
41
+ type: DataTypes.DECIMAL(15, 2),
42
+ },
43
+ careApprovedLimit: {
44
+ type: DataTypes.DECIMAL(15, 2),
45
+ },
46
+ careDateSolicitation: {
47
+ type: DataTypes.DATE,
48
+ defaultValue: DataTypes.NOW,
49
+ },
50
+ careResponseDate: {
51
+ type: DataTypes.DATE,
52
+ },
53
+ careResponse: {
54
+ type: DataTypes.BOOLEAN,
55
+ defaultValue: false,
56
+ },
57
+ careRequestId: {
58
+ type: DataTypes.UUID,
59
+ allowNull: false,
60
+ },
61
+ soliId: {
62
+ type: DataTypes.INTEGER,
63
+ allowNull: false,
64
+ },
65
+ csrcId: {
66
+ type: DataTypes.INTEGER,
67
+ allowNull: false,
68
+ }
69
+ }, {
70
+ sequelize,
71
+ tableName: 'credit_analysis_result',
72
+ schema: process.env.NODE_ENV === 'test' ? undefined : 'sch_financial',
73
+ underscored: true,
74
+ timestamps: false
75
+ });
76
+ }
77
+
78
+ associate(): void {
79
+ CreditAnalysisResult.belongsTo(Solicitation, { foreignKey: 'soliId', as: 'solicitation' });
80
+ CreditAnalysisResult.belongsTo(CreditSource, { foreignKey: 'csrcId', as: 'creditSource' });
81
+ }
82
+ }
@@ -0,0 +1,46 @@
1
+ import { CreationOptional, DataTypes, Model, NonAttribute, Sequelize } from "sequelize";
2
+ import { CreateCreditSourceEntity, CreditSourceEntity } from "src/core/entity/CreditSourceSchema";
3
+ import { CreditSourceLimitHistory } from "./CreditSourceLimitHistory";
4
+ import { CreditAnalysisResult } from "./CreditAnalysisResult";
5
+
6
+ export class CreditSource extends Model<CreditSourceEntity, CreateCreditSourceEntity> {
7
+ declare csrcId: CreationOptional<number>;
8
+ declare csrcName: string;
9
+ declare csrcType: 'PARTNER' | 'IN_HOUSE';
10
+
11
+ declare limitHistories?: NonAttribute<CreditSourceLimitHistory[]>;
12
+ declare analysisResults?: NonAttribute<CreditAnalysisResult[]>;
13
+
14
+ init(sequelize: Sequelize): void {
15
+ CreditSource.init({
16
+ csrcId: {
17
+ type: DataTypes.INTEGER,
18
+ autoIncrement: true,
19
+ primaryKey: true,
20
+ allowNull: false,
21
+ },
22
+ csrcName: {
23
+ type: DataTypes.STRING,
24
+ allowNull: false,
25
+ },
26
+ csrcType: {
27
+ type: DataTypes.ENUM('PARTNER', 'IN_HOUSE'),
28
+ allowNull: false,
29
+ }
30
+ }, {
31
+ sequelize,
32
+ tableName: 'credit_start',
33
+ schema: process.env.NODE_ENV === 'test' ? undefined : 'sch_financial',
34
+ underscored: true,
35
+ timestamps: false
36
+ })
37
+ }
38
+
39
+ associate(): void {
40
+ CreditSource.hasMany(CreditSourceLimitHistory, {
41
+ foreignKey: 'csrcId',
42
+ as: 'limitHistories'
43
+ });
44
+ CreditSource.hasMany(CreditAnalysisResult, { foreignKey: 'csrcId', as: 'analysisResults' });
45
+ }
46
+ }
@@ -0,0 +1,91 @@
1
+ import {
2
+ CreationOptional,
3
+ DataTypes,
4
+ Model,
5
+ Sequelize,
6
+ InferAttributes,
7
+ InferCreationAttributes,
8
+ NonAttribute
9
+ } from "sequelize";
10
+ import { CreditSourceLimitHistoryEntity, CreateCreditSourceLimitHistoryEntity } from "src/core/entity/schFinancial/CreditSourceLimitHistorySchema";
11
+ import { Person, Company, CreditSource } from "../initModels";
12
+
13
+ export class CreditSourceLimitHistory extends Model<
14
+ CreditSourceLimitHistoryEntity,
15
+ CreateCreditSourceLimitHistoryEntity
16
+ > {
17
+ declare cslhId: CreationOptional<number>;
18
+ declare csrcId: number;
19
+ declare persId: number | null;
20
+ declare compId: number | null;
21
+ declare cslhTotalLimit: number;
22
+ declare cslhUsedLimit: number;
23
+ declare cslhAvailableLimit: CreationOptional<number>;
24
+ declare cslhReferenceDate: Date;
25
+ declare cslhCreatedAt: CreationOptional<Date>;
26
+
27
+ declare person?: NonAttribute<Person>;
28
+ declare company?: NonAttribute<Company>;
29
+ declare creditSource?: NonAttribute<CreditSource>;
30
+
31
+ init(sequelize: Sequelize): void {
32
+ CreditSourceLimitHistory.init({
33
+ cslhId: {
34
+ type: DataTypes.INTEGER,
35
+ autoIncrement: true,
36
+ primaryKey: true,
37
+ },
38
+ csrcId: {
39
+ type: DataTypes.INTEGER,
40
+ allowNull: false,
41
+ },
42
+ persId: {
43
+ type: DataTypes.INTEGER,
44
+ allowNull: true,
45
+ references: { model: { tableName: 'person', schema: 'sch_orgs' }, key: 'pers_id' }
46
+ },
47
+ compId: {
48
+ type: DataTypes.INTEGER,
49
+ allowNull: true,
50
+ references: { model: { tableName: 'company', schema: 'sch_orgs' }, key: 'comp_id' }
51
+ },
52
+ cslhTotalLimit: {
53
+ type: DataTypes.DECIMAL(15, 2),
54
+ allowNull: false,
55
+ },
56
+ cslhUsedLimit: {
57
+ type: DataTypes.DECIMAL(15, 2),
58
+ allowNull: false,
59
+ },
60
+ cslhAvailableLimit: {
61
+ type: DataTypes.DECIMAL(15, 2),
62
+ allowNull: true,
63
+ // set() { throw new Error('cslhAvailableLimit is a read-only generated column'); }
64
+ },
65
+ cslhReferenceDate: {
66
+ type: DataTypes.DATEONLY,
67
+ allowNull: false,
68
+ },
69
+ cslhCreatedAt: {
70
+ type: DataTypes.DATE,
71
+ defaultValue: DataTypes.NOW,
72
+ }
73
+ }, {
74
+ sequelize,
75
+ tableName: 'credit_source_limit_history',
76
+ schema: process.env.NODE_ENV === 'test' ? undefined : 'sch_financial',
77
+ underscored: true,
78
+ timestamps: false
79
+ });
80
+ }
81
+
82
+ associate(): void {
83
+ CreditSourceLimitHistory.belongsTo(Person, { foreignKey: 'persId', as: 'person' });
84
+ CreditSourceLimitHistory.belongsTo(Company, { foreignKey: 'compId', as: 'company' });
85
+ CreditSourceLimitHistory.belongsTo(CreditSource, {
86
+ foreignKey: 'csrcId',
87
+ as: 'creditSource',
88
+ onDelete: 'CASCADE'
89
+ });
90
+ }
91
+ }
@@ -0,0 +1,45 @@
1
+ import { CreationOptional, DataTypes, Model, Sequelize, InferAttributes, InferCreationAttributes } from "sequelize";
2
+ import { CreateRateRulesEntity, RateRulesEntity } from "src/core/entity/schFinancial/RateRulesSchema";
3
+
4
+ export class RateRules extends Model<RateRulesEntity, CreateRateRulesEntity> {
5
+ declare raruId: CreationOptional<number>;
6
+ declare raruVersion: CreationOptional<number>;
7
+ declare raruRating: string;
8
+ declare raruInHousePercentage: number;
9
+ declare raruPartnerPercentage: number;
10
+
11
+ init(sequelize: Sequelize): void {
12
+ RateRules.init({
13
+ raruId: {
14
+ type: DataTypes.INTEGER,
15
+ autoIncrement: true,
16
+ primaryKey: true,
17
+ allowNull: false,
18
+ },
19
+ raruVersion: {
20
+ type: DataTypes.INTEGER,
21
+ allowNull: true,
22
+ },
23
+ raruRating: {
24
+ type: DataTypes.STRING(2),
25
+ allowNull: false,
26
+ },
27
+ raruInHousePercentage: {
28
+ type: DataTypes.DECIMAL(5, 2),
29
+ allowNull: false,
30
+ },
31
+ raruPartnerPercentage: {
32
+ type: DataTypes.DECIMAL(5, 2),
33
+ allowNull: false,
34
+ }
35
+ }, {
36
+ sequelize,
37
+ tableName: 'rate_rules',
38
+ schema: process.env.NODE_ENV === 'test' ? undefined : 'sch_financial',
39
+ underscored: true,
40
+ timestamps: false
41
+ });
42
+ }
43
+
44
+ associate(): void { }
45
+ }
@@ -0,0 +1,91 @@
1
+ import { CreationOptional, DataTypes, Model, NonAttribute, Sequelize } from "sequelize";
2
+ import { CreateSolicitationEntity, SolicitationEntity } from "src/core/entity/schFinancial/SolicitationSchema";
3
+ import { Person, Company, SolicitationRevenue } from "../initModels";
4
+ import { SolicitationRate } from "./SolicitationRate";
5
+ import { SolicitationNf } from "./SolicitationNf";
6
+ import { CreditAnalysisResult } from "./CreditAnalysisResult";
7
+
8
+ export class Solicitation extends Model<SolicitationEntity, CreateSolicitationEntity> {
9
+ declare soliId: CreationOptional<number>;
10
+ declare soliRequestedLimit: number;
11
+ declare soliCompleted: boolean;
12
+ declare persId: CreationOptional<number>;
13
+ declare compId: CreationOptional<number>;
14
+
15
+ declare person?: NonAttribute<Person>
16
+ declare company?: NonAttribute<Company>
17
+ declare rates?: NonAttribute<SolicitationRate[]>
18
+ declare revenues?: NonAttribute<SolicitationRevenue[]>
19
+ declare nfs?: NonAttribute<SolicitationNf[]>
20
+ declare analysisResults?: NonAttribute<CreditAnalysisResult[]>;
21
+
22
+ init(sequelize: Sequelize): void {
23
+ Solicitation.init({
24
+ soliId: {
25
+ type: DataTypes.INTEGER,
26
+ autoIncrement: true,
27
+ primaryKey: true,
28
+ allowNull: false,
29
+ },
30
+ soliRequestedLimit: {
31
+ type: DataTypes.NUMBER,
32
+ allowNull: false,
33
+ },
34
+ soliCompleted: {
35
+ type: DataTypes.BOOLEAN,
36
+ defaultValue: false,
37
+ allowNull: false,
38
+ },
39
+ persId: {
40
+ type: DataTypes.INTEGER,
41
+ allowNull: true,
42
+ references: {
43
+ model: {
44
+ tableName: 'person',
45
+ schema: 'sch_orgs'
46
+ },
47
+ key: 'pers_id'
48
+ }
49
+ },
50
+ compId: {
51
+ type: DataTypes.INTEGER,
52
+ allowNull: true,
53
+ references: {
54
+ model: {
55
+ tableName: 'company',
56
+ schema: 'sch_orgs'
57
+ },
58
+ key: 'comp_id'
59
+ }
60
+ }
61
+ }, {
62
+ sequelize,
63
+ tableName: 'solicitation',
64
+ schema: process.env.NODE_ENV === 'test' ? undefined : 'sch_financial',
65
+ underscored: true,
66
+ timestamps: false
67
+ })
68
+ }
69
+
70
+ associate(): void {
71
+ Solicitation.belongsTo(Person, {
72
+ foreignKey: 'persId',
73
+ as: 'person'
74
+ });
75
+
76
+ Solicitation.belongsTo(Company, {
77
+ foreignKey: 'compId',
78
+ as: 'company'
79
+ });
80
+ Solicitation.hasMany(SolicitationRate, {
81
+ foreignKey: 'soliId',
82
+ as: 'rates'
83
+ });
84
+ Solicitation.hasMany(SolicitationRevenue, {
85
+ foreignKey: 'soliId',
86
+ as: 'revenues'
87
+ });
88
+ Solicitation.hasMany(SolicitationNf, { foreignKey: 'soliId', as: 'nfs' });
89
+ Solicitation.hasMany(CreditAnalysisResult, { foreignKey: 'soliId', as: 'analysisResults' });
90
+ }
91
+ }
@@ -0,0 +1,74 @@
1
+ import {
2
+ CreationOptional,
3
+ DataTypes,
4
+ Model,
5
+ Sequelize,
6
+ InferAttributes,
7
+ InferCreationAttributes,
8
+ NonAttribute
9
+ } from "sequelize";
10
+ import { CreateSolicitationNfEntity, SolicitationNfEntity } from "src/core/entity/schFinancial/SolicitationNfSchema";
11
+ import { Solicitation } from "./Solicitation";
12
+
13
+ export class SolicitationNf extends Model<
14
+ SolicitationNfEntity,
15
+ CreateSolicitationNfEntity
16
+ > {
17
+ declare sonfId: CreationOptional<number>;
18
+ declare sonfSumNf: number | null;
19
+ declare sonfCompleted: CreationOptional<boolean>;
20
+ declare sonfRequestId: string;
21
+ declare soliId: number;
22
+
23
+ declare solicitation?: NonAttribute<Solicitation>;
24
+
25
+ init(sequelize: Sequelize): void {
26
+ SolicitationNf.init({
27
+ sonfId: {
28
+ type: DataTypes.INTEGER,
29
+ autoIncrement: true,
30
+ primaryKey: true,
31
+ allowNull: false,
32
+ },
33
+ sonfSumNf: {
34
+ type: DataTypes.DECIMAL(15, 2),
35
+ allowNull: true,
36
+ },
37
+ sonfCompleted: {
38
+ type: DataTypes.BOOLEAN,
39
+ defaultValue: false,
40
+ allowNull: false,
41
+ },
42
+ sonfRequestId: {
43
+ type: DataTypes.UUID,
44
+ allowNull: false,
45
+ },
46
+ soliId: {
47
+ type: DataTypes.INTEGER,
48
+ allowNull: false,
49
+ references: {
50
+ model: {
51
+ tableName: 'solicitation',
52
+ schema: 'sch_financial'
53
+ },
54
+ key: 'soli_id'
55
+ }
56
+ }
57
+ }, {
58
+ sequelize,
59
+ tableName: 'solicitation_nf',
60
+ schema: process.env.NODE_ENV === 'test' ? undefined : 'sch_financial',
61
+ underscored: true,
62
+ timestamps: false
63
+ });
64
+ }
65
+
66
+ associate(): void {
67
+ SolicitationNf.belongsTo(Solicitation, {
68
+ foreignKey: 'soliId',
69
+ as: 'solicitation',
70
+ onDelete: 'CASCADE',
71
+ onUpdate: 'CASCADE'
72
+ });
73
+ }
74
+ }
@@ -0,0 +1,72 @@
1
+ import { CreationOptional, DataTypes, Model, NonAttribute, Sequelize } from "sequelize";
2
+ import { CreateSolicitationRateEntity, SolicitationRateEntity } from "src/core/entity/schFinancial/SolicitationRateSchema";
3
+ import { Solicitation } from "./Solicitation";
4
+
5
+ export class SolicitationRate extends Model<SolicitationRateEntity, CreateSolicitationRateEntity> {
6
+ declare soraId: CreationOptional<number>;
7
+ declare soraRating: CreationOptional<string>;
8
+ declare soraInHousePercentage: number;
9
+ declare soraPartnerPercentage: number;
10
+ declare soraInHouseAllocation: number;
11
+ declare soraPartnerAllocation: number;
12
+ declare soliId: number;
13
+
14
+ declare solicitation?: NonAttribute<Solicitation>;
15
+
16
+ init(sequelize: Sequelize): void {
17
+ SolicitationRate.init({
18
+ soraId: {
19
+ type: DataTypes.INTEGER,
20
+ autoIncrement: true,
21
+ primaryKey: true,
22
+ allowNull: false,
23
+ },
24
+ soraRating: {
25
+ type: DataTypes.STRING(2),
26
+ allowNull: true,
27
+ },
28
+ soraInHousePercentage: {
29
+ type: DataTypes.DECIMAL(5, 2),
30
+ allowNull: false,
31
+ },
32
+ soraPartnerPercentage: {
33
+ type: DataTypes.DECIMAL(5, 2),
34
+ allowNull: false,
35
+ },
36
+ soraInHouseAllocation: {
37
+ type: DataTypes.DECIMAL(15, 2),
38
+ allowNull: false,
39
+ },
40
+ soraPartnerAllocation: {
41
+ type: DataTypes.DECIMAL(15, 2),
42
+ allowNull: false,
43
+ },
44
+ soliId: {
45
+ type: DataTypes.INTEGER,
46
+ allowNull: false,
47
+ references: {
48
+ model: {
49
+ tableName: 'solicitation',
50
+ schema: 'sch_financial'
51
+ },
52
+ key: 'soli_id'
53
+ }
54
+ }
55
+ }, {
56
+ sequelize,
57
+ tableName: 'solicitation_rate',
58
+ schema: process.env.NODE_ENV === 'test' ? undefined : 'sch_financial',
59
+ underscored: true,
60
+ timestamps: false
61
+ });
62
+ }
63
+
64
+ associate(): void {
65
+ SolicitationRate.belongsTo(Solicitation, {
66
+ foreignKey: 'soliId',
67
+ as: 'solicitation',
68
+ onDelete: 'CASCADE',
69
+ onUpdate: 'CASCADE'
70
+ });
71
+ }
72
+ }
@@ -0,0 +1,72 @@
1
+ import {
2
+ CreationOptional,
3
+ DataTypes,
4
+ Model,
5
+ Sequelize,
6
+ NonAttribute
7
+ } from "sequelize";
8
+ import { Solicitation } from "./Solicitation";
9
+ import { CreateSolicitationRevenueEntity, SolicitationRevenueEntity } from "src/core/entity/schFinancial/SolicitationRevenueSchema";
10
+
11
+ export class SolicitationRevenue extends Model<
12
+ SolicitationRevenueEntity,
13
+ CreateSolicitationRevenueEntity
14
+ > {
15
+ declare soreId: CreationOptional<number>;
16
+ declare soreRevenue: number | null;
17
+ declare soreCompleted: CreationOptional<boolean>;
18
+ declare soreRequestId: string;
19
+ declare soliId: number;
20
+
21
+ declare solicitation?: NonAttribute<Solicitation>;
22
+
23
+ init(sequelize: Sequelize): void {
24
+ SolicitationRevenue.init({
25
+ soreId: {
26
+ type: DataTypes.INTEGER,
27
+ autoIncrement: true,
28
+ primaryKey: true,
29
+ allowNull: false,
30
+ },
31
+ soreRevenue: {
32
+ type: DataTypes.DECIMAL(15, 2),
33
+ allowNull: true,
34
+ },
35
+ soreCompleted: {
36
+ type: DataTypes.BOOLEAN,
37
+ defaultValue: false,
38
+ allowNull: false,
39
+ },
40
+ soreRequestId: {
41
+ type: DataTypes.UUID,
42
+ allowNull: false,
43
+ },
44
+ soliId: {
45
+ type: DataTypes.INTEGER,
46
+ allowNull: false,
47
+ references: {
48
+ model: {
49
+ tableName: 'solicitation',
50
+ schema: 'sch_financial'
51
+ },
52
+ key: 'soli_id'
53
+ }
54
+ }
55
+ }, {
56
+ sequelize,
57
+ tableName: 'solicitation_revenue',
58
+ schema: process.env.NODE_ENV === 'test' ? undefined : 'sch_financial',
59
+ underscored: true,
60
+ timestamps: false
61
+ });
62
+ }
63
+
64
+ associate(): void {
65
+ SolicitationRevenue.belongsTo(Solicitation, {
66
+ foreignKey: 'soliId',
67
+ as: 'solicitation',
68
+ onDelete: 'CASCADE',
69
+ onUpdate: 'CASCADE'
70
+ });
71
+ }
72
+ }
@@ -0,0 +1,20 @@
1
+ import { describe, it, afterEach, beforeEach, expect } from "vitest";
2
+ import { initMock, closeMock } from '../../../../utils/initMock'
3
+ import { CreditSource } from '../CreditSource'
4
+
5
+ describe('CreditSource Model', () => {
6
+ beforeEach(async () => {
7
+ await initMock()
8
+ })
9
+
10
+ afterEach(async () => {
11
+ await closeMock()
12
+ })
13
+
14
+ describe('When findAll is called', () => {
15
+ it('should return a list of CreditSource', async () => {
16
+ const creditSources = await CreditSource.findAll()
17
+ expect(creditSources[0].csrcName).toBe('FARM')
18
+ })
19
+ })
20
+ })
@@ -0,0 +1,37 @@
1
+ import { describe, it, afterEach, beforeEach, expect } from "vitest";
2
+ import { initMock, closeMock } from '../../../../utils/initMock'
3
+ import { Solicitation } from '../Solicitation'
4
+ import { SolicitationRate } from "../SolicitationRate";
5
+ import { CreditSource, CreditSourceLimitHistory, Person, RateRules } from "../../initModels";
6
+
7
+ describe('CreditSourceLimitHistory Model', () => {
8
+ beforeEach(async () => {
9
+ await initMock()
10
+ })
11
+
12
+ afterEach(async () => {
13
+ await closeMock()
14
+ })
15
+
16
+ describe('When findAll is called', () => {
17
+ it('should return a list of CreditSourceLimitHistory', async () => {
18
+ const creditSourceLimitHistories = await CreditSourceLimitHistory.findAll()
19
+ expect(creditSourceLimitHistories[0].cslhId).toBe(1)
20
+ })
21
+ })
22
+
23
+ describe('When findOne is called', () => {
24
+ it('should return one with relationship', async () => {
25
+ const creditSourceLimitHistory = await CreditSourceLimitHistory.findOne({
26
+ where: { cslhId: 1 },
27
+ include: [
28
+ { model: CreditSource, as: 'creditSource' },
29
+ { model: Person, as: 'person' }
30
+ ]
31
+ })
32
+
33
+ expect(creditSourceLimitHistory?.cslhTotalLimit).toBe(4000)
34
+ expect(creditSourceLimitHistory?.person?.persId).toBe(1)
35
+ })
36
+ })
37
+ })
@@ -0,0 +1,37 @@
1
+ import { describe, it, afterEach, beforeEach, expect } from "vitest";
2
+ import { initMock, closeMock } from '../../../../utils/initMock'
3
+ import { Solicitation } from '../Solicitation'
4
+ import { SolicitationRate } from "../SolicitationRate";
5
+ import { Person, RateRules } from "../../initModels";
6
+
7
+ describe('RateRules Model', () => {
8
+ beforeEach(async () => {
9
+ await initMock()
10
+ })
11
+
12
+ afterEach(async () => {
13
+ await closeMock()
14
+ })
15
+
16
+ describe('When findAll is called', () => {
17
+ it('should return a list of Rules', async () => {
18
+ const solicitations = await RateRules.findAll()
19
+ expect(solicitations[0].raruRating).toBe('A')
20
+ })
21
+ })
22
+
23
+ describe('When findOne is called', () => {
24
+ it('should return one with relationship', async () => {
25
+ const solicitation = await Solicitation.findOne({
26
+ where: { soliId: 1 },
27
+ include: [
28
+ { model: SolicitationRate, as: 'rates' },
29
+ { model: Person, as: 'person' }
30
+ ]
31
+ })
32
+ expect(solicitation?.soliId).toBe(1)
33
+ expect(solicitation?.rates?.[0]?.soraRating).toBe('A');
34
+ expect(solicitation?.person?.persId).toBe(1)
35
+ })
36
+ })
37
+ })