Move relationship types + dashboard recent off the machines blueprint

- Add /api/assets/relationshiptypes (GET/POST) serving RelationshipType; point
  relationshipTypesApi at it instead of the legacy /api/machines blueprint.
- Dashboard recent-devices widget reads assetsApi.list (asset shape) instead
  of machinesApi.

No frontend code references machinesApi anymore.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-06-26 09:29:30 -04:00
parent b68b0895ee
commit 167a9514cf
3 changed files with 56 additions and 11 deletions

View File

@@ -176,10 +176,10 @@ export const computersApi = {
// Relationship Types API
export const relationshipTypesApi = {
list() {
return api.get('/machines/relationshiptypes')
return api.get('/assets/relationshiptypes')
},
create(data) {
return api.post('/machines/relationshiptypes', data)
return api.post('/assets/relationshiptypes', data)
}
}

View File

@@ -65,18 +65,18 @@
<table>
<thead>
<tr>
<th>Name</th>
<th>Category</th>
<th>Asset #</th>
<th>Type</th>
<th>Status</th>
<th>Business Unit</th>
</tr>
</thead>
<tbody>
<tr v-for="machine in recentMachines" :key="machine.machineid">
<td>{{ machine.machinenumber || machine.hostname || machine.alias || '-' }}</td>
<td>{{ machine.category || '-' }}</td>
<td>{{ machine.machinetype || '-' }}</td>
<td>{{ machine.businessunit || '-' }}</td>
<tr v-for="machine in recentMachines" :key="machine.assetid">
<td>{{ machine.assetnumber || machine.name || '-' }}</td>
<td>{{ machine.assettypename || '-' }}</td>
<td>{{ machine.statusname || '-' }}</td>
<td>{{ machine.businessunitname || '-' }}</td>
</tr>
<tr v-if="recentMachines.length === 0">
<td colspan="4" style="text-align: center; color: var(--text-light);">
@@ -93,7 +93,7 @@
<script setup>
import { ref, onMounted } from 'vue'
import { dashboardApi, machinesApi, printersApi } from '../api'
import { dashboardApi, assetsApi, printersApi } from '../api'
const loading = ref(true)
const stats = ref({})
@@ -104,7 +104,7 @@ onMounted(async () => {
try {
const [dashRes, machinesRes, printersRes] = await Promise.all([
dashboardApi.summary().catch(() => ({ data: { data: {} } })),
machinesApi.list({ perpage: 5 }).catch(() => ({ data: { data: [] } })),
assetsApi.list({ perpage: 5 }).catch(() => ({ data: { data: [] } })),
printersApi.dashboardSummary().catch(() => ({ data: { data: {} } }))
])

View File

@@ -203,6 +203,51 @@ def delete_asset_status(status_id: int):
return success_response(message='Asset status deleted')
# =============================================================================
# Relationship Types
# =============================================================================
@assets_bp.route('/relationshiptypes', methods=['GET'])
@jwt_required(optional=True)
def list_relationship_types():
"""List all asset relationship types."""
types = RelationshipType.query.order_by(RelationshipType.relationshiptype).all()
return success_response([{
'relationshiptypeid': t.relationshiptypeid,
'relationshiptype': t.relationshiptype,
'description': t.description
} for t in types])
@assets_bp.route('/relationshiptypes', methods=['POST'])
@jwt_required()
def create_relationship_type():
"""Create a new asset relationship type."""
data = request.get_json()
if not data or not data.get('relationshiptype'):
return error_response(ErrorCodes.VALIDATION_ERROR, 'relationshiptype is required')
if RelationshipType.query.filter_by(relationshiptype=data['relationshiptype']).first():
return error_response(
ErrorCodes.CONFLICT,
f"Relationship type '{data['relationshiptype']}' already exists",
http_code=409
)
rel_type = RelationshipType(
relationshiptype=data['relationshiptype'],
description=data.get('description')
)
db.session.add(rel_type)
db.session.commit()
return success_response({
'relationshiptypeid': rel_type.relationshiptypeid,
'relationshiptype': rel_type.relationshiptype,
'description': rel_type.description
}, message='Relationship type created', http_code=201)
# =============================================================================
# Assets
# =============================================================================