Skip to content

Commit

Permalink
fix(api,dashboard): déploiement du dashboard avant l'api pour éviter …
Browse files Browse the repository at this point in the history
…que la bannière 'Rafraichissez svp' ne soit inutile
  • Loading branch information
Arnaud AMBROSELLI committed Nov 6, 2023
1 parent eb95612 commit 3ade606
Show file tree
Hide file tree
Showing 4 changed files with 615 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .kontinuous/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ www:
api:
~chart: app
~needs: [build-api, pg]
~needs: [build-api, pg, dashboard]
host: "{{ .Values.global.host }}"
enabled: true
containerPort: 3000
Expand Down
33 changes: 28 additions & 5 deletions api/src/controllers/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,29 @@ const validateUser = require("../middleware/validateUser");
const { serializeOrganisation } = require("../utils/data-serializer");
const { Organisation, Person, Action, Comment, Report, Team, Service, sequelize, Group } = require("../db/sequelize");

const migrationsAvailable = {
"integrate-comments-in-actions-history": true,
};

// why this route ?
// because we deplpy the dashboard BEFORE the backend
// so if the dashboard wants to do a migration and the backend is not deployed yet
// the dashboard would spend time and ressource to prepare a migration
// that the backend would ignore because it doesn't know it yet
router.get(
"/migrations-available",
passport.authenticate("user", { session: false }),
validateUser(["admin", "normal", "restricted-access"]),
catchErrors(async (req, res) => {
const organisation = await Organisation.findOne({ where: { _id: req.user.organisation } });
if (!organisation) return res.status(404).send({ ok: false, error: "Not Found" });
return res.status(200).send({
ok: true,
data: migrationsAvailable,
});
})
);

router.put(
"/:migrationName",
passport.authenticate("user", { session: false }),
Expand Down Expand Up @@ -86,13 +109,13 @@ router.put(
for (const { _id, encrypted, encryptedEntityKey } of req.body.actionsToUpdate) {
await Action.update({ encrypted, encryptedEntityKey }, { where: { _id }, transaction: tx, paranoid: false });
}
organisation.set({
migrations: [...(organisation.migrations || []), req.params.migrationName],
migrationLastUpdateAt: new Date(),
});
}

organisation.set({
migrations: [...(organisation.migrations || []), req.params.migrationName],
migrating: false,
migrationLastUpdateAt: new Date(),
});
organisation.set({ migrating: false });
await organisation.save({ transaction: tx });
});
} catch (e) {
Expand Down
16 changes: 13 additions & 3 deletions dashboard/src/components/DataMigrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ export default function useDataMigrator() {
migrateData: async (organisation) => {
const organisationId = organisation?._id;
let migrationLastUpdateAt = organisation.migrationLastUpdateAt;
const migrationsAvailable = await API.get({ path: '/migration/migrations-available' }).then((res) => {
console.log({ res });
return res.data || {};
});

console.log({ migrationsAvailable });

/*
// Example of migration:
if (!organisation.migrations?.includes('migration-name')) {
if (!organisation.migrations?.includes('migration-name') && migrationsAvailable['migration-name']) {
setLoadingText(LOADING_TEXT);
const somethingRes = await API.get({
path: '/something-to-update',
Expand All @@ -49,14 +56,17 @@ export default function useDataMigrator() {
if (response.ok) {
setOrganisation(response.organisation);
migrationLastUpdateAt = response.organisation.migrationLastUpdateAt;
else {
} else {
return false;
}
}
// End of example of migration.
*/

if (!organisation.migrations?.includes('integrate-comments-in-actions-history')) {
if (
!organisation.migrations?.includes('integrate-comments-in-actions-history') &&
migrationsAvailable['integrate-comments-in-actions-history']
) {
setLoadingText(LOADING_TEXT);
const comments = await API.get({
path: '/comment',
Expand Down
Loading

0 comments on commit 3ade606

Please sign in to comment.