-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TECH] Appliquer le patch dans PG lorsque la release est patchée (PIX…
- Loading branch information
Showing
9 changed files
with
370 additions
and
111 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
97 changes: 97 additions & 0 deletions
97
api/src/learning-content/domain/usecases/patch-learning-content-cache-entry.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** @param {import('./dependencies.js').Dependencies} */ | ||
export async function patchLearningContentCacheEntry({ | ||
recordId, | ||
updatedRecord, | ||
modelName, | ||
LearningContentCache, | ||
frameworkRepository, | ||
areaRepository, | ||
competenceRepository, | ||
thematicRepository, | ||
tubeRepository, | ||
skillRepository, | ||
challengeRepository, | ||
courseRepository, | ||
tutorialRepository, | ||
missionRepository, | ||
}) { | ||
const currentLearningContent = await LearningContentCache.instance.get(); | ||
const patch = generatePatch(currentLearningContent, recordId, updatedRecord, modelName); | ||
await LearningContentCache.instance.patch(patch); | ||
await patchDatabase( | ||
modelName, | ||
updatedRecord, | ||
frameworkRepository, | ||
areaRepository, | ||
competenceRepository, | ||
thematicRepository, | ||
tubeRepository, | ||
skillRepository, | ||
challengeRepository, | ||
courseRepository, | ||
tutorialRepository, | ||
missionRepository, | ||
); | ||
} | ||
|
||
function generatePatch(currentLearningContent, id, newEntry, modelName) { | ||
const index = currentLearningContent[modelName].findIndex((element) => element?.id === id); | ||
if (index === -1) { | ||
return { | ||
operation: 'push', | ||
path: modelName, | ||
value: newEntry, | ||
}; | ||
} | ||
return { | ||
operation: 'assign', | ||
path: `${modelName}[${index}]`, | ||
value: newEntry, | ||
}; | ||
} | ||
|
||
async function patchDatabase( | ||
modelName, | ||
patchedRecord, | ||
frameworkRepository, | ||
areaRepository, | ||
competenceRepository, | ||
thematicRepository, | ||
tubeRepository, | ||
skillRepository, | ||
challengeRepository, | ||
courseRepository, | ||
tutorialRepository, | ||
missionRepository, | ||
) { | ||
if (modelName === 'frameworks') { | ||
await frameworkRepository.save([patchedRecord]); | ||
} | ||
if (modelName === 'areas') { | ||
await areaRepository.save([patchedRecord]); | ||
} | ||
if (modelName === 'competences') { | ||
await competenceRepository.save([patchedRecord]); | ||
} | ||
if (modelName === 'thematics') { | ||
await thematicRepository.save([patchedRecord]); | ||
} | ||
if (modelName === 'tubes') { | ||
await tubeRepository.save([patchedRecord]); | ||
} | ||
if (modelName === 'skills') { | ||
await skillRepository.save([patchedRecord]); | ||
} | ||
if (modelName === 'challenges') { | ||
await challengeRepository.save([patchedRecord]); | ||
} | ||
if (modelName === 'courses') { | ||
await courseRepository.save([patchedRecord]); | ||
} | ||
if (modelName === 'tutorials') { | ||
await tutorialRepository.save([patchedRecord]); | ||
} | ||
if (modelName === 'missions') { | ||
await missionRepository.save([patchedRecord]); | ||
} | ||
} |
This file contains 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
21 changes: 0 additions & 21 deletions
21
api/src/shared/domain/usecases/patch-learning-content-cache-entry.js
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Oops, something went wrong.