cardus 0.0.18 → 0.0.20
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/dist/index.js +216 -0
- package/dist/insertTempShipment/index.js +123 -0
- package/dist/types/index.js +26 -0
- package/index.ts +16 -7
- package/insertTempShipment/index.ts +12 -2
- package/package.json +3 -3
- package/types/index.ts +19 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.IntegrationManager = void 0;
|
|
16
|
+
const moment_1 = __importDefault(require("moment"));
|
|
17
|
+
const insertTempShipment_1 = require("./insertTempShipment");
|
|
18
|
+
class IntegrationManager {
|
|
19
|
+
constructor(params) {
|
|
20
|
+
this.insertOrder = (_a) => __awaiter(this, [_a], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario, group }) {
|
|
21
|
+
const idEnvioTemporal = yield this.insertTempShipment({
|
|
22
|
+
order,
|
|
23
|
+
agencyId,
|
|
24
|
+
warehouseId,
|
|
25
|
+
sellerAddress,
|
|
26
|
+
idUsuario
|
|
27
|
+
});
|
|
28
|
+
if (!idEnvioTemporal)
|
|
29
|
+
throw new Error('Temp shipments could not be created');
|
|
30
|
+
yield this.insertExternalShipment({
|
|
31
|
+
idUsuario,
|
|
32
|
+
order,
|
|
33
|
+
idEnvioTemporal
|
|
34
|
+
});
|
|
35
|
+
const grouped = Number((group === null || group === void 0 ? void 0 : group.grouped) === 1);
|
|
36
|
+
if (grouped)
|
|
37
|
+
yield this.insertTempShipmentLines({ idEnvioTemporal, group });
|
|
38
|
+
return Object.assign(order, { idEnvioTemporal });
|
|
39
|
+
});
|
|
40
|
+
this.insertTempShipment = (_b) => __awaiter(this, [_b], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario }) {
|
|
41
|
+
const tempShipmentData = yield (0, insertTempShipment_1.cookTempShipment)({
|
|
42
|
+
order,
|
|
43
|
+
shipmentType: this.shipmentType,
|
|
44
|
+
agencyId,
|
|
45
|
+
warehouseId,
|
|
46
|
+
sellerAddress,
|
|
47
|
+
idUsuario,
|
|
48
|
+
findNextPickupDate: this.findNextPickupDate,
|
|
49
|
+
countriesService: this.services.countriesService
|
|
50
|
+
});
|
|
51
|
+
return yield this.services.integrationsService.insertTempShipment(tempShipmentData);
|
|
52
|
+
});
|
|
53
|
+
this.insertExternalShipment = (_c) => __awaiter(this, [_c], void 0, function* ({ idUsuario, order, idEnvioTemporal }) {
|
|
54
|
+
const idEnvioExterno = yield this.services.integrationsService.insertExternalShipment({
|
|
55
|
+
id_envio_temporal_usuario: idEnvioTemporal,
|
|
56
|
+
codigo_envio_externo: order.codigoEnvioExterno,
|
|
57
|
+
id_usuario: idUsuario,
|
|
58
|
+
fecha_hora_creacion: (0, moment_1.default)().format('YYYY-MM-DD HH:mm:ss'),
|
|
59
|
+
servicio: this.type,
|
|
60
|
+
id_interno_shopify: order.idInternoShopify,
|
|
61
|
+
fecha_creacion_externa: (0, moment_1.default)(order === null || order === void 0 ? void 0 : order.fecha_creacion_externa).isValid() ? (0, moment_1.default)(order.fecha_creacion_externa).format("YYYY-MM-DD HH:mm:ss") : null
|
|
62
|
+
});
|
|
63
|
+
return idEnvioExterno;
|
|
64
|
+
});
|
|
65
|
+
this.insertTempShipmentLines = (_d) => __awaiter(this, [_d], void 0, function* ({ idEnvioTemporal, group }) {
|
|
66
|
+
const grouped = group.grouped === 1 || group.grouped === '1';
|
|
67
|
+
if (grouped)
|
|
68
|
+
yield this.services.integrationsService.insertTempShipmentLines({
|
|
69
|
+
id_envio: idEnvioTemporal,
|
|
70
|
+
bulto: {
|
|
71
|
+
peso: group.weight,
|
|
72
|
+
alto: group.height,
|
|
73
|
+
ancho: group.width,
|
|
74
|
+
largo: group.length
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
this.services = {
|
|
79
|
+
integrationsService: params.integrationsService,
|
|
80
|
+
addressesService: params.addressesService,
|
|
81
|
+
countriesService: params.countriesService,
|
|
82
|
+
configurationService: params.configurationService,
|
|
83
|
+
usersService: params.usersService
|
|
84
|
+
};
|
|
85
|
+
this.shipmentType = params.shipmentType;
|
|
86
|
+
this.type = params.type;
|
|
87
|
+
this.executionManager = params.executionManager;
|
|
88
|
+
this.findNextPickupDate = params.findNextPickupDate;
|
|
89
|
+
}
|
|
90
|
+
insertTempShipments(_a) {
|
|
91
|
+
return __awaiter(this, arguments, void 0, function* ({ payload: { idUsuario, agencyId, addressId, warehouseId, group }, fetchAllOrders, crearBulto, modificarOrdenOriginal }) {
|
|
92
|
+
const estaAgrupado = Number(group === null || group === void 0 ? void 0 : group.grouped) === 1;
|
|
93
|
+
const { integrationsService, addressesService } = this.services;
|
|
94
|
+
// esto hay que pasarlo ya en los parametros
|
|
95
|
+
const sellerAddress = warehouseId > 0
|
|
96
|
+
? yield addressesService.getWarehouseAddress(idUsuario)
|
|
97
|
+
: yield addressesService.getAddress(addressId, idUsuario);
|
|
98
|
+
const allOrders = yield fetchAllOrders();
|
|
99
|
+
const filteredOrders = yield integrationsService.filterExternalDuplicatedOrders({
|
|
100
|
+
idUsuario,
|
|
101
|
+
orders: allOrders,
|
|
102
|
+
type: this.type
|
|
103
|
+
});
|
|
104
|
+
const insertOrdersResult = yield new this.executionManager({
|
|
105
|
+
arrayParams: allOrders,
|
|
106
|
+
executable: (order) => __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const parsedOrder = yield modificarOrdenOriginal({
|
|
108
|
+
originalOrder: order
|
|
109
|
+
});
|
|
110
|
+
const duplicatedTempShipment = yield integrationsService.checkDuplicateTempShipment(parsedOrder.codigoEnvioExterno, idUsuario);
|
|
111
|
+
if (duplicatedTempShipment)
|
|
112
|
+
throw new Error('Envio Duplicado');
|
|
113
|
+
return this.insertOrder({
|
|
114
|
+
order: parsedOrder,
|
|
115
|
+
agencyId,
|
|
116
|
+
warehouseId,
|
|
117
|
+
sellerAddress,
|
|
118
|
+
idUsuario,
|
|
119
|
+
group
|
|
120
|
+
});
|
|
121
|
+
}),
|
|
122
|
+
regularExecutionTime: 100, // ms
|
|
123
|
+
initialBatchQuantity: 5 // de cinco en cinco
|
|
124
|
+
}).upload();
|
|
125
|
+
const successfullShipments = insertOrdersResult
|
|
126
|
+
.filter(Boolean)
|
|
127
|
+
.filter((each) => each.status === 'fulfilled')
|
|
128
|
+
.map((each) => each.value);
|
|
129
|
+
yield this.insertQuantityRelatedLines({
|
|
130
|
+
orders: successfullShipments,
|
|
131
|
+
idUsuario,
|
|
132
|
+
crearBulto,
|
|
133
|
+
estaAgrupado
|
|
134
|
+
});
|
|
135
|
+
yield this.insertUserDefaultConfigurationContent({
|
|
136
|
+
idUsuario,
|
|
137
|
+
tempShimpmentIds: successfullShipments.map((successfullShipment) => successfullShipment.idEnvioTemporal)
|
|
138
|
+
});
|
|
139
|
+
return filteredOrders;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
insertUserDefaultConfigurationContent(_a) {
|
|
143
|
+
return __awaiter(this, arguments, void 0, function* ({ idUsuario, tempShimpmentIds }) {
|
|
144
|
+
const { usersService, configurationService, integrationsService } = this.services;
|
|
145
|
+
const insert = (data, tempShimpmentId) => __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
return Promise.allSettled(data.map((tempContent) => __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
yield integrationsService.insertTempContent(Object.assign(Object.assign({}, tempContent), { id_envio: tempShimpmentId }));
|
|
148
|
+
})));
|
|
149
|
+
});
|
|
150
|
+
const insertOrdersResult = yield new this.executionManager({
|
|
151
|
+
arrayParams: tempShimpmentIds,
|
|
152
|
+
executable: (order) => __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) || [];
|
|
154
|
+
if (userSavedData.length > 0) {
|
|
155
|
+
yield insert(userSavedData, order);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
const user = yield usersService.obtenerUsuarioId(idUsuario);
|
|
159
|
+
const userFakeData = configurationService.getFakeDefaultProformaConfiguration(idUsuario, user.dni);
|
|
160
|
+
yield insert(userFakeData, order);
|
|
161
|
+
}
|
|
162
|
+
}),
|
|
163
|
+
regularExecutionTime: 100, // ms
|
|
164
|
+
initialBatchQuantity: 5 // de cinco en cinco
|
|
165
|
+
}).upload();
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
insertQuantityRelatedLines(_a) {
|
|
169
|
+
return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, estaAgrupado }) {
|
|
170
|
+
const { integrationsService } = this.services;
|
|
171
|
+
const quantityRelatedFunctions = [];
|
|
172
|
+
const obtenerBultosYCantidades = orders.map((_b) => __awaiter(this, [_b], void 0, function* ({ idEnvioTemporal, lineas }) {
|
|
173
|
+
if (!idEnvioTemporal)
|
|
174
|
+
return null;
|
|
175
|
+
return yield Promise.all(lineas.map((line) => __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const { bulto, cantidad = 0 } = yield crearBulto({
|
|
177
|
+
lineItems: { idEnvioTemporal, line },
|
|
178
|
+
idUsuario
|
|
179
|
+
});
|
|
180
|
+
if (cantidad === 0)
|
|
181
|
+
return null;
|
|
182
|
+
return { bulto, cantidad, idEnvioTemporal };
|
|
183
|
+
})));
|
|
184
|
+
}));
|
|
185
|
+
const bultosYCantidades = (yield new Promise((res) => __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
const bultosYCantidadesAnidados = yield Promise.all(obtenerBultosYCantidades);
|
|
187
|
+
const bultosYCantidades = bultosYCantidadesAnidados
|
|
188
|
+
.flat()
|
|
189
|
+
.filter(Boolean);
|
|
190
|
+
res(bultosYCantidades);
|
|
191
|
+
})));
|
|
192
|
+
bultosYCantidades.forEach(({ bulto, cantidad, idEnvioTemporal }) => {
|
|
193
|
+
try {
|
|
194
|
+
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
195
|
+
arrayFake.forEach(() => {
|
|
196
|
+
if (!estaAgrupado) {
|
|
197
|
+
quantityRelatedFunctions.push(integrationsService.insertTempShipmentLines({
|
|
198
|
+
id_envio: idEnvioTemporal,
|
|
199
|
+
bulto
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
quantityRelatedFunctions.push(integrationsService.insertTempDetailsShipment({
|
|
203
|
+
id_envio: idEnvioTemporal,
|
|
204
|
+
bulto
|
|
205
|
+
}));
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
catch (e) {
|
|
209
|
+
console.log(e);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
yield Promise.allSettled(quantityRelatedFunctions);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.IntegrationManager = IntegrationManager;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.cookTempShipment = void 0;
|
|
16
|
+
const moment_1 = __importDefault(require("moment"));
|
|
17
|
+
const cookTempShipment = (_a) => __awaiter(void 0, [_a], void 0, function* ({ order, shipmentType, agencyId, warehouseId, sellerAddress, idUsuario, findNextPickupDate, countriesService }) {
|
|
18
|
+
let zonaLLegada = {};
|
|
19
|
+
if (order.codigoPaisLLegada)
|
|
20
|
+
zonaLLegada = yield countriesService.getCountryFromCountryCode(order.codigoPaisLLegada);
|
|
21
|
+
const setDatosVendedor = () => ({
|
|
22
|
+
id_usuario: idUsuario,
|
|
23
|
+
id_agencia: agencyId,
|
|
24
|
+
nom_ape_salida: sellerAddress.nombre,
|
|
25
|
+
direccion_salida: sellerAddress.direccion,
|
|
26
|
+
cod_pos_salida: sellerAddress.codigo_postal,
|
|
27
|
+
poblacion_salida: sellerAddress.poblacion,
|
|
28
|
+
provincia_salida: sellerAddress.provincia,
|
|
29
|
+
id_zona_salida: sellerAddress.id_zona,
|
|
30
|
+
pais_salida: sellerAddress.nombre_pais,
|
|
31
|
+
tlf_salida: sellerAddress.telefono,
|
|
32
|
+
observaciones_salida: sellerAddress.observaciones,
|
|
33
|
+
contacto_salida: sellerAddress.nombre,
|
|
34
|
+
mail_salida: sellerAddress.mail
|
|
35
|
+
});
|
|
36
|
+
const setUbicacionComprador = (order) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const compradorLocation = {
|
|
38
|
+
pais_llegada: null,
|
|
39
|
+
provincia_llegada: null,
|
|
40
|
+
id_zona_llegada: null
|
|
41
|
+
};
|
|
42
|
+
if (order.codigoPaisLLegada) {
|
|
43
|
+
const _zonaLLegada = zonaLLegada;
|
|
44
|
+
compradorLocation.pais_llegada = (_zonaLLegada === null || _zonaLLegada === void 0 ? void 0 : _zonaLLegada.nombre_pais) || null;
|
|
45
|
+
if ((_zonaLLegada === null || _zonaLLegada === void 0 ? void 0 : _zonaLLegada.id_pais) && order.codigoPostalLLegada) {
|
|
46
|
+
const oTempShipmentProvincia = yield countriesService.getProvinceByCountryIdAndPostalCode(_zonaLLegada.id_pais, order.codigoPostalLLegada);
|
|
47
|
+
compradorLocation.provincia_llegada =
|
|
48
|
+
(oTempShipmentProvincia === null || oTempShipmentProvincia === void 0 ? void 0 : oTempShipmentProvincia.nombre_provincia) || null;
|
|
49
|
+
compradorLocation.id_zona_llegada =
|
|
50
|
+
yield countriesService.getZoneIdByCountryIdAndPostalCode(_zonaLLegada.id_pais, order.codigoPostalLLegada);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return compradorLocation;
|
|
54
|
+
});
|
|
55
|
+
const setDatosComprador = (order) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
return ({
|
|
57
|
+
nom_ape_llegada: order.primerApellidoLLegada
|
|
58
|
+
? order.nombreLLegada + ' ' + order.primerApellidoLLegada
|
|
59
|
+
: order.nombreLLegada,
|
|
60
|
+
contacto_llegada: order.primerApellidoLLegada
|
|
61
|
+
? order.nombreLLegada + ' ' + order.primerApellidoLLegada
|
|
62
|
+
: order.nombreLLegada,
|
|
63
|
+
direccion_llegada: order.direccionLLegada2
|
|
64
|
+
? order.direccionLLegada1 + ' ' + order.direccionLLegada2
|
|
65
|
+
: order.direccionLLegada1,
|
|
66
|
+
cod_pos_llegada: order.codigoPostalLLegada,
|
|
67
|
+
poblacion_llegada: order.ciudadLLegada,
|
|
68
|
+
tlf_llegada: order.telefonoLLegada || 'no informado',
|
|
69
|
+
mail_llegada: order.emailLLegada || 'no informado'
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
const setReembolso = (order) => {
|
|
73
|
+
return { cantidad_contrareembolso: order.cantidadContrareembolso };
|
|
74
|
+
};
|
|
75
|
+
const setFechas = (order) => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
+
const date = (0, moment_1.default)().format('YYYY-MM-DD');
|
|
77
|
+
const beginHour = '09:00';
|
|
78
|
+
const afterHour = '13:00';
|
|
79
|
+
if (order.codigoPaisLLegada) {
|
|
80
|
+
const _zonaLLegada = zonaLLegada;
|
|
81
|
+
const oDeliveryDate = yield findNextPickupDate({
|
|
82
|
+
cp_salida: sellerAddress.codigo_postal,
|
|
83
|
+
id_pais_origen: sellerAddress.id_pais,
|
|
84
|
+
id_pais_destino: _zonaLLegada.id_pais,
|
|
85
|
+
idAgencia: agencyId
|
|
86
|
+
});
|
|
87
|
+
if (oDeliveryDate) {
|
|
88
|
+
const deliveryDateFramgents = oDeliveryDate.fecha_recogida_horas.split(',');
|
|
89
|
+
return {
|
|
90
|
+
fecha_recogida: deliveryDateFramgents[0],
|
|
91
|
+
hora_desde: deliveryDateFramgents[1],
|
|
92
|
+
hora_hasta: deliveryDateFramgents[2]
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
fecha_recogida: date,
|
|
98
|
+
hora_desde: beginHour,
|
|
99
|
+
hora_hasta: afterHour
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
const setBultos = (order) => ({
|
|
103
|
+
num_bultos: warehouseId ? 0 : order.lineas.length,
|
|
104
|
+
tipo_envio: shipmentType,
|
|
105
|
+
codigo_envio_externo: order.codigoEnvioExterno,
|
|
106
|
+
id_almacen: warehouseId
|
|
107
|
+
});
|
|
108
|
+
const setters = [
|
|
109
|
+
setDatosVendedor,
|
|
110
|
+
setDatosComprador,
|
|
111
|
+
setUbicacionComprador,
|
|
112
|
+
setReembolso,
|
|
113
|
+
setFechas,
|
|
114
|
+
setBultos
|
|
115
|
+
];
|
|
116
|
+
const dataInsert = (yield setters.reduce((acc, curr) => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
const accumulated = yield acc;
|
|
118
|
+
const stepResult = yield curr(Object.assign(Object.assign({}, order), accumulated));
|
|
119
|
+
return Object.assign(Object.assign({}, accumulated), stepResult);
|
|
120
|
+
}), {}));
|
|
121
|
+
return dataInsert;
|
|
122
|
+
});
|
|
123
|
+
exports.cookTempShipment = cookTempShipment;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const shipmentTypes = {
|
|
4
|
+
NORMAL: 1,
|
|
5
|
+
EXCEL: 7,
|
|
6
|
+
RECTIFICATIVO: 8,
|
|
7
|
+
PRESTASHOP_MODULE: 15,
|
|
8
|
+
API: 16,
|
|
9
|
+
EBAY: 17,
|
|
10
|
+
ABONO: 18,
|
|
11
|
+
WOOCOMMERCE: 19,
|
|
12
|
+
ALIEXPRESS: 22,
|
|
13
|
+
SHOPIFY: 23,
|
|
14
|
+
ECWID: 31,
|
|
15
|
+
CARGOS: 40,
|
|
16
|
+
DAILY_PICKUP: 50,
|
|
17
|
+
FLASH_SHIPMENT: 51,
|
|
18
|
+
WITHDRAWALL: 52,
|
|
19
|
+
SHIPMENT_SCHEME: 53,
|
|
20
|
+
PRESTASHOP: 115,
|
|
21
|
+
AMAZON: 118,
|
|
22
|
+
JOOM: 119,
|
|
23
|
+
HOLDED: 120,
|
|
24
|
+
ETSY: 121,
|
|
25
|
+
NORMAL_V2: 122
|
|
26
|
+
};
|
package/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import moment from 'moment';
|
|
2
|
+
|
|
2
3
|
import { cookTempShipment } from './insertTempShipment';
|
|
4
|
+
|
|
3
5
|
import {
|
|
4
6
|
ModifiedOrderExtended,
|
|
5
7
|
CrearBulto,
|
|
@@ -53,6 +55,7 @@ export class IntegrationManager {
|
|
|
53
55
|
configurationService: params.configurationService,
|
|
54
56
|
usersService: params.usersService
|
|
55
57
|
};
|
|
58
|
+
|
|
56
59
|
this.shipmentType = params.shipmentType;
|
|
57
60
|
this.type = params.type;
|
|
58
61
|
this.executionManager = params.executionManager;
|
|
@@ -74,7 +77,6 @@ export class IntegrationManager {
|
|
|
74
77
|
: await addressesService.getAddress(addressId, idUsuario);
|
|
75
78
|
|
|
76
79
|
const allOrders = await fetchAllOrders();
|
|
77
|
-
|
|
78
80
|
const filteredOrders =
|
|
79
81
|
await integrationsService.filterExternalDuplicatedOrders({
|
|
80
82
|
idUsuario,
|
|
@@ -88,6 +90,7 @@ export class IntegrationManager {
|
|
|
88
90
|
const parsedOrder = await modificarOrdenOriginal({
|
|
89
91
|
originalOrder: order
|
|
90
92
|
});
|
|
93
|
+
|
|
91
94
|
const duplicatedTempShipment =
|
|
92
95
|
await integrationsService.checkDuplicateTempShipment(
|
|
93
96
|
parsedOrder.codigoEnvioExterno,
|
|
@@ -139,6 +142,7 @@ export class IntegrationManager {
|
|
|
139
142
|
}) {
|
|
140
143
|
const { usersService, configurationService, integrationsService } =
|
|
141
144
|
this.services;
|
|
145
|
+
|
|
142
146
|
const insert = async (
|
|
143
147
|
data: UserDefaultConfigurationContent[],
|
|
144
148
|
tempShimpmentId: number
|
|
@@ -147,13 +151,16 @@ export class IntegrationManager {
|
|
|
147
151
|
data.map(async (tempContent) => {
|
|
148
152
|
await integrationsService.insertTempContent({
|
|
149
153
|
...tempContent,
|
|
154
|
+
|
|
150
155
|
id_envio: tempShimpmentId
|
|
151
156
|
});
|
|
152
157
|
})
|
|
153
158
|
);
|
|
154
159
|
};
|
|
160
|
+
|
|
155
161
|
const insertOrdersResult = await new this.executionManager({
|
|
156
162
|
arrayParams: tempShimpmentIds,
|
|
163
|
+
|
|
157
164
|
executable: async (order: any) => {
|
|
158
165
|
const userSavedData =
|
|
159
166
|
(await configurationService.getDefaultProformaConfiguration(
|
|
@@ -169,7 +176,6 @@ export class IntegrationManager {
|
|
|
169
176
|
idUsuario,
|
|
170
177
|
user.dni
|
|
171
178
|
);
|
|
172
|
-
|
|
173
179
|
await insert(userFakeData, order);
|
|
174
180
|
}
|
|
175
181
|
},
|
|
@@ -211,9 +217,7 @@ export class IntegrationManager {
|
|
|
211
217
|
});
|
|
212
218
|
|
|
213
219
|
const grouped = Number(group?.grouped === 1);
|
|
214
|
-
|
|
215
220
|
if (grouped) await this.insertTempShipmentLines({ idEnvioTemporal, group });
|
|
216
|
-
|
|
217
221
|
return Object.assign(order, { idEnvioTemporal });
|
|
218
222
|
};
|
|
219
223
|
|
|
@@ -240,6 +244,7 @@ export class IntegrationManager {
|
|
|
240
244
|
findNextPickupDate: this.findNextPickupDate,
|
|
241
245
|
countriesService: this.services.countriesService
|
|
242
246
|
});
|
|
247
|
+
|
|
243
248
|
return await this.services.integrationsService.insertTempShipment(
|
|
244
249
|
tempShipmentData
|
|
245
250
|
);
|
|
@@ -261,7 +266,8 @@ export class IntegrationManager {
|
|
|
261
266
|
id_usuario: idUsuario,
|
|
262
267
|
fecha_hora_creacion: moment().format('YYYY-MM-DD HH:mm:ss'),
|
|
263
268
|
servicio: this.type,
|
|
264
|
-
id_interno_shopify: order.idInternoShopify
|
|
269
|
+
id_interno_shopify: order.idInternoShopify,
|
|
270
|
+
fecha_creacion_externa: moment(order?.fecha_creacion_externa).isValid() ? moment(order.fecha_creacion_externa).format("YYYY-MM-DD HH:mm:ss") : null
|
|
265
271
|
});
|
|
266
272
|
|
|
267
273
|
return idEnvioExterno;
|
|
@@ -275,6 +281,7 @@ export class IntegrationManager {
|
|
|
275
281
|
group: Group;
|
|
276
282
|
}) => {
|
|
277
283
|
const grouped = group.grouped === 1 || group.grouped === '1';
|
|
284
|
+
|
|
278
285
|
if (grouped)
|
|
279
286
|
await this.services.integrationsService.insertTempShipmentLines({
|
|
280
287
|
id_envio: idEnvioTemporal,
|
|
@@ -310,9 +317,7 @@ export class IntegrationManager {
|
|
|
310
317
|
lineItems: { idEnvioTemporal, line },
|
|
311
318
|
idUsuario
|
|
312
319
|
});
|
|
313
|
-
|
|
314
320
|
if (cantidad === 0) return null;
|
|
315
|
-
|
|
316
321
|
return { bulto, cantidad, idEnvioTemporal };
|
|
317
322
|
})
|
|
318
323
|
);
|
|
@@ -323,20 +328,24 @@ export class IntegrationManager {
|
|
|
323
328
|
const bultosYCantidadesAnidados = await Promise.all(
|
|
324
329
|
obtenerBultosYCantidades
|
|
325
330
|
);
|
|
331
|
+
|
|
326
332
|
const bultosYCantidades = bultosYCantidadesAnidados
|
|
327
333
|
.flat()
|
|
328
334
|
.filter(Boolean);
|
|
335
|
+
|
|
329
336
|
res(bultosYCantidades);
|
|
330
337
|
})) as Array<any>;
|
|
331
338
|
|
|
332
339
|
bultosYCantidades.forEach(({ bulto, cantidad, idEnvioTemporal }) => {
|
|
333
340
|
try {
|
|
334
341
|
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
342
|
+
|
|
335
343
|
arrayFake.forEach(() => {
|
|
336
344
|
if (!estaAgrupado) {
|
|
337
345
|
quantityRelatedFunctions.push(
|
|
338
346
|
integrationsService.insertTempShipmentLines({
|
|
339
347
|
id_envio: idEnvioTemporal,
|
|
348
|
+
|
|
340
349
|
bulto
|
|
341
350
|
})
|
|
342
351
|
);
|
|
@@ -30,7 +30,6 @@ export const cookTempShipment = async ({
|
|
|
30
30
|
countriesService: CountriesService;
|
|
31
31
|
}): Promise<Shipment> => {
|
|
32
32
|
let zonaLLegada = {};
|
|
33
|
-
|
|
34
33
|
if (order.codigoPaisLLegada)
|
|
35
34
|
zonaLLegada = await countriesService.getCountryFromCountryCode(
|
|
36
35
|
order.codigoPaisLLegada
|
|
@@ -52,6 +51,7 @@ export const cookTempShipment = async ({
|
|
|
52
51
|
mail_salida: sellerAddress.mail
|
|
53
52
|
});
|
|
54
53
|
|
|
54
|
+
|
|
55
55
|
const setUbicacionComprador = async (order: ModifiedOrder) => {
|
|
56
56
|
type CompradorLocation = {
|
|
57
57
|
pais_llegada: string | null;
|
|
@@ -59,11 +59,13 @@ export const cookTempShipment = async ({
|
|
|
59
59
|
id_zona_llegada: string | null;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
+
|
|
62
63
|
const compradorLocation: CompradorLocation = {
|
|
63
64
|
pais_llegada: null,
|
|
64
65
|
provincia_llegada: null,
|
|
65
66
|
id_zona_llegada: null
|
|
66
67
|
};
|
|
68
|
+
|
|
67
69
|
if (order.codigoPaisLLegada) {
|
|
68
70
|
const _zonaLLegada = zonaLLegada as ZonaLLegada;
|
|
69
71
|
compradorLocation.pais_llegada = _zonaLLegada?.nombre_pais || null;
|
|
@@ -88,26 +90,32 @@ export const cookTempShipment = async ({
|
|
|
88
90
|
return compradorLocation;
|
|
89
91
|
};
|
|
90
92
|
|
|
93
|
+
|
|
91
94
|
const setDatosComprador = async (order: ModifiedOrder) => ({
|
|
92
95
|
nom_ape_llegada: order.primerApellidoLLegada
|
|
93
96
|
? order.nombreLLegada + ' ' + order.primerApellidoLLegada
|
|
94
97
|
: order.nombreLLegada,
|
|
98
|
+
|
|
95
99
|
contacto_llegada: order.primerApellidoLLegada
|
|
96
100
|
? order.nombreLLegada + ' ' + order.primerApellidoLLegada
|
|
97
101
|
: order.nombreLLegada,
|
|
102
|
+
|
|
98
103
|
direccion_llegada: order.direccionLLegada2
|
|
99
104
|
? order.direccionLLegada1 + ' ' + order.direccionLLegada2
|
|
100
105
|
: order.direccionLLegada1,
|
|
106
|
+
|
|
101
107
|
cod_pos_llegada: order.codigoPostalLLegada,
|
|
102
108
|
poblacion_llegada: order.ciudadLLegada,
|
|
103
109
|
tlf_llegada: order.telefonoLLegada || 'no informado',
|
|
104
110
|
mail_llegada: order.emailLLegada || 'no informado'
|
|
105
111
|
});
|
|
106
112
|
|
|
113
|
+
|
|
107
114
|
const setReembolso = (order: ModifiedOrder) => {
|
|
108
115
|
return { cantidad_contrareembolso: order.cantidadContrareembolso };
|
|
109
116
|
};
|
|
110
117
|
|
|
118
|
+
|
|
111
119
|
const setFechas = async (order: ModifiedOrder) => {
|
|
112
120
|
const date = moment().format('YYYY-MM-DD');
|
|
113
121
|
const beginHour = '09:00';
|
|
@@ -162,11 +170,13 @@ export const cookTempShipment = async ({
|
|
|
162
170
|
...order,
|
|
163
171
|
...accumulated
|
|
164
172
|
});
|
|
173
|
+
|
|
165
174
|
return {
|
|
166
175
|
...accumulated,
|
|
167
176
|
...stepResult
|
|
168
177
|
};
|
|
178
|
+
|
|
169
179
|
}, {})) as Shipment;
|
|
170
180
|
|
|
171
181
|
return dataInsert;
|
|
172
|
-
};
|
|
182
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cardus",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
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
|
|
8
|
+
"build": "rm -rf dist && tsc --build",
|
|
9
9
|
"prepublishOnly": "npm run build",
|
|
10
10
|
"test": "jest",
|
|
11
11
|
"lint": "eslint --ignore-path .eslintignore --ext .js,.ts && npm run format",
|
|
@@ -28,4 +28,4 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"moment": "^2.30.1"
|
|
30
30
|
}
|
|
31
|
-
}
|
|
31
|
+
}
|
package/types/index.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export type AnyObject = Record<string, any>; // Object with whichever properties
|
|
2
|
-
|
|
3
2
|
export type OriginalOrder = AnyObject;
|
|
4
|
-
|
|
5
3
|
export type Shipment = {
|
|
6
4
|
id_usuario: number;
|
|
7
5
|
id_agencia: number;
|
|
@@ -62,7 +60,6 @@ const shipmentTypes = {
|
|
|
62
60
|
};
|
|
63
61
|
|
|
64
62
|
export type ShipmentType = (typeof shipmentTypes)[keyof typeof shipmentTypes];
|
|
65
|
-
|
|
66
63
|
export type Bulto = {
|
|
67
64
|
id_envio: number;
|
|
68
65
|
bulto: {
|
|
@@ -93,6 +90,7 @@ export type ModifiedOrder = {
|
|
|
93
90
|
codigoEnvioExterno: string;
|
|
94
91
|
idInternoShopify?: string;
|
|
95
92
|
precio: number | null;
|
|
93
|
+
fecha_creacion_externa?: string | null;
|
|
96
94
|
};
|
|
97
95
|
|
|
98
96
|
export interface ModifiedOrderExtended extends ModifiedOrder {
|
|
@@ -100,10 +98,13 @@ export interface ModifiedOrderExtended extends ModifiedOrder {
|
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
type FetchAllOrders = () => Promise<OriginalOrder[]>;
|
|
101
|
+
|
|
103
102
|
export type CrearBulto = (params: {
|
|
104
103
|
lineItems: { idEnvioTemporal: number; line: AnyObject };
|
|
104
|
+
|
|
105
105
|
idUsuario: number;
|
|
106
106
|
}) => Promise<Bulto>;
|
|
107
|
+
|
|
107
108
|
type ModificarOrdenOriginal = (param: {
|
|
108
109
|
originalOrder: OriginalOrder;
|
|
109
110
|
}) => Promise<ModifiedOrder>;
|
|
@@ -141,11 +142,14 @@ export type IntegrationsService = {
|
|
|
141
142
|
orders: OriginalOrder[];
|
|
142
143
|
type: Type;
|
|
143
144
|
}) => Promise<OriginalOrder[]>;
|
|
145
|
+
|
|
144
146
|
checkDuplicateTempShipment: (
|
|
145
147
|
codigoEnvioExterno: string,
|
|
146
148
|
idUsuario: number
|
|
147
149
|
) => Promise<boolean>;
|
|
150
|
+
|
|
148
151
|
insertTempShipment: (params: Shipment) => number | false;
|
|
152
|
+
|
|
149
153
|
insertExternalShipment: (params: {
|
|
150
154
|
id_envio_temporal_usuario: number;
|
|
151
155
|
codigo_envio_externo: string;
|
|
@@ -153,15 +157,19 @@ export type IntegrationsService = {
|
|
|
153
157
|
fecha_hora_creacion: string;
|
|
154
158
|
servicio: Type;
|
|
155
159
|
id_interno_shopify?: string;
|
|
160
|
+
fecha_creacion_externa: string | null
|
|
156
161
|
}) => number | false;
|
|
162
|
+
|
|
157
163
|
insertTempShipmentLines: (params: {
|
|
158
164
|
id_envio: number;
|
|
159
165
|
bulto: Pick<Bulto['bulto'], 'peso' | 'alto' | 'ancho' | 'largo'>;
|
|
160
166
|
}) => Promise<undefined>;
|
|
167
|
+
|
|
161
168
|
insertTempDetailsShipment: (params: {
|
|
162
169
|
id_envio: number;
|
|
163
170
|
bulto: Bulto['bulto'];
|
|
164
171
|
}) => Promise<undefined>;
|
|
172
|
+
|
|
165
173
|
insertTempContent: (
|
|
166
174
|
params: UserDefaultConfigurationContent & { id_envio: number }
|
|
167
175
|
) => Promise<number | false>;
|
|
@@ -184,6 +192,7 @@ export type SellerAddress = {
|
|
|
184
192
|
|
|
185
193
|
export type AddressesService = {
|
|
186
194
|
getWarehouseAddress: (idUsuario: number) => Promise<SellerAddress>;
|
|
195
|
+
|
|
187
196
|
getAddress: (addressId: number, idUsuario: number) => Promise<SellerAddress>;
|
|
188
197
|
};
|
|
189
198
|
|
|
@@ -195,12 +204,16 @@ export type CountriesService = {
|
|
|
195
204
|
getCountryFromCountryCode: (
|
|
196
205
|
countryCode: string
|
|
197
206
|
) => Promise<{ nombre_pais: string; id_pais?: number }>;
|
|
207
|
+
|
|
198
208
|
getProvinceByCountryIdAndPostalCode: (
|
|
199
209
|
id_pais: Country['id_pais'],
|
|
210
|
+
|
|
200
211
|
zipCode: string
|
|
201
212
|
) => Promise<Provincia>;
|
|
213
|
+
|
|
202
214
|
getZoneIdByCountryIdAndPostalCode: (
|
|
203
215
|
id_pais: Country['id_pais'],
|
|
216
|
+
|
|
204
217
|
zipCode: string
|
|
205
218
|
) => Promise<Zone>;
|
|
206
219
|
};
|
|
@@ -228,8 +241,10 @@ export type ConfigurationService = {
|
|
|
228
241
|
getDefaultProformaConfiguration: (
|
|
229
242
|
id_usuario: number
|
|
230
243
|
) => Promise<UserDefaultConfigurationContent[] | false>;
|
|
244
|
+
|
|
231
245
|
getFakeDefaultProformaConfiguration: (
|
|
232
246
|
id_usuario: number,
|
|
247
|
+
|
|
233
248
|
dni: string
|
|
234
249
|
) => UserDefaultConfigurationContent[];
|
|
235
250
|
};
|
|
@@ -262,5 +277,5 @@ type ExecutionManagerUploadReturn = {
|
|
|
262
277
|
|
|
263
278
|
export type ExecutionManager = {
|
|
264
279
|
upload(): ExecutionManagerUploadReturn[];
|
|
265
|
-
new
|
|
280
|
+
new(params: ExecutionManagerConstructorParams): ExecutionManager;
|
|
266
281
|
};
|