@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
package/lib/index.js ADDED
@@ -0,0 +1,949 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ Company: () => Company,
34
+ CreditAnalysisResult: () => CreditAnalysisResult,
35
+ CreditSource: () => CreditSource,
36
+ CreditSourceLimitHistory: () => CreditSourceLimitHistory,
37
+ Person: () => Person,
38
+ RateRules: () => RateRules,
39
+ Solicitation: () => Solicitation,
40
+ SolicitationNf: () => SolicitationNf,
41
+ SolicitationRate: () => SolicitationRate,
42
+ SolicitationRevenue: () => SolicitationRevenue,
43
+ closeMock: () => closeMock,
44
+ initMock: () => initMock,
45
+ initModels: () => initModels
46
+ });
47
+ module.exports = __toCommonJS(index_exports);
48
+
49
+ // src/infra/database/strategies/PostgresStrategy.ts
50
+ var import_sequelize = require("sequelize");
51
+ var import_pg = __toESM(require("pg"));
52
+ var PostgresStrategy = class {
53
+ constructor(config) {
54
+ this.config = config;
55
+ }
56
+ connect() {
57
+ return new import_sequelize.Sequelize({
58
+ ...this.config,
59
+ dialect: "postgres",
60
+ dialectModule: import_pg.default,
61
+ logging: false,
62
+ pool: { max: 20, min: 5, acquire: 3e4, idle: 1e4 }
63
+ });
64
+ }
65
+ };
66
+
67
+ // src/infra/database/strategies/SqliteStrategy.ts
68
+ var import_sequelize2 = require("sequelize");
69
+ var SqliteStrategy = class {
70
+ constructor(storage) {
71
+ this.storage = storage;
72
+ }
73
+ connect() {
74
+ return new import_sequelize2.Sequelize({
75
+ dialect: "sqlite",
76
+ storage: this.storage || ":memory:",
77
+ logging: false
78
+ });
79
+ }
80
+ };
81
+
82
+ // src/infra/database/Database.ts
83
+ var Database = class _Database {
84
+ static getConnection() {
85
+ if (!_Database.instance) {
86
+ const strategy = _Database.resolveStrategy();
87
+ _Database.instance = strategy.connect();
88
+ }
89
+ return _Database.instance;
90
+ }
91
+ static resolveStrategy() {
92
+ const env = process.env.NODE_ENV || "development";
93
+ const isProductionLike = ["dev", "sit", "pre-prod", "prod"].includes(env);
94
+ if (isProductionLike) {
95
+ return new PostgresStrategy({
96
+ username: process.env.DB_USER,
97
+ password: process.env.DB_PASSWORD,
98
+ database: process.env.DB_NAME,
99
+ host: process.env.DB_HOST,
100
+ port: Number(process.env.DB_PORT)
101
+ });
102
+ }
103
+ return new SqliteStrategy(process.env.DB_STORAGE);
104
+ }
105
+ };
106
+
107
+ // src/infra/models/schFinancial/CreditAnalysisResult.ts
108
+ var import_sequelize3 = require("sequelize");
109
+ var CreditAnalysisResult = class _CreditAnalysisResult extends import_sequelize3.Model {
110
+ init(sequelize) {
111
+ _CreditAnalysisResult.init({
112
+ careId: {
113
+ type: import_sequelize3.DataTypes.INTEGER,
114
+ autoIncrement: true,
115
+ primaryKey: true
116
+ },
117
+ careExternalId: {
118
+ type: import_sequelize3.DataTypes.STRING(255),
119
+ allowNull: false
120
+ },
121
+ careRequestedLimit: {
122
+ type: import_sequelize3.DataTypes.DECIMAL(15, 2)
123
+ },
124
+ careApprovedLimit: {
125
+ type: import_sequelize3.DataTypes.DECIMAL(15, 2)
126
+ },
127
+ careDateSolicitation: {
128
+ type: import_sequelize3.DataTypes.DATE,
129
+ defaultValue: import_sequelize3.DataTypes.NOW
130
+ },
131
+ careResponseDate: {
132
+ type: import_sequelize3.DataTypes.DATE
133
+ },
134
+ careResponse: {
135
+ type: import_sequelize3.DataTypes.BOOLEAN,
136
+ defaultValue: false
137
+ },
138
+ careRequestId: {
139
+ type: import_sequelize3.DataTypes.UUID,
140
+ allowNull: false
141
+ },
142
+ soliId: {
143
+ type: import_sequelize3.DataTypes.INTEGER,
144
+ allowNull: false
145
+ },
146
+ csrcId: {
147
+ type: import_sequelize3.DataTypes.INTEGER,
148
+ allowNull: false
149
+ }
150
+ }, {
151
+ sequelize,
152
+ tableName: "credit_analysis_result",
153
+ schema: process.env.NODE_ENV === "test" ? void 0 : "sch_financial",
154
+ underscored: true,
155
+ timestamps: false
156
+ });
157
+ }
158
+ associate() {
159
+ _CreditAnalysisResult.belongsTo(Solicitation, { foreignKey: "soliId", as: "solicitation" });
160
+ _CreditAnalysisResult.belongsTo(CreditSource, { foreignKey: "csrcId", as: "creditSource" });
161
+ }
162
+ };
163
+
164
+ // src/infra/models/schFinancial/CreditSource.ts
165
+ var import_sequelize5 = require("sequelize");
166
+
167
+ // src/infra/models/schFinancial/CreditSourceLimitHistory.ts
168
+ var import_sequelize4 = require("sequelize");
169
+ var CreditSourceLimitHistory = class _CreditSourceLimitHistory extends import_sequelize4.Model {
170
+ init(sequelize) {
171
+ _CreditSourceLimitHistory.init({
172
+ cslhId: {
173
+ type: import_sequelize4.DataTypes.INTEGER,
174
+ autoIncrement: true,
175
+ primaryKey: true
176
+ },
177
+ csrcId: {
178
+ type: import_sequelize4.DataTypes.INTEGER,
179
+ allowNull: false
180
+ },
181
+ persId: {
182
+ type: import_sequelize4.DataTypes.INTEGER,
183
+ allowNull: true,
184
+ references: { model: { tableName: "person", schema: "sch_orgs" }, key: "pers_id" }
185
+ },
186
+ compId: {
187
+ type: import_sequelize4.DataTypes.INTEGER,
188
+ allowNull: true,
189
+ references: { model: { tableName: "company", schema: "sch_orgs" }, key: "comp_id" }
190
+ },
191
+ cslhTotalLimit: {
192
+ type: import_sequelize4.DataTypes.DECIMAL(15, 2),
193
+ allowNull: false
194
+ },
195
+ cslhUsedLimit: {
196
+ type: import_sequelize4.DataTypes.DECIMAL(15, 2),
197
+ allowNull: false
198
+ },
199
+ cslhAvailableLimit: {
200
+ type: import_sequelize4.DataTypes.DECIMAL(15, 2),
201
+ allowNull: true
202
+ // set() { throw new Error('cslhAvailableLimit is a read-only generated column'); }
203
+ },
204
+ cslhReferenceDate: {
205
+ type: import_sequelize4.DataTypes.DATEONLY,
206
+ allowNull: false
207
+ },
208
+ cslhCreatedAt: {
209
+ type: import_sequelize4.DataTypes.DATE,
210
+ defaultValue: import_sequelize4.DataTypes.NOW
211
+ }
212
+ }, {
213
+ sequelize,
214
+ tableName: "credit_source_limit_history",
215
+ schema: process.env.NODE_ENV === "test" ? void 0 : "sch_financial",
216
+ underscored: true,
217
+ timestamps: false
218
+ });
219
+ }
220
+ associate() {
221
+ _CreditSourceLimitHistory.belongsTo(Person, { foreignKey: "persId", as: "person" });
222
+ _CreditSourceLimitHistory.belongsTo(Company, { foreignKey: "compId", as: "company" });
223
+ _CreditSourceLimitHistory.belongsTo(CreditSource, {
224
+ foreignKey: "csrcId",
225
+ as: "creditSource",
226
+ onDelete: "CASCADE"
227
+ });
228
+ }
229
+ };
230
+
231
+ // src/infra/models/schFinancial/CreditSource.ts
232
+ var CreditSource = class _CreditSource extends import_sequelize5.Model {
233
+ init(sequelize) {
234
+ _CreditSource.init({
235
+ csrcId: {
236
+ type: import_sequelize5.DataTypes.INTEGER,
237
+ autoIncrement: true,
238
+ primaryKey: true,
239
+ allowNull: false
240
+ },
241
+ csrcName: {
242
+ type: import_sequelize5.DataTypes.STRING,
243
+ allowNull: false
244
+ },
245
+ csrcType: {
246
+ type: import_sequelize5.DataTypes.ENUM("PARTNER", "IN_HOUSE"),
247
+ allowNull: false
248
+ }
249
+ }, {
250
+ sequelize,
251
+ tableName: "credit_start",
252
+ schema: process.env.NODE_ENV === "test" ? void 0 : "sch_financial",
253
+ underscored: true,
254
+ timestamps: false
255
+ });
256
+ }
257
+ associate() {
258
+ _CreditSource.hasMany(CreditSourceLimitHistory, {
259
+ foreignKey: "csrcId",
260
+ as: "limitHistories"
261
+ });
262
+ _CreditSource.hasMany(CreditAnalysisResult, { foreignKey: "csrcId", as: "analysisResults" });
263
+ }
264
+ };
265
+
266
+ // src/infra/models/schFinancial/RateRules.ts
267
+ var import_sequelize6 = require("sequelize");
268
+ var RateRules = class _RateRules extends import_sequelize6.Model {
269
+ init(sequelize) {
270
+ _RateRules.init({
271
+ raruId: {
272
+ type: import_sequelize6.DataTypes.INTEGER,
273
+ autoIncrement: true,
274
+ primaryKey: true,
275
+ allowNull: false
276
+ },
277
+ raruVersion: {
278
+ type: import_sequelize6.DataTypes.INTEGER,
279
+ allowNull: true
280
+ },
281
+ raruRating: {
282
+ type: import_sequelize6.DataTypes.STRING(2),
283
+ allowNull: false
284
+ },
285
+ raruInHousePercentage: {
286
+ type: import_sequelize6.DataTypes.DECIMAL(5, 2),
287
+ allowNull: false
288
+ },
289
+ raruPartnerPercentage: {
290
+ type: import_sequelize6.DataTypes.DECIMAL(5, 2),
291
+ allowNull: false
292
+ }
293
+ }, {
294
+ sequelize,
295
+ tableName: "rate_rules",
296
+ schema: process.env.NODE_ENV === "test" ? void 0 : "sch_financial",
297
+ underscored: true,
298
+ timestamps: false
299
+ });
300
+ }
301
+ associate() {
302
+ }
303
+ };
304
+
305
+ // src/infra/models/schFinancial/Solicitation.ts
306
+ var import_sequelize9 = require("sequelize");
307
+
308
+ // src/infra/models/schFinancial/SolicitationRate.ts
309
+ var import_sequelize7 = require("sequelize");
310
+ var SolicitationRate = class _SolicitationRate extends import_sequelize7.Model {
311
+ init(sequelize) {
312
+ _SolicitationRate.init({
313
+ soraId: {
314
+ type: import_sequelize7.DataTypes.INTEGER,
315
+ autoIncrement: true,
316
+ primaryKey: true,
317
+ allowNull: false
318
+ },
319
+ soraRating: {
320
+ type: import_sequelize7.DataTypes.STRING(2),
321
+ allowNull: true
322
+ },
323
+ soraInHousePercentage: {
324
+ type: import_sequelize7.DataTypes.DECIMAL(5, 2),
325
+ allowNull: false
326
+ },
327
+ soraPartnerPercentage: {
328
+ type: import_sequelize7.DataTypes.DECIMAL(5, 2),
329
+ allowNull: false
330
+ },
331
+ soraInHouseAllocation: {
332
+ type: import_sequelize7.DataTypes.DECIMAL(15, 2),
333
+ allowNull: false
334
+ },
335
+ soraPartnerAllocation: {
336
+ type: import_sequelize7.DataTypes.DECIMAL(15, 2),
337
+ allowNull: false
338
+ },
339
+ soliId: {
340
+ type: import_sequelize7.DataTypes.INTEGER,
341
+ allowNull: false,
342
+ references: {
343
+ model: {
344
+ tableName: "solicitation",
345
+ schema: "sch_financial"
346
+ },
347
+ key: "soli_id"
348
+ }
349
+ }
350
+ }, {
351
+ sequelize,
352
+ tableName: "solicitation_rate",
353
+ schema: process.env.NODE_ENV === "test" ? void 0 : "sch_financial",
354
+ underscored: true,
355
+ timestamps: false
356
+ });
357
+ }
358
+ associate() {
359
+ _SolicitationRate.belongsTo(Solicitation, {
360
+ foreignKey: "soliId",
361
+ as: "solicitation",
362
+ onDelete: "CASCADE",
363
+ onUpdate: "CASCADE"
364
+ });
365
+ }
366
+ };
367
+
368
+ // src/infra/models/schFinancial/SolicitationNf.ts
369
+ var import_sequelize8 = require("sequelize");
370
+ var SolicitationNf = class _SolicitationNf extends import_sequelize8.Model {
371
+ init(sequelize) {
372
+ _SolicitationNf.init({
373
+ sonfId: {
374
+ type: import_sequelize8.DataTypes.INTEGER,
375
+ autoIncrement: true,
376
+ primaryKey: true,
377
+ allowNull: false
378
+ },
379
+ sonfSumNf: {
380
+ type: import_sequelize8.DataTypes.DECIMAL(15, 2),
381
+ allowNull: true
382
+ },
383
+ sonfCompleted: {
384
+ type: import_sequelize8.DataTypes.BOOLEAN,
385
+ defaultValue: false,
386
+ allowNull: false
387
+ },
388
+ sonfRequestId: {
389
+ type: import_sequelize8.DataTypes.UUID,
390
+ allowNull: false
391
+ },
392
+ soliId: {
393
+ type: import_sequelize8.DataTypes.INTEGER,
394
+ allowNull: false,
395
+ references: {
396
+ model: {
397
+ tableName: "solicitation",
398
+ schema: "sch_financial"
399
+ },
400
+ key: "soli_id"
401
+ }
402
+ }
403
+ }, {
404
+ sequelize,
405
+ tableName: "solicitation_nf",
406
+ schema: process.env.NODE_ENV === "test" ? void 0 : "sch_financial",
407
+ underscored: true,
408
+ timestamps: false
409
+ });
410
+ }
411
+ associate() {
412
+ _SolicitationNf.belongsTo(Solicitation, {
413
+ foreignKey: "soliId",
414
+ as: "solicitation",
415
+ onDelete: "CASCADE",
416
+ onUpdate: "CASCADE"
417
+ });
418
+ }
419
+ };
420
+
421
+ // src/infra/models/schFinancial/Solicitation.ts
422
+ var Solicitation = class _Solicitation extends import_sequelize9.Model {
423
+ init(sequelize) {
424
+ _Solicitation.init({
425
+ soliId: {
426
+ type: import_sequelize9.DataTypes.INTEGER,
427
+ autoIncrement: true,
428
+ primaryKey: true,
429
+ allowNull: false
430
+ },
431
+ soliRequestedLimit: {
432
+ type: import_sequelize9.DataTypes.NUMBER,
433
+ allowNull: false
434
+ },
435
+ soliCompleted: {
436
+ type: import_sequelize9.DataTypes.BOOLEAN,
437
+ defaultValue: false,
438
+ allowNull: false
439
+ },
440
+ persId: {
441
+ type: import_sequelize9.DataTypes.INTEGER,
442
+ allowNull: true,
443
+ references: {
444
+ model: {
445
+ tableName: "person",
446
+ schema: "sch_orgs"
447
+ },
448
+ key: "pers_id"
449
+ }
450
+ },
451
+ compId: {
452
+ type: import_sequelize9.DataTypes.INTEGER,
453
+ allowNull: true,
454
+ references: {
455
+ model: {
456
+ tableName: "company",
457
+ schema: "sch_orgs"
458
+ },
459
+ key: "comp_id"
460
+ }
461
+ }
462
+ }, {
463
+ sequelize,
464
+ tableName: "solicitation",
465
+ schema: process.env.NODE_ENV === "test" ? void 0 : "sch_financial",
466
+ underscored: true,
467
+ timestamps: false
468
+ });
469
+ }
470
+ associate() {
471
+ _Solicitation.belongsTo(Person, {
472
+ foreignKey: "persId",
473
+ as: "person"
474
+ });
475
+ _Solicitation.belongsTo(Company, {
476
+ foreignKey: "compId",
477
+ as: "company"
478
+ });
479
+ _Solicitation.hasMany(SolicitationRate, {
480
+ foreignKey: "soliId",
481
+ as: "rates"
482
+ });
483
+ _Solicitation.hasMany(SolicitationRevenue, {
484
+ foreignKey: "soliId",
485
+ as: "revenues"
486
+ });
487
+ _Solicitation.hasMany(SolicitationNf, { foreignKey: "soliId", as: "nfs" });
488
+ _Solicitation.hasMany(CreditAnalysisResult, { foreignKey: "soliId", as: "analysisResults" });
489
+ }
490
+ };
491
+
492
+ // src/infra/models/schFinancial/SolicitationRevenue.ts
493
+ var import_sequelize10 = require("sequelize");
494
+ var SolicitationRevenue = class _SolicitationRevenue extends import_sequelize10.Model {
495
+ init(sequelize) {
496
+ _SolicitationRevenue.init({
497
+ soreId: {
498
+ type: import_sequelize10.DataTypes.INTEGER,
499
+ autoIncrement: true,
500
+ primaryKey: true,
501
+ allowNull: false
502
+ },
503
+ soreRevenue: {
504
+ type: import_sequelize10.DataTypes.DECIMAL(15, 2),
505
+ allowNull: true
506
+ },
507
+ soreCompleted: {
508
+ type: import_sequelize10.DataTypes.BOOLEAN,
509
+ defaultValue: false,
510
+ allowNull: false
511
+ },
512
+ soreRequestId: {
513
+ type: import_sequelize10.DataTypes.UUID,
514
+ allowNull: false
515
+ },
516
+ soliId: {
517
+ type: import_sequelize10.DataTypes.INTEGER,
518
+ allowNull: false,
519
+ references: {
520
+ model: {
521
+ tableName: "solicitation",
522
+ schema: "sch_financial"
523
+ },
524
+ key: "soli_id"
525
+ }
526
+ }
527
+ }, {
528
+ sequelize,
529
+ tableName: "solicitation_revenue",
530
+ schema: process.env.NODE_ENV === "test" ? void 0 : "sch_financial",
531
+ underscored: true,
532
+ timestamps: false
533
+ });
534
+ }
535
+ associate() {
536
+ _SolicitationRevenue.belongsTo(Solicitation, {
537
+ foreignKey: "soliId",
538
+ as: "solicitation",
539
+ onDelete: "CASCADE",
540
+ onUpdate: "CASCADE"
541
+ });
542
+ }
543
+ };
544
+
545
+ // src/infra/models/schOrgs/Company.ts
546
+ var import_sequelize11 = require("sequelize");
547
+ var Company = class _Company extends import_sequelize11.Model {
548
+ init(sequelize) {
549
+ _Company.init({
550
+ compId: {
551
+ type: import_sequelize11.DataTypes.INTEGER,
552
+ autoIncrement: true,
553
+ primaryKey: true
554
+ },
555
+ compDes: {
556
+ type: import_sequelize11.DataTypes.STRING(60)
557
+ },
558
+ compCorporateName: {
559
+ type: import_sequelize11.DataTypes.STRING(300),
560
+ allowNull: false
561
+ },
562
+ compRegistration: {
563
+ type: import_sequelize11.DataTypes.STRING(20)
564
+ },
565
+ compUuid: {
566
+ type: import_sequelize11.DataTypes.UUID,
567
+ defaultValue: import_sequelize11.DataTypes.UUIDV4
568
+ },
569
+ compObs: {
570
+ type: import_sequelize11.DataTypes.STRING(4e3)
571
+ },
572
+ compRegisDate: {
573
+ type: import_sequelize11.DataTypes.DATE,
574
+ allowNull: false
575
+ },
576
+ compRegisUser: {
577
+ type: import_sequelize11.DataTypes.STRING(100),
578
+ allowNull: false
579
+ },
580
+ compErpRegisDate: {
581
+ type: import_sequelize11.DataTypes.DATE,
582
+ defaultValue: import_sequelize11.DataTypes.NOW
583
+ }
584
+ }, {
585
+ sequelize,
586
+ tableName: "companies",
587
+ schema: process.env.NODE_ENV === "test" ? void 0 : "sch_orgs",
588
+ underscored: true,
589
+ timestamps: false
590
+ });
591
+ }
592
+ associate() {
593
+ _Company.hasMany(Solicitation, {
594
+ foreignKey: "compId",
595
+ as: "solicitations"
596
+ });
597
+ _Company.hasMany(CreditSourceLimitHistory, {
598
+ foreignKey: "compId",
599
+ as: "creditLimitHistories"
600
+ });
601
+ }
602
+ };
603
+
604
+ // src/infra/models/schOrgs/Person.ts
605
+ var import_sequelize12 = require("sequelize");
606
+ var Person = class _Person extends import_sequelize12.Model {
607
+ init(sequelize) {
608
+ _Person.init({
609
+ persId: {
610
+ type: import_sequelize12.DataTypes.INTEGER,
611
+ autoIncrement: true,
612
+ primaryKey: true
613
+ },
614
+ persName: {
615
+ type: import_sequelize12.DataTypes.STRING(100),
616
+ allowNull: false
617
+ },
618
+ persSocialName: {
619
+ type: import_sequelize12.DataTypes.STRING(100)
620
+ },
621
+ persFirstName: {
622
+ type: import_sequelize12.DataTypes.STRING(50)
623
+ },
624
+ persLastName: {
625
+ type: import_sequelize12.DataTypes.STRING(50)
626
+ },
627
+ persBirthDate: {
628
+ type: import_sequelize12.DataTypes.DATE
629
+ },
630
+ persMothersName: {
631
+ type: import_sequelize12.DataTypes.STRING(100)
632
+ },
633
+ persFathersName: {
634
+ type: import_sequelize12.DataTypes.STRING(100)
635
+ },
636
+ persIndSex: {
637
+ type: import_sequelize12.DataTypes.STRING(1)
638
+ },
639
+ persRegistration: {
640
+ type: import_sequelize12.DataTypes.STRING(20)
641
+ },
642
+ persUuid: {
643
+ type: import_sequelize12.DataTypes.UUID,
644
+ defaultValue: import_sequelize12.DataTypes.UUIDV4
645
+ },
646
+ mastCod: {
647
+ type: import_sequelize12.DataTypes.STRING(10)
648
+ },
649
+ gendCod: {
650
+ type: import_sequelize12.DataTypes.STRING(10)
651
+ },
652
+ persObs: {
653
+ type: import_sequelize12.DataTypes.STRING(4e3)
654
+ },
655
+ persRegisDate: {
656
+ type: import_sequelize12.DataTypes.DATE,
657
+ allowNull: false
658
+ },
659
+ persRegisUser: {
660
+ type: import_sequelize12.DataTypes.STRING(50),
661
+ allowNull: false
662
+ },
663
+ persErpRegisDate: {
664
+ type: import_sequelize12.DataTypes.DATE,
665
+ defaultValue: import_sequelize12.DataTypes.NOW
666
+ }
667
+ }, {
668
+ sequelize,
669
+ tableName: "person",
670
+ schema: process.env.NODE_ENV === "test" ? void 0 : "sch_orgs",
671
+ underscored: true,
672
+ timestamps: false
673
+ });
674
+ }
675
+ associate() {
676
+ _Person.hasMany(Solicitation, {
677
+ foreignKey: "persId",
678
+ as: "solicitations"
679
+ });
680
+ _Person.hasMany(CreditSourceLimitHistory, {
681
+ foreignKey: "persId",
682
+ as: "creditLimitHistories"
683
+ });
684
+ }
685
+ };
686
+
687
+ // src/infra/models/initModels.ts
688
+ async function initModels() {
689
+ const sequelize = Database.getConnection();
690
+ const models = [
691
+ Person,
692
+ Company,
693
+ CreditSource,
694
+ Solicitation,
695
+ SolicitationRate,
696
+ RateRules,
697
+ SolicitationRevenue,
698
+ SolicitationNf,
699
+ CreditSourceLimitHistory,
700
+ CreditAnalysisResult
701
+ ];
702
+ models.forEach((model) => {
703
+ model.prototype.init(sequelize);
704
+ });
705
+ models.forEach((model) => {
706
+ if (model.prototype.associate) {
707
+ model.prototype.associate();
708
+ }
709
+ });
710
+ return sequelize;
711
+ }
712
+
713
+ // src/utils/mocks/mockCreditSources.ts
714
+ var mockCreditSources = [
715
+ {
716
+ csrcId: 1,
717
+ csrcName: "FARM",
718
+ csrcType: "PARTNER"
719
+ },
720
+ {
721
+ csrcId: 2,
722
+ csrcName: "SUPPLIER",
723
+ csrcType: "PARTNER"
724
+ },
725
+ {
726
+ csrcId: 3,
727
+ csrcName: "SELLOR",
728
+ csrcType: "PARTNER"
729
+ },
730
+ {
731
+ csrcId: 4,
732
+ csrcName: "NUTRIEN",
733
+ csrcType: "IN_HOUSE"
734
+ }
735
+ ];
736
+
737
+ // src/utils/mocks/mockPerson.ts
738
+ var import_node_crypto = require("crypto");
739
+ var mockPerson = [
740
+ {
741
+ persId: 1,
742
+ persName: "JOHNNY MOREIRA",
743
+ persSocialName: "JOHNNY",
744
+ persFirstName: "Johnny",
745
+ persLastName: "Moreira",
746
+ persBirthDate: /* @__PURE__ */ new Date("1991-01-18"),
747
+ persMothersName: "TESTE MOREIRA",
748
+ persFathersName: "TESTE2 MOREIRA",
749
+ persIndSex: "M",
750
+ persRegistration: "REG-001",
751
+ persUuid: (0, import_node_crypto.randomUUID)(),
752
+ mastCod: "1",
753
+ persObs: "Usu\xE1rio administrador",
754
+ persRegisDate: /* @__PURE__ */ new Date(),
755
+ persRegisUser: "MONEYFARM",
756
+ persErpRegisDate: /* @__PURE__ */ new Date()
757
+ }
758
+ ];
759
+
760
+ // src/utils/mocks/mockCompanies.ts
761
+ var import_node_crypto2 = require("crypto");
762
+ var mockCompanies = [
763
+ {
764
+ compId: 1,
765
+ compDes: "NUTRIEN MATRIZ",
766
+ compCorporateName: "NUTRIEN SOLUCOES AGRICOLAS LTDA",
767
+ compRegistration: "12.345.678/0001-00",
768
+ compUuid: (0, import_node_crypto2.randomUUID)(),
769
+ compObs: "Unidade principal de processamento.",
770
+ compRegisDate: /* @__PURE__ */ new Date(),
771
+ compRegisUser: "admin_sys",
772
+ compErpRegisDate: /* @__PURE__ */ new Date()
773
+ },
774
+ {
775
+ compId: 2,
776
+ compDes: "FILIAL SUL",
777
+ compCorporateName: "NUTRIEN AGRICULTURA DO SUL S.A.",
778
+ compRegistration: "98.765.432/0001-99",
779
+ compUuid: (0, import_node_crypto2.randomUUID)(),
780
+ compObs: "Respons\xE1vel pela log\xEDstica regional sul.",
781
+ compRegisDate: /* @__PURE__ */ new Date(),
782
+ compRegisUser: "johnny_dev",
783
+ compErpRegisDate: /* @__PURE__ */ new Date()
784
+ }
785
+ ];
786
+
787
+ // src/utils/mocks/mockSolicitation.ts
788
+ var mockSolicitation = [{
789
+ soliId: 1,
790
+ soliRequestedLimit: 5e3,
791
+ soliCompleted: false,
792
+ persId: 1,
793
+ compId: null
794
+ }];
795
+
796
+ // src/utils/mocks/mockSolicitationRate.ts
797
+ var mockSolicitationRate = [{
798
+ soraId: 1,
799
+ soraRating: "A",
800
+ soraInHousePercentage: 90,
801
+ soraPartnerPercentage: 10,
802
+ soraInHouseAllocation: 4500,
803
+ soraPartnerAllocation: 500,
804
+ soliId: 1
805
+ }];
806
+
807
+ // src/utils/mocks/mockRateRules.ts
808
+ var mockRateRules = [
809
+ {
810
+ raruId: 1,
811
+ raruVersion: 1,
812
+ raruRating: "A",
813
+ raruInHousePercentage: 90,
814
+ raruPartnerPercentage: 10
815
+ },
816
+ {
817
+ raruId: 2,
818
+ raruVersion: 1,
819
+ raruRating: "B",
820
+ raruInHousePercentage: 50,
821
+ raruPartnerPercentage: 50
822
+ }
823
+ ];
824
+
825
+ // src/utils/mocks/mockSolicitationRevenue.ts
826
+ var import_node_crypto3 = require("crypto");
827
+ var mockSolicitationRevenue = [
828
+ {
829
+ soreId: 1,
830
+ soreRevenue: 1500.5,
831
+ soreCompleted: true,
832
+ soreRequestId: (0, import_node_crypto3.randomUUID)(),
833
+ soliId: 1
834
+ }
835
+ ];
836
+
837
+ // src/utils/mocks/mockSolicitationNf.ts
838
+ var mockSolicitationNf = [
839
+ {
840
+ sonfId: 1,
841
+ sonfSumNf: 2500,
842
+ sonfCompleted: true,
843
+ sonfRequestId: "550e8400-e29b-41d4-a716-446655440000",
844
+ soliId: 1
845
+ }
846
+ ];
847
+
848
+ // src/utils/mocks/mockCreditSourceLimitHistory.ts
849
+ var mockCreditSourceLimitHistory = [
850
+ {
851
+ cslhId: 1,
852
+ csrcId: 4,
853
+ persId: 1,
854
+ compId: null,
855
+ cslhTotalLimit: 4e3,
856
+ cslhUsedLimit: 500,
857
+ cslhAvailableLimit: 3500,
858
+ cslhReferenceDate: /* @__PURE__ */ new Date("2026-03-01"),
859
+ cslhCreatedAt: /* @__PURE__ */ new Date()
860
+ },
861
+ {
862
+ cslhId: 2,
863
+ csrcId: 2,
864
+ persId: 1,
865
+ compId: null,
866
+ cslhTotalLimit: 1e3,
867
+ cslhUsedLimit: 500,
868
+ cslhAvailableLimit: 500,
869
+ cslhReferenceDate: /* @__PURE__ */ new Date("2026-03-01"),
870
+ cslhCreatedAt: /* @__PURE__ */ new Date()
871
+ }
872
+ ];
873
+
874
+ // src/utils/mocks/mockCreditAnalysisResult.ts
875
+ var mockCreditAnalysisResult = [
876
+ {
877
+ careId: 1,
878
+ careExternalId: "FARM_001",
879
+ careRequestedLimit: 1e4,
880
+ careApprovedLimit: 5e3,
881
+ careDateSolicitation: /* @__PURE__ */ new Date("2026-03-01T10:00:00Z"),
882
+ careResponseDate: /* @__PURE__ */ new Date("2026-03-01T10:05:00Z"),
883
+ careResponse: true,
884
+ careRequestId: "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
885
+ soliId: 1,
886
+ csrcId: 4
887
+ },
888
+ {
889
+ careId: 2,
890
+ careExternalId: "SUPPLIER_001",
891
+ careRequestedLimit: 5e3,
892
+ careApprovedLimit: 0,
893
+ careDateSolicitation: /* @__PURE__ */ new Date("2026-03-05T14:20:00Z"),
894
+ careResponseDate: /* @__PURE__ */ new Date("2026-03-05T14:21:00Z"),
895
+ careResponse: true,
896
+ careRequestId: "7da7b810-9dad-11d1-80b4-00c04fd430c8",
897
+ soliId: 1,
898
+ csrcId: 2
899
+ }
900
+ ];
901
+
902
+ // src/utils/initMock.ts
903
+ async function initMock() {
904
+ process.env.NODE_ENV = "test";
905
+ const sequelize = Database.getConnection();
906
+ try {
907
+ await initModels();
908
+ await sequelize.query("PRAGMA foreign_keys = OFF");
909
+ await sequelize.sync({ force: true });
910
+ await Person.bulkCreate(mockPerson);
911
+ await Company.bulkCreate(mockCompanies);
912
+ await CreditSource.bulkCreate(mockCreditSources);
913
+ await Solicitation.bulkCreate(mockSolicitation);
914
+ await SolicitationRate.bulkCreate(mockSolicitationRate);
915
+ await RateRules.bulkCreate(mockRateRules);
916
+ await SolicitationRevenue.bulkCreate(mockSolicitationRevenue);
917
+ await SolicitationNf.bulkCreate(mockSolicitationNf);
918
+ await CreditSourceLimitHistory.bulkCreate(mockCreditSourceLimitHistory);
919
+ await CreditAnalysisResult.bulkCreate(mockCreditAnalysisResult);
920
+ await sequelize.query("PRAGMA foreign_keys = ON");
921
+ } catch (error) {
922
+ console.error("Error no initMock:", error);
923
+ }
924
+ }
925
+ async function closeMock() {
926
+ const sequelize = Database.getConnection();
927
+ try {
928
+ console.log("Closing Mock DB...");
929
+ await sequelize.drop();
930
+ } catch (error) {
931
+ console.error(error);
932
+ }
933
+ }
934
+ // Annotate the CommonJS export names for ESM import in node:
935
+ 0 && (module.exports = {
936
+ Company,
937
+ CreditAnalysisResult,
938
+ CreditSource,
939
+ CreditSourceLimitHistory,
940
+ Person,
941
+ RateRules,
942
+ Solicitation,
943
+ SolicitationNf,
944
+ SolicitationRate,
945
+ SolicitationRevenue,
946
+ closeMock,
947
+ initMock,
948
+ initModels
949
+ });