cardus 0.0.4 → 0.0.6
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/.eslintignore +2 -0
- package/.eslintrc +14 -0
- package/.prettierrc +8 -0
- package/dist/index.js +65 -62
- package/dist/insertTempShipment/index.js +30 -21
- package/index.ts +263 -194
- package/insertTempShipment/index.ts +156 -138
- package/package.json +16 -6
- package/types/index.ts +162 -136
|
@@ -1,154 +1,172 @@
|
|
|
1
|
-
import moment from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import {
|
|
3
|
+
Type,
|
|
4
|
+
Shipment,
|
|
5
|
+
ModifiedOrder,
|
|
6
|
+
CountriesService,
|
|
7
|
+
FindNextPickupDate,
|
|
8
|
+
SellerAddress
|
|
9
|
+
} from 'types';
|
|
10
|
+
|
|
11
|
+
type ZonaLLegada = { nombre_pais: string; id_pais: number };
|
|
5
12
|
|
|
6
13
|
export const cookTempShipment = async ({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
order,
|
|
15
|
+
type,
|
|
16
|
+
agencyId,
|
|
17
|
+
warehouseId,
|
|
18
|
+
sellerAddress,
|
|
19
|
+
idUsuario,
|
|
20
|
+
findNextPickupDate,
|
|
21
|
+
countriesService
|
|
15
22
|
}: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
order: ModifiedOrder;
|
|
24
|
+
type: Type;
|
|
25
|
+
agencyId: number;
|
|
26
|
+
warehouseId: number;
|
|
27
|
+
sellerAddress: SellerAddress;
|
|
28
|
+
idUsuario: number;
|
|
29
|
+
findNextPickupDate: FindNextPickupDate;
|
|
30
|
+
countriesService: CountriesService;
|
|
24
31
|
}): Promise<Shipment> => {
|
|
32
|
+
let zonaLLegada = {};
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
order.codigoPaisLLegada,
|
|
34
|
+
if (order.codigoPaisLLegada)
|
|
35
|
+
zonaLLegada = await countriesService.getCountryFromCountryCode(
|
|
36
|
+
order.codigoPaisLLegada
|
|
30
37
|
);
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const compradorLocation: CompradorLocation = {
|
|
56
|
-
pais_llegada: null,
|
|
57
|
-
provincia_llegada: null,
|
|
58
|
-
id_zona_llegada: null,
|
|
59
|
-
};
|
|
60
|
-
if (order.codigoPaisLLegada) {
|
|
61
|
-
const _zonaLLegada = zonaLLegada as ZonaLLegada
|
|
62
|
-
compradorLocation.pais_llegada = _zonaLLegada?.nombre_pais || null;
|
|
63
|
-
|
|
64
|
-
if (_zonaLLegada?.id_pais && order.codigoPostalLLegada) {
|
|
65
|
-
const oTempShipmentProvincia = await countriesService.getProvinceByCountryIdAndPostalCode(
|
|
66
|
-
_zonaLLegada.id_pais,
|
|
67
|
-
order.codigoPostalLLegada,
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
compradorLocation.provincia_llegada = oTempShipmentProvincia?.nombre_provincia || null;
|
|
71
|
-
|
|
72
|
-
compradorLocation.id_zona_llegada = await countriesService.getZoneIdByCountryIdAndPostalCode(
|
|
73
|
-
_zonaLLegada.id_pais,
|
|
74
|
-
order.codigoPostalLLegada,
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return compradorLocation;
|
|
39
|
+
const setDatosVendedor = () => ({
|
|
40
|
+
id_usuario: idUsuario,
|
|
41
|
+
id_agencia: agencyId,
|
|
42
|
+
nom_ape_salida: sellerAddress.nombre,
|
|
43
|
+
direccion_salida: sellerAddress.direccion,
|
|
44
|
+
cod_pos_salida: sellerAddress.codigo_postal,
|
|
45
|
+
poblacion_salida: sellerAddress.poblacion,
|
|
46
|
+
provincia_salida: sellerAddress.provincia,
|
|
47
|
+
id_zona_salida: sellerAddress.id_zona,
|
|
48
|
+
pais_salida: sellerAddress.nombre_pais,
|
|
49
|
+
tlf_salida: sellerAddress.telefono,
|
|
50
|
+
observaciones_salida: sellerAddress.observaciones,
|
|
51
|
+
contacto_salida: sellerAddress.nombre,
|
|
52
|
+
mail_salida: sellerAddress.mail
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const setUbicacionComprador = async (order: ModifiedOrder) => {
|
|
56
|
+
type CompradorLocation = {
|
|
57
|
+
pais_llegada: string | null;
|
|
58
|
+
provincia_llegada: string | null;
|
|
59
|
+
id_zona_llegada: string | null;
|
|
79
60
|
};
|
|
80
61
|
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
contacto_llegada: order.primerApellidoLLegada
|
|
86
|
-
? order.nombreLLegada + " " + order.primerApellidoLLegada
|
|
87
|
-
: order.nombreLLegada,
|
|
88
|
-
direccion_llegada: order.direccionLLegada2
|
|
89
|
-
? order.direccionLLegada1 + " " + order.direccionLLegada2
|
|
90
|
-
: order.direccionLLegada1,
|
|
91
|
-
cod_pos_llegada: order.codigoPostalLLegada,
|
|
92
|
-
poblacion_llegada: order.ciudadLLegada,
|
|
93
|
-
tlf_llegada: order.telefonoLLegada || "no informado",
|
|
94
|
-
mail_llegada: order.emailLLegada || "no informado",
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
const setReembolso = (order: ModifiedOrder) => {
|
|
98
|
-
return { cantidad_contrareembolso: order.cantidadContrareembolso };
|
|
62
|
+
const compradorLocation: CompradorLocation = {
|
|
63
|
+
pais_llegada: null,
|
|
64
|
+
provincia_llegada: null,
|
|
65
|
+
id_zona_llegada: null
|
|
99
66
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
67
|
+
if (order.codigoPaisLLegada) {
|
|
68
|
+
const _zonaLLegada = zonaLLegada as ZonaLLegada;
|
|
69
|
+
compradorLocation.pais_llegada = _zonaLLegada?.nombre_pais || null;
|
|
70
|
+
|
|
71
|
+
if (_zonaLLegada?.id_pais && order.codigoPostalLLegada) {
|
|
72
|
+
const oTempShipmentProvincia =
|
|
73
|
+
await countriesService.getProvinceByCountryIdAndPostalCode(
|
|
74
|
+
_zonaLLegada.id_pais,
|
|
75
|
+
order.codigoPostalLLegada
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
compradorLocation.provincia_llegada =
|
|
79
|
+
oTempShipmentProvincia?.nombre_provincia || null;
|
|
80
|
+
|
|
81
|
+
compradorLocation.id_zona_llegada =
|
|
82
|
+
await countriesService.getZoneIdByCountryIdAndPostalCode(
|
|
83
|
+
_zonaLLegada.id_pais,
|
|
84
|
+
order.codigoPostalLLegada
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return compradorLocation;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const setDatosComprador = async (order: ModifiedOrder) => ({
|
|
92
|
+
nom_ape_llegada: order.primerApellidoLLegada
|
|
93
|
+
? order.nombreLLegada + ' ' + order.primerApellidoLLegada
|
|
94
|
+
: order.nombreLLegada,
|
|
95
|
+
contacto_llegada: order.primerApellidoLLegada
|
|
96
|
+
? order.nombreLLegada + ' ' + order.primerApellidoLLegada
|
|
97
|
+
: order.nombreLLegada,
|
|
98
|
+
direccion_llegada: order.direccionLLegada2
|
|
99
|
+
? order.direccionLLegada1 + ' ' + order.direccionLLegada2
|
|
100
|
+
: order.direccionLLegada1,
|
|
101
|
+
cod_pos_llegada: order.codigoPostalLLegada,
|
|
102
|
+
poblacion_llegada: order.ciudadLLegada,
|
|
103
|
+
tlf_llegada: order.telefonoLLegada || 'no informado',
|
|
104
|
+
mail_llegada: order.emailLLegada || 'no informado'
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const setReembolso = (order: ModifiedOrder) => {
|
|
108
|
+
return { cantidad_contrareembolso: order.cantidadContrareembolso };
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const setFechas = async (order: ModifiedOrder) => {
|
|
112
|
+
const date = moment().format('YYYY-MM-DD');
|
|
113
|
+
const beginHour = '09:00';
|
|
114
|
+
const afterHour = '13:00';
|
|
115
|
+
|
|
116
|
+
if (order.codigoPaisLLegada) {
|
|
117
|
+
const _zonaLLegada = zonaLLegada as ZonaLLegada;
|
|
118
|
+
const oDeliveryDate = await findNextPickupDate({
|
|
119
|
+
cp_salida: sellerAddress.codigo_postal,
|
|
120
|
+
id_pais_origen: sellerAddress.id_pais,
|
|
121
|
+
id_pais_destino: _zonaLLegada.id_pais,
|
|
122
|
+
idAgencia: agencyId
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (oDeliveryDate) {
|
|
126
|
+
const deliveryDateFramgents =
|
|
127
|
+
oDeliveryDate.fecha_recogida_horas.split(',');
|
|
125
128
|
return {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
fecha_recogida: deliveryDateFramgents[0],
|
|
130
|
+
hora_desde: deliveryDateFramgents[1],
|
|
131
|
+
hora_hasta: deliveryDateFramgents[2]
|
|
129
132
|
};
|
|
130
|
-
|
|
133
|
+
}
|
|
134
|
+
}
|
|
131
135
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
return {
|
|
137
|
+
fecha_recogida: date,
|
|
138
|
+
hora_desde: beginHour,
|
|
139
|
+
hora_hasta: afterHour
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const setBultos = (order: ModifiedOrder) => ({
|
|
144
|
+
num_bultos: warehouseId ? 0 : order.lineas.length,
|
|
145
|
+
tipo_envio: type,
|
|
146
|
+
codigo_envio_externo: order.codigoEnvioExterno,
|
|
147
|
+
id_almacen: warehouseId
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const setters = [
|
|
151
|
+
setDatosVendedor,
|
|
152
|
+
setDatosComprador,
|
|
153
|
+
setUbicacionComprador,
|
|
154
|
+
setReembolso,
|
|
155
|
+
setFechas,
|
|
156
|
+
setBultos
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
const dataInsert = (await setters.reduce(async (acc, curr) => {
|
|
160
|
+
const accumulated = await acc;
|
|
161
|
+
const stepResult = await curr({
|
|
162
|
+
...order,
|
|
163
|
+
...accumulated
|
|
137
164
|
});
|
|
165
|
+
return {
|
|
166
|
+
...accumulated,
|
|
167
|
+
...stepResult
|
|
168
|
+
};
|
|
169
|
+
}, {})) as Shipment;
|
|
138
170
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const dataInsert = await setters.reduce(async (acc, curr) => {
|
|
142
|
-
const accumulated = await acc;
|
|
143
|
-
const stepResult = await curr({
|
|
144
|
-
...order,
|
|
145
|
-
...accumulated,
|
|
146
|
-
});
|
|
147
|
-
return {
|
|
148
|
-
...accumulated,
|
|
149
|
-
...stepResult,
|
|
150
|
-
};
|
|
151
|
-
}, {}) as Shipment;
|
|
152
|
-
|
|
153
|
-
return dataInsert;
|
|
171
|
+
return dataInsert;
|
|
154
172
|
};
|
package/package.json
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cardus",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "an integration manager",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "rm -rf dist && tsc --build",
|
|
9
|
-
"
|
|
10
|
-
"test": "
|
|
8
|
+
"build": "rm -rf dist && tsc --build & npm run lint",
|
|
9
|
+
"prepublishOnly": "npm run build",
|
|
10
|
+
"test": "jest",
|
|
11
|
+
"lint": "eslint --ignore-path .eslintignore --ext .js,.ts && npm run format",
|
|
12
|
+
"format": "prettier --config .prettierrc './**/*.ts' --write"
|
|
11
13
|
},
|
|
12
14
|
"author": "sergio ibanez",
|
|
13
15
|
"license": "ISC",
|
|
14
16
|
"devDependencies": {
|
|
17
|
+
"@eslint/js": "^9.1.1",
|
|
15
18
|
"@types/node": "^20.12.7",
|
|
16
|
-
"typescript": "^
|
|
19
|
+
"@typescript-eslint/eslint-plugin": "^7.7.1",
|
|
20
|
+
"@typescript-eslint/parser": "^7.7.1",
|
|
21
|
+
"eslint": "^8.57.0",
|
|
22
|
+
"globals": "^15.0.0",
|
|
23
|
+
"jest": "^29.7.0",
|
|
24
|
+
"typescript": "^5.4.5",
|
|
25
|
+
"typescript-eslint": "^7.7.1"
|
|
17
26
|
},
|
|
18
27
|
"dependencies": {
|
|
19
|
-
"moment": "^2.30.1"
|
|
28
|
+
"moment": "^2.30.1",
|
|
29
|
+
"prettier": "^3.2.5"
|
|
20
30
|
}
|
|
21
31
|
}
|