Skip to content

Commit

Permalink
Merge pull request #326 from friggframework/bugfix/entity-model-searc…
Browse files Browse the repository at this point in the history
…h-local-bug

Fix bug during local running
  • Loading branch information
seanspeaks authored Aug 8, 2024
2 parents 9bc9921 + 3cacb09 commit 6572f99
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 6572f99

Please sign in to comment.