Notes/src/becca/entity_constructor.js

32 lines
923 B
JavaScript
Raw Normal View History

2021-06-29 22:15:57 +02:00
const Note = require('./entities/note');
const NoteRevision = require('./entities/note_revision');
const Branch = require('./entities/branch');
const Attribute = require('./entities/attribute');
const RecentNote = require('./entities/recent_note');
2022-01-10 17:09:20 +01:00
const EtapiToken = require('./entities/etapi_token');
2021-06-29 22:15:57 +02:00
const Option = require('./entities/option');
const ENTITY_NAME_TO_ENTITY = {
2018-08-10 14:31:57 +02:00
"attributes": Attribute,
"branches": Branch,
"notes": Note,
"note_contents": Note,
2018-08-10 14:31:57 +02:00
"note_revisions": NoteRevision,
"note_revision_contents": NoteRevision,
2018-08-10 14:31:57 +02:00
"recent_notes": RecentNote,
2022-01-10 17:09:20 +01:00
"etapi_tokens": EtapiToken,
2021-06-29 22:15:57 +02:00
"options": Option
2018-08-09 20:08:00 +02:00
};
function getEntityFromEntityName(entityName) {
if (!(entityName in ENTITY_NAME_TO_ENTITY)) {
throw new Error(`Entity for table ${entityName} not found!`);
2018-08-10 14:31:57 +02:00
}
return ENTITY_NAME_TO_ENTITY[entityName];
2018-08-09 20:08:00 +02:00
}
module.exports = {
getEntityFromEntityName
2018-08-09 20:08:00 +02:00
};