Updated Asset Entry and Views

This commit is contained in:
2026-06-03 14:12:32 -05:00
parent 2f13b8c590
commit 8335f1af1b
9 changed files with 620 additions and 73 deletions

View File

@@ -141,10 +141,71 @@ async function main() {
acquired_date: '2026-01-05',
in_service_date: '2026-01-05',
useful_life_months: 60,
depreciation_method: 'macrs_gds_200db_5'
depreciation_method: 'macrs_gds_200db_5',
books: [
{ book_type: 'GAAP', active: true, depreciation_method: 'straight_line', convention: 'half_year', useful_life_months: 60, cost: 2400 },
{ book_type: 'FEDERAL', active: true, depreciation_method: 'macrs_gds_200db_5', convention: 'half_year', useful_life_months: 60, section_179_amount: 500, bonus_percent: 0, cost: 2400 }
]
})
});
const assetId = assetResult.asset.id;
// Per-book persistence: GAAP and FEDERAL must keep distinct methods.
const hydrated = await request(`/api/assets/${assetId}`, { headers: auth });
const gaapBook = hydrated.asset.books.find((book) => book.book_type === 'GAAP');
const federalBook = hydrated.asset.books.find((book) => book.book_type === 'FEDERAL');
if (gaapBook?.depreciation_method !== 'straight_line' || federalBook?.depreciation_method !== 'macrs_gds_200db_5') {
throw new Error('Per-book depreciation methods did not persist independently');
}
if (Number(federalBook.section_179_amount) !== 500) {
throw new Error('Per-book Section 179 amount did not persist');
}
// File cabinet (multipart upload bypasses the JSON request helper)
const uploadForm = new FormData();
uploadForm.append('file', new Blob(['invoice contents'], { type: 'text/plain' }), 'invoice.txt');
const uploadResponse = await fetch(`${baseUrl}/api/assets/${assetId}/files`, { method: 'POST', headers: auth, body: uploadForm });
const fileResult = await uploadResponse.json();
if (!uploadResponse.ok || !fileResult.file?.id) throw new Error('Asset file upload did not return a file');
const fileDownload = await fetch(`${baseUrl}/api/assets/${assetId}/files/${fileResult.file.id}`, { headers: auth });
if (!fileDownload.ok || (await fileDownload.text()) !== 'invoice contents') {
throw new Error('Asset file download did not return stored contents');
}
// Warranty
const warrantyResult = await request(`/api/assets/${assetId}/warranties`, {
method: 'POST',
headers: auth,
body: JSON.stringify({ provider: 'Acme Care', start_date: '2026-01-05', expiration_date: '2029-01-05', coverage_details: 'Parts and labor' })
});
if (!warrantyResult.warranty?.id) throw new Error('Warranty was not created');
// Task lifecycle
const taskResult = await request(`/api/assets/${assetId}/tasks`, {
method: 'POST',
headers: auth,
body: JSON.stringify({ title: 'Calibrate device', type: 'calibration', due_date: '2026-03-01' })
});
const completedTask = await request(`/api/assets/${assetId}/tasks/${taskResult.task.id}`, {
method: 'PUT',
headers: auth,
body: JSON.stringify({ status: 'complete' })
});
if (completedTask.task.status !== 'complete') throw new Error('Task status update did not persist');
// Notes
await request(`/api/assets/${assetId}/notes`, {
method: 'POST',
headers: auth,
body: JSON.stringify({ body: 'Received and tagged in receiving dock.' })
});
const detailed = await request(`/api/assets/${assetId}`, { headers: auth });
if (!detailed.asset.files.length || !detailed.asset.warranties.length || !detailed.asset.notes_log.length) {
throw new Error('Asset detail collections (files/warranties/notes) were not returned');
}
const employeeResult = await request('/api/employees', {
method: 'POST',
headers: auth,