Skip to content

Instantly share code, notes, and snippets.

@rightisleft
Created August 16, 2017 14:46
Show Gist options
  • Select an option

  • Save rightisleft/5b0efe9e5c90367c55d24463f675344f to your computer and use it in GitHub Desktop.

Select an option

Save rightisleft/5b0efe9e5c90367c55d24463f675344f to your computer and use it in GitHub Desktop.
public async applyMapping(model: DTOModel): Promise<boolean> {
// Todo: Jack Murphy - Here be Dragons!!!! This whole object should be processed by a single authority - IE ML tier.
try {
let lens: DTOLens = await this.lenses.createQueryBuilder('lens')
.where(`lens.model = ${model.id}`)
.leftJoinAndSelect("lens.model", "model")
.leftJoinAndSelect("lens.modifiers", "modifiers")
.getOne();
// mappings is an array where the index is the old id and the value is the new id
for (let originTopicId in model.mapping) {
let newTopicId: string = model.mapping[originTopicId];
let modDTO: DTOModifier = lens.modifiers.find((mod: DTOModifier) => mod.topicId === parseInt(originTopicId));
let newTopic: number = parseInt(newTopicId);
if (newTopic === -1) {
await this.modifiers.remove(modDTO);
} else {
modDTO.topicId = newTopic;
await this.modifiers.persist(modDTO);
}
}
return true;
} catch (e) {
return false;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment