updates
This commit is contained in:
@@ -65,6 +65,8 @@ function buildAssetPayload({ assetSelection = {}, registrationDefaults = {} }) {
|
||||
const assetName = (rawName || 'Measurement asset').toString();
|
||||
const assetDescription = (assetSelection.assetDescription || assetSelection.description || assetName).toString();
|
||||
|
||||
const modelId = metadata.product_model_id ?? metadata.id ?? assetSelection.modelId ?? assetSelection.model ?? null;
|
||||
|
||||
const payload = {
|
||||
profile_id: toNumber(defaults.profileId, 1),
|
||||
location_id: toNumber(defaults.locationId, 1),
|
||||
@@ -72,11 +74,62 @@ function buildAssetPayload({ assetSelection = {}, registrationDefaults = {} }) {
|
||||
asset_name: assetName,
|
||||
asset_description: assetDescription,
|
||||
asset_status: (assetSelection.assetStatus || defaults.status || 'actief').toString(),
|
||||
product_model_id: metadata.product_model_id || metadata.id || assetSelection.model || null,
|
||||
product_model_uuid: metadata.product_model_uuid || metadata.uuid || metadata.id || assetSelection.model || null,
|
||||
product_model_id: modelId,
|
||||
product_model_uuid: metadata.product_model_uuid || metadata.uuid || null,
|
||||
child_assets: toArray(defaults.childAssets)
|
||||
};
|
||||
|
||||
const validation = [];
|
||||
const missing = [];
|
||||
const tooLong = [];
|
||||
const invalid = [];
|
||||
|
||||
if (!payload.asset_name) {
|
||||
missing.push('asset_name');
|
||||
} else if (payload.asset_name.length > 100) {
|
||||
tooLong.push('asset_name');
|
||||
}
|
||||
|
||||
if (!payload.asset_status) {
|
||||
missing.push('asset_status');
|
||||
} else if (payload.asset_status.length > 20) {
|
||||
tooLong.push('asset_status');
|
||||
}
|
||||
|
||||
if (!Number.isInteger(payload.location_id)) {
|
||||
invalid.push('location_id');
|
||||
}
|
||||
if (!Number.isInteger(payload.process_id)) {
|
||||
invalid.push('process_id');
|
||||
}
|
||||
if (!Number.isInteger(payload.profile_id)) {
|
||||
invalid.push('profile_id');
|
||||
}
|
||||
|
||||
if (!Number.isInteger(payload.product_model_id)) {
|
||||
invalid.push('product_model_id');
|
||||
}
|
||||
|
||||
if (!Array.isArray(payload.child_assets)) {
|
||||
invalid.push('child_assets');
|
||||
}
|
||||
|
||||
if (missing.length) {
|
||||
validation.push(`missing: ${missing.join(', ')}`);
|
||||
}
|
||||
if (tooLong.length) {
|
||||
validation.push(`too long: ${tooLong.join(', ')}`);
|
||||
}
|
||||
if (invalid.length) {
|
||||
validation.push(`invalid type: ${invalid.join(', ')}`);
|
||||
}
|
||||
|
||||
if (validation.length) {
|
||||
console.warn('[assetUtils] payload validation', validation.join(' | '));
|
||||
} else {
|
||||
console.info('[assetUtils] payload validation ok');
|
||||
}
|
||||
|
||||
const tagNumber = typeof assetSelection.tagNumber === 'string' && assetSelection.tagNumber.trim()
|
||||
? assetSelection.tagNumber.trim()
|
||||
: null;
|
||||
@@ -161,7 +214,7 @@ async function syncAsset({ assetSelection = {}, registrationDefaults = {}, apiCo
|
||||
? apiConfig.updatePath(tagNumber)
|
||||
: apiConfig.registerPath;
|
||||
const url = prepareUrl(apiConfig.baseUrl, path);
|
||||
const method = isUpdate ? 'PUT' : 'POST';
|
||||
const method = isUpdate ? (apiConfig.updateMethod || 'PUT') : 'POST';
|
||||
const headers = apiConfig.headers || {};
|
||||
|
||||
console.info('[assetUtils] Sending asset update', { nodeContext, method, url });
|
||||
|
||||
Reference in New Issue
Block a user