@silexpert/core 1.0.149 → 1.0.151
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.
- package/es/types/Interface/api/commercialManagement/Create.d.ts +1 -0
- package/es/types/Interface/api/commercialManagement/Create.d.ts.map +1 -1
- package/es/types/Interface/api/commercialManagement/Create.js +4 -0
- package/es/types/Interface/api/commercialManagement/Create.js.map +1 -1
- package/es/types/Interface/api/loan/CreateLoan.d.ts +1 -1
- package/es/types/Interface/api/loan/CreateLoan.js +3 -3
- package/es/types/Interface/api/loan/CreateLoan.js.map +1 -1
- package/es/types/Interface/api/loan/UpdateLoan.d.ts +1 -1
- package/es/types/Interface/api/loan/UpdateLoan.js +2 -2
- package/es/types/Interface/api/loan/UpdateLoan.js.map +1 -1
- package/es/types/Interface/models/ILoan.d.ts +1 -1
- package/es/types/Interface/models/ILoan.js.map +1 -1
- package/es/types/Interface/models/ISocietyGescom.d.ts +1 -0
- package/es/types/Interface/models/ISocietyGescom.d.ts.map +1 -1
- package/es/types/Interface/models/ISocietyGescom.js.map +1 -1
- package/es/utils/commercialManagement/document.d.ts.map +1 -1
- package/es/utils/commercialManagement/document.js +1 -1
- package/es/utils/commercialManagement/document.js.map +1 -1
- package/es/utils/commercialManagement/templates/body.d.ts.map +1 -1
- package/es/utils/commercialManagement/templates/body.js +3 -2
- package/es/utils/commercialManagement/templates/body.js.map +1 -1
- package/es/utils/documents.js +1 -1
- package/es/utils/documents.js.map +1 -1
- package/es/utils/siretValidation.d.ts +1 -0
- package/es/utils/siretValidation.d.ts.map +1 -1
- package/es/utils/siretValidation.js +22 -3
- package/es/utils/siretValidation.js.map +1 -1
- package/js/types/Interface/api/commercialManagement/Create.js +3 -0
- package/js/types/Interface/api/commercialManagement/Create.js.map +1 -1
- package/js/types/Interface/api/loan/CreateLoan.js +1 -1
- package/js/types/Interface/api/loan/CreateLoan.js.map +1 -1
- package/js/types/Interface/api/loan/UpdateLoan.js +1 -1
- package/js/types/Interface/api/loan/UpdateLoan.js.map +1 -1
- package/js/types/Interface/models/ILoan.js.map +1 -1
- package/js/types/Interface/models/ISocietyGescom.js.map +1 -1
- package/js/utils/commercialManagement/document.js +2 -1
- package/js/utils/commercialManagement/document.js.map +1 -1
- package/js/utils/commercialManagement/templates/body.js +3 -2
- package/js/utils/commercialManagement/templates/body.js.map +1 -1
- package/js/utils/documents.js +1 -1
- package/js/utils/documents.js.map +1 -1
- package/js/utils/siretValidation.js +21 -3
- package/js/utils/siretValidation.js.map +1 -1
- package/package.json +1 -1
- package/ts/types/Interface/api/commercialManagement/Create.ts +3 -0
- package/ts/types/Interface/api/loan/CreateLoan.ts +3 -3
- package/ts/types/Interface/api/loan/UpdateLoan.ts +2 -2
- package/ts/types/Interface/models/ILoan.ts +1 -1
- package/ts/types/Interface/models/ISocietyGescom.ts +1 -0
- package/ts/utils/commercialManagement/document.ts +1 -0
- package/ts/utils/commercialManagement/templates/body.ts +3 -2
- package/ts/utils/documents.ts +1 -1
- package/ts/utils/siretValidation.ts +23 -3
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
import { isDefined } from 'class-validator';
|
|
2
2
|
import { CountryId } from '../types/Enum/Country';
|
|
3
3
|
|
|
4
|
+
// Function to validate SIREN (9 digits)
|
|
5
|
+
export function validateSiren(siren: string) {
|
|
6
|
+
if (!/^\d{9}$/.test(siren)) throw new Error('Format du SIREN invalide');
|
|
7
|
+
|
|
8
|
+
const sirenArray = Array.from(siren).map(Number).reverse();
|
|
9
|
+
const luhnSum = sirenArray.reduce((acc, v, i) => {
|
|
10
|
+
if (i % 2 === 1) {
|
|
11
|
+
const currentVal = v * 2;
|
|
12
|
+
if (currentVal > 9) {
|
|
13
|
+
const array = Array.from(currentVal.toString());
|
|
14
|
+
return acc + Number(array[0]) + Number(array[1]);
|
|
15
|
+
}
|
|
16
|
+
return acc + currentVal;
|
|
17
|
+
}
|
|
18
|
+
return acc + v;
|
|
19
|
+
}, 0);
|
|
20
|
+
|
|
21
|
+
if (luhnSum % 10 !== 0) throw new Error('SIREN invalide');
|
|
22
|
+
}
|
|
23
|
+
|
|
4
24
|
export function validateSiret(siret: string) {
|
|
5
|
-
if (!/^\d{14}$/.test(siret)) throw new Error('
|
|
25
|
+
if (!/^\d{14}$/.test(siret)) throw new Error('Format du SIRET invalide');
|
|
6
26
|
|
|
7
27
|
const siretArray = Array.from(siret).map(Number).reverse();
|
|
8
28
|
const luhnSum = siretArray.reduce((acc, v, i) => {
|
|
@@ -22,10 +42,10 @@ export function validateSiret(siret: string) {
|
|
|
22
42
|
if (siret.startsWith('356000000')) {
|
|
23
43
|
const sum = siretArray.reduce((acc, v) => acc + v, 0);
|
|
24
44
|
if (sum % 5 !== 0) {
|
|
25
|
-
throw new Error('
|
|
45
|
+
throw new Error('SIRET invalide');
|
|
26
46
|
}
|
|
27
47
|
} else {
|
|
28
|
-
throw new Error('
|
|
48
|
+
throw new Error('SIRET invalide');
|
|
29
49
|
}
|
|
30
50
|
}
|
|
31
51
|
}
|