Skip to content

Commit

Permalink
Adding toJSON so that the descriminator decorator will be evaluated/a…
Browse files Browse the repository at this point in the history
…dded to the mongoose model (currently undefined on initialization and first invocation)
  • Loading branch information
seanspeaks committed Aug 8, 2024
1 parent 9bc9921 commit 3cacb09
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions packages/core/module-plugin/module-factory.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
const { Entity } = require("./entity");
const { Entity } = require('./entity');
const { Auther } = require('./auther');

class ModuleFactory {
constructor(...params) {
this.moduleDefinitions = params;
this.moduleTypes = this.moduleDefinitions.map(
(def) => def.moduleName
);
this.moduleTypes = this.moduleDefinitions.map((def) => def.moduleName);
}

async getEntitiesForUser(userId) {
let results = [];
for (const moduleDefinition of this.moduleDefinitions) {
const moduleInstance = await Auther.getInstance({
userId,
definition: moduleDefinition
definition: moduleDefinition,
});
const list = await moduleInstance.getEntitiesForUserId(userId);
results.push(...list);
Expand All @@ -27,33 +25,36 @@ class ModuleFactory {
}

getModuleDefinitionFromTypeName(typeName) {
return
return;
}


async getModuleInstanceFromEntityId(entityId, userId) {
const entity = await Entity.findById(entityId);
const moduleDefinition = this.moduleDefinitions.find(
(def) => entity['__t'] === Auther.getEntityModelFromDefinition(def).modelName
)
(def) =>
entity.toJSON()['__t'] ===
Auther.getEntityModelFromDefinition(def).modelName
);
if (!moduleDefinition) {
throw new Error('Module definition not found for entity type: ' + entity['__t']);
throw new Error(
'Module definition not found for entity type: ' + entity['__t']
);
}
return await Auther.getInstance({
userId,
entityId,
definition: moduleDefinition
definition: moduleDefinition,
});
}

async getInstanceFromTypeName(typeName, userId) {
const moduleDefinition =this.moduleDefinitions.find(
async getInstanceFromTypeName(typeName, userId) {
const moduleDefinition = this.moduleDefinitions.find(
(def) => def.getName() === typeName
);
return await Auther.getInstance({
userId,
definition: moduleDefinition
});
return await Auther.getInstance({
userId,
definition: moduleDefinition,
});
}
}

Expand Down

0 comments on commit 3cacb09

Please sign in to comment.