-
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.
[FEATURE] Configuration de l'oralisation par élève pour les écoles (P…
- Loading branch information
Showing
31 changed files
with
559 additions
and
279 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...-builder/factory/prescription/organization-learners/build-organization-learner-feature.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,25 @@ | ||
import { databaseBuffer } from '../../../database-buffer.js'; | ||
import { buildFeature } from '../../build-feature.js'; | ||
import { buildOrganizationLearner } from '../../build-organization-learner.js'; | ||
|
||
const buildOrganizationLearnerFeature = function ({ | ||
id = databaseBuffer.getNextId(), | ||
organizationLearnerId, | ||
featureId, | ||
} = {}) { | ||
organizationLearnerId = organizationLearnerId === undefined ? buildOrganizationLearner().id : organizationLearnerId; | ||
featureId = featureId === undefined ? buildFeature().id : featureId; | ||
|
||
const values = { | ||
id, | ||
organizationLearnerId, | ||
featureId, | ||
}; | ||
|
||
return databaseBuffer.pushInsertable({ | ||
tableName: 'organization-learner-features', | ||
values, | ||
}); | ||
}; | ||
|
||
export { buildOrganizationLearnerFeature }; |
22 changes: 22 additions & 0 deletions
22
api/db/migrations/20241015153115_create-table-organization-learner-features.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,22 @@ | ||
const TABLE_NAME = 'organization-learner-features'; | ||
const CONSTRAINT_NAME = 'organizationLearnerId_featureId_unique'; | ||
|
||
const up = async function (knex) { | ||
return knex.schema.createTable(TABLE_NAME, function (table) { | ||
table.bigIncrements().primary(); | ||
table.bigInteger('featureId').references('features.id').notNullable().comment('Feature identifier'); | ||
table | ||
.bigInteger('organizationLearnerId') | ||
.references('organization-learners.id') | ||
.notNullable() | ||
.comment('Identifier of the organization learner having the feature'); | ||
table.unique(['featureId', 'organizationLearnerId'], CONSTRAINT_NAME); | ||
table.comment('Association table between organization-learners and features.'); | ||
}); | ||
}; | ||
|
||
const down = async function (knex) { | ||
return knex.schema.dropTable(TABLE_NAME); | ||
}; | ||
|
||
export { down, up }; |
23 changes: 23 additions & 0 deletions
23
api/db/migrations/20241016094500_add-oralization-to-features.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,23 @@ | ||
// Make sure you properly test your migration, especially DDL (Data Definition Language) | ||
// ! If the target table is large, and the migration take more than 20 minutes, the deployment will fail ! | ||
|
||
// You can design and test your migration to avoid this by following this guide | ||
// https://1024pix.atlassian.net/wiki/spaces/DEV/pages/2153512965/Cr+er+une+migration | ||
|
||
// If your migrations target `answers` or `knowledge-elements` | ||
// contact @team-captains, because automatic migrations are not active on `pix-datawarehouse-production` | ||
// this may prevent data replication to succeed the day after your migration is deployed on `pix-api-production` | ||
import { ORGANIZATION_FEATURE } from '../../src/shared/domain/constants.js'; | ||
|
||
const up = async function (knex) { | ||
await knex('features').insert({ | ||
key: ORGANIZATION_FEATURE.ORALIZATION_MANAGED_BY_PRESCRIBER.key, | ||
description: ORGANIZATION_FEATURE.ORALIZATION_MANAGED_BY_PRESCRIBER.description, | ||
}); | ||
}; | ||
|
||
const down = async function (knex) { | ||
await knex('features').where({ key: ORGANIZATION_FEATURE.ORALIZATION_MANAGED_BY_PRESCRIBER.key }).delete(); | ||
}; | ||
|
||
export { down, up }; |
28 changes: 28 additions & 0 deletions
28
api/db/migrations/20241016095050_add-oralization-feature-to-sco-1d-organizations.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,28 @@ | ||
const up = async function (knex) { | ||
const feature = await knex.select('id').from('features').where({ key: 'ORALIZATION' }).first(); | ||
const organizationIdsSco1d = await knex.select('id').from('organizations').where({ type: 'SCO-1D' }); | ||
|
||
for await (const organization of organizationIdsSco1d) { | ||
await knex('organization-features') | ||
.insert({ | ||
organizationId: organization.id, | ||
featureId: feature.id, | ||
}) | ||
.onConflict() | ||
.ignore(); | ||
} | ||
}; | ||
|
||
const down = async function (knex) { | ||
const [feature] = await knex.select('id').from('features').where({ key: 'ORALIZATION' }).limit(1); | ||
const organizationIdsSco1d = await knex.select('id').from('organizations').where({ type: 'SCO-1D' }); | ||
|
||
for await (const organization of organizationIdsSco1d) { | ||
await knex('organization-features').del().where({ | ||
organizationId: organization.id, | ||
featureId: feature.id, | ||
}); | ||
} | ||
}; | ||
|
||
export { down, up }; |
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
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
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.