@ -70,14 +71,17 @@ function updateNoteAttribute(req) {
};
}
functionsetNoteAttribute(req){
functionsetNoteAttribute(req: Request){
constnoteId=req.params.noteId;
constbody=req.body;
constattributeId=sql.getValue(`SELECT attributeId FROM attributes WHERE isDeleted = 0 AND noteId = ? AND type = ? AND name = ?`,[noteId,body.type,body.name]);
constattributeId=sql.getValue<string|null>(`SELECT attributeId FROM attributes WHERE isDeleted = 0 AND noteId = ? AND type = ? AND name = ?`,[noteId,body.type,body.name]);
if(attributeId){
constattr=becca.getAttribute(attributeId);
if(!attr){
thrownewValidationError(`Missing attribute with ID ${attributeId}.`);
}
attr.value=body.value;
attr.save();
}else{
@ -88,14 +92,14 @@ function setNoteAttribute(req) {
}
}
functionaddNoteAttribute(req){
functionaddNoteAttribute(req: Request){
constnoteId=req.params.noteId;
constbody=req.body;
newBAttribute({...body,noteId}).save();
}
functiondeleteNoteAttribute(req){
functiondeleteNoteAttribute(req: Request){
constnoteId=req.params.noteId;
constattributeId=req.params.attributeId;
@ -110,11 +114,14 @@ function deleteNoteAttribute(req) {
}
}
functionupdateNoteAttributes(req){
functionupdateNoteAttributes(req: Request){
constnoteId=req.params.noteId;
constincomingAttributes=req.body;
constnote=becca.getNote(noteId);
if(!note){
thrownewValidationError(`Cannot find note with ID ${noteId}.`);
returnsql.getColumn("SELECT DISTINCT value FROM attributes WHERE isDeleted = 0 AND name = ? AND type = 'label' AND value != '' ORDER BY value",[attributeName]);
}
functioncreateRelation(req){
functioncreateRelation(req: Request){
constsourceNoteId=req.params.noteId;
consttargetNoteId=req.params.targetNoteId;
constname=req.params.name;
constattributeId=sql.getValue(`SELECT attributeId FROM attributes WHERE isDeleted = 0 AND noteId = ? AND type = 'relation' AND name = ? AND value = ?`,[sourceNoteId,name,targetNoteId]);
constattributeId=sql.getValue<string>(`SELECT attributeId FROM attributes WHERE isDeleted = 0 AND noteId = ? AND type = 'relation' AND name = ? AND value = ?`,[sourceNoteId,name,targetNoteId]);
letattribute=becca.getAttribute(attributeId);
if(!attribute){
@ -212,20 +223,22 @@ function createRelation(req) {
returnattribute;
}
functiondeleteRelation(req){
functiondeleteRelation(req: Request){
constsourceNoteId=req.params.noteId;
consttargetNoteId=req.params.targetNoteId;
constname=req.params.name;
constattributeId=sql.getValue(`SELECT attributeId FROM attributes WHERE isDeleted = 0 AND noteId = ? AND type = 'relation' AND name = ? AND value = ?`,[sourceNoteId,name,targetNoteId]);
constattributeId=sql.getValue<string|null>(`SELECT attributeId FROM attributes WHERE isDeleted = 0 AND noteId = ? AND type = 'relation' AND name = ? AND value = ?`,[sourceNoteId,name,targetNoteId]);