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.
@@ -1,154 +1,172 @@
1
- import moment from "moment";
2
- import { Type, Shipment, ModifiedOrder, CountriesService, FindNextPickupDate, SellerAddress } from "types";
3
-
4
- type ZonaLLegada = { nombre_pais: string, id_pais: number }
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
- order,
8
- type,
9
- agencyId,
10
- warehouseId,
11
- sellerAddress,
12
- idUsuario,
13
- findNextPickupDate,
14
- countriesService,
14
+ order,
15
+ type,
16
+ agencyId,
17
+ warehouseId,
18
+ sellerAddress,
19
+ idUsuario,
20
+ findNextPickupDate,
21
+ countriesService
15
22
  }: {
16
- order: ModifiedOrder,
17
- type: Type,
18
- agencyId: number,
19
- warehouseId: number,
20
- sellerAddress: SellerAddress,
21
- idUsuario: number,
22
- findNextPickupDate: FindNextPickupDate,
23
- countriesService: CountriesService,
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
- let zonaLLegada = {}
27
-
28
- if (order.codigoPaisLLegada) zonaLLegada = await countriesService.getCountryFromCountryCode(
29
- order.codigoPaisLLegada,
34
+ if (order.codigoPaisLLegada)
35
+ zonaLLegada = await countriesService.getCountryFromCountryCode(
36
+ order.codigoPaisLLegada
30
37
  );
31
38
 
32
- const setDatosVendedor = () => ({
33
- id_usuario: idUsuario,
34
- id_agencia: agencyId,
35
- nom_ape_salida: sellerAddress.nombre,
36
- direccion_salida: sellerAddress.direccion,
37
- cod_pos_salida: sellerAddress.codigo_postal,
38
- poblacion_salida: sellerAddress.poblacion,
39
- provincia_salida: sellerAddress.provincia,
40
- id_zona_salida: sellerAddress.id_zona,
41
- pais_salida: sellerAddress.nombre_pais,
42
- tlf_salida: sellerAddress.telefono,
43
- observaciones_salida: sellerAddress.observaciones,
44
- contacto_salida: sellerAddress.nombre,
45
- mail_salida: sellerAddress.mail,
46
- });
47
-
48
- const setUbicacionComprador = async (order: ModifiedOrder) => {
49
- type CompradorLocation = {
50
- pais_llegada: string | null,
51
- provincia_llegada: string | null,
52
- id_zona_llegada: string | null,
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 setDatosComprador = async (order: ModifiedOrder) => ({
82
- nom_ape_llegada: order.primerApellidoLLegada
83
- ? order.nombreLLegada + " " + order.primerApellidoLLegada
84
- : order.nombreLLegada,
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
- const setFechas = async (order: ModifiedOrder) => {
102
- const date = moment().format("YYYY-MM-DD");
103
- const beginHour = "09:00";
104
- const afterHour = "13:00";
105
-
106
- if (order.codigoPaisLLegada) {
107
- const _zonaLLegada = zonaLLegada as ZonaLLegada
108
- const oDeliveryDate = await findNextPickupDate({
109
- cp_salida: sellerAddress.codigo_postal,
110
- id_pais_origen: sellerAddress.id_pais,
111
- id_pais_destino: _zonaLLegada.id_pais,
112
- idAgencia: agencyId
113
- });
114
-
115
- if (oDeliveryDate) {
116
- const deliveryDateFramgents = oDeliveryDate.fecha_recogida_horas.split(",");
117
- return {
118
- fecha_recogida: deliveryDateFramgents[0],
119
- hora_desde: deliveryDateFramgents[1],
120
- hora_hasta: deliveryDateFramgents[2],
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
- fecha_recogida: date,
127
- hora_desde: beginHour,
128
- hora_hasta: afterHour,
129
+ fecha_recogida: deliveryDateFramgents[0],
130
+ hora_desde: deliveryDateFramgents[1],
131
+ hora_hasta: deliveryDateFramgents[2]
129
132
  };
130
- };
133
+ }
134
+ }
131
135
 
132
- const setBultos = (order: ModifiedOrder) => ({
133
- num_bultos: warehouseId ? 0 : order.lineas.length,
134
- tipo_envio: type,
135
- codigo_envio_externo: order.codigoEnvioExterno,
136
- id_almacen: warehouseId,
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
- const setters = [setDatosVendedor, setDatosComprador, setUbicacionComprador, setReembolso, setFechas, setBultos];
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.4",
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
- "prepublish": "npm run build",
10
- "test": "npm run 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": "^5.4.5"
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
  }