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