104 lines
3.3 KiB
JavaScript
104 lines
3.3 KiB
JavaScript
import { api, apiURL } from '@Services/Api';
|
|
|
|
/**
|
|
* Servicio para gestionar números de serie de inventario
|
|
*/
|
|
const serialService = {
|
|
/**
|
|
* Obtener lista de seriales de un producto
|
|
* @param {Number} inventoryId - ID del inventario
|
|
* @param {Object} filters - Filtros opcionales (status, q, page)
|
|
* @returns {Promise}
|
|
*/
|
|
async getSerials(inventoryId, filters = {}) {
|
|
return new Promise((resolve, reject) => {
|
|
api.get(apiURL(`inventario/${inventoryId}/serials`), {
|
|
params: filters,
|
|
onSuccess: (response) => {
|
|
resolve(response);
|
|
},
|
|
onError: (error) => {
|
|
reject(error);
|
|
}
|
|
});
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Obtener solo seriales disponibles de un producto
|
|
* @param {Number} inventoryId - ID del inventario
|
|
* @param {Number|null} warehouseId - ID del almacén específico (gestión de inventario)
|
|
* @param {Object} options - Opciones adicionales
|
|
* @param {Boolean} options.mainWarehouse - Si true, filtra por almacén principal (?main_warehouse=1)
|
|
* @returns {Promise}
|
|
*/
|
|
async getAvailableSerials(inventoryId, warehouseId = null, options = {}) {
|
|
const filters = { status: 'disponible' };
|
|
if (options.mainWarehouse) {
|
|
filters.main_warehouse = 1;
|
|
} else if (warehouseId) {
|
|
filters.warehouse_id = warehouseId;
|
|
}
|
|
return this.getSerials(inventoryId, filters);
|
|
},
|
|
|
|
/**
|
|
* Obtener un serial específico
|
|
* @param {Number} inventoryId - ID del inventario
|
|
* @param {Number} serialId - ID del serial
|
|
* @returns {Promise}
|
|
*/
|
|
async getSerial(inventoryId, serialId) {
|
|
return new Promise((resolve, reject) => {
|
|
api.get(apiURL(`inventario/${inventoryId}/serials/${serialId}`), {
|
|
onSuccess: (response) => {
|
|
resolve(response.serial || response);
|
|
},
|
|
onError: (error) => {
|
|
reject(error);
|
|
}
|
|
});
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Obtener componentes de un bundle con info de track_serials
|
|
* @param {Number} bundleId - ID del bundle
|
|
* @returns {Promise}
|
|
*/
|
|
async getBundleComponents(bundleId) {
|
|
return new Promise((resolve, reject) => {
|
|
api.get(apiURL(`bundles/${bundleId}`), {
|
|
onSuccess: (response) => {
|
|
const bundle = response.model || response;
|
|
resolve(bundle.items || []);
|
|
},
|
|
onError: (error) => {
|
|
reject(error);
|
|
}
|
|
});
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Eliminar un serial
|
|
* @param {Number} inventoryId - ID del inventario
|
|
* @param {Number} serialId - ID del serial
|
|
* @returns {Promise}
|
|
*/
|
|
async deleteSerial(inventoryId, serialId) {
|
|
return new Promise((resolve, reject) => {
|
|
api.delete(apiURL(`inventario/${inventoryId}/serials/${serialId}`), {
|
|
onSuccess: (response) => {
|
|
resolve(response);
|
|
},
|
|
onError: (error) => {
|
|
reject(error);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
};
|
|
|
|
export default serialService;
|