Versie 0.2.0
This commit is contained in:
commit
e77d8fd373
495 files changed
+81026
No files matched your search
@@ -0,0 +1,19 @@
|
||||
// Generated, do not edit. sha256:2a06cfff8bd22ab273abad66a7bff34ee21d692bd6b4215d67a43a86980cd81f
|
||||
import * as db from '../db.js';
|
||||
|
||||
export function getAssetNote(assetId) {
|
||||
return db.one(`SELECT body, createdAt FROM AssetNote WHERE assetId = ?`, [assetId]) || null;
|
||||
}
|
||||
|
||||
export async function setAssetNote(assetId, body) {
|
||||
if (!db.one(`SELECT id FROM Asset WHERE id = ?`, [assetId])) throw new Error(`Asset ${assetId} does not exist.`);
|
||||
const tekst = typeof body === 'string' ? body : '';
|
||||
if (!tekst.trim()) {
|
||||
db.run(`DELETE FROM AssetNote WHERE assetId = ?`, [assetId]);
|
||||
} else {
|
||||
db.run(`INSERT INTO AssetNote (assetId, body, createdAt) VALUES (?, ?, ?)
|
||||
ON CONFLICT(assetId) DO UPDATE SET body = excluded.body`, [assetId, tekst, new Date().toISOString()]);
|
||||
}
|
||||
await db.persist();
|
||||
return getAssetNote(assetId);
|
||||
}
|
||||
Reference in new issue
Block a user