Notes/src/etapi/mappers.ts

73 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-04-07 14:56:22 +03:00
import BAttachment = require("../becca/entities/battachment");
import BAttribute = require("../becca/entities/battribute");
import BBranch = require("../becca/entities/bbranch");
import BNote = require("../becca/entities/bnote");
function mapNoteToPojo(note: BNote) {
2022-01-07 19:33:59 +01:00
return {
noteId: note.noteId,
isProtected: note.isProtected,
title: note.title,
type: note.type,
mime: note.mime,
2023-06-04 11:59:19 +02:00
blobId: note.blobId,
2022-01-07 19:33:59 +01:00
dateCreated: note.dateCreated,
dateModified: note.dateModified,
utcDateCreated: note.utcDateCreated,
utcDateModified: note.utcDateModified,
parentNoteIds: note.getParentNotes().map(p => p.noteId),
childNoteIds: note.getChildNotes().map(ch => ch.noteId),
parentBranchIds: note.getParentBranches().map(p => p.branchId),
childBranchIds: note.getChildBranches().map(ch => ch.branchId),
attributes: note.getAttributes().map(attr => mapAttributeToPojo(attr))
};
}
2024-04-07 14:56:22 +03:00
function mapBranchToPojo(branch: BBranch) {
2022-01-07 19:33:59 +01:00
return {
branchId: branch.branchId,
noteId: branch.noteId,
parentNoteId: branch.parentNoteId,
prefix: branch.prefix,
notePosition: branch.notePosition,
isExpanded: branch.isExpanded,
utcDateModified: branch.utcDateModified
};
}
2024-04-07 14:56:22 +03:00
function mapAttributeToPojo(attr: BAttribute) {
2022-01-07 19:33:59 +01:00
return {
attributeId: attr.attributeId,
noteId: attr.noteId,
type: attr.type,
name: attr.name,
value: attr.value,
position: attr.position,
isInheritable: attr.isInheritable,
utcDateModified: attr.utcDateModified
};
}
2024-04-07 14:56:22 +03:00
function mapAttachmentToPojo(attachment: BAttachment) {
2023-06-05 09:23:42 +02:00
return {
attachmentId: attachment.attachmentId,
ownerId: attachment.ownerId,
2023-06-05 09:23:42 +02:00
role: attachment.role,
mime: attachment.mime,
title: attachment.title,
position: attachment.position,
blobId: attachment.blobId,
dateModified: attachment.dateModified,
utcDateModified: attachment.utcDateModified,
utcDateScheduledForErasureSince: attachment.utcDateScheduledForErasureSince,
contentLength: attachment.contentLength
};
}
2024-04-07 14:56:22 +03:00
export = {
2022-01-07 19:33:59 +01:00
mapNoteToPojo,
mapBranchToPojo,
2023-06-05 09:23:42 +02:00
mapAttributeToPojo,
mapAttachmentToPojo
2023-06-04 11:59:19 +02:00
};