Created
August 16, 2017 14:46
-
-
Save rightisleft/5b0efe9e5c90367c55d24463f675344f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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