Skip to content

Commit 927f9cc

Browse files
[FEATURE] Permet au SUPER ADMIN de mettre à jour la colonne params sur les fonctionnalités (PIX-16763)
#11531
2 parents e6af37c + a155b4a commit 927f9cc

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

api/src/organizational-entities/infrastructure/repositories/organization-feature-repository.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ async function saveInBatch(organizationFeatures) {
2121
try {
2222
const knexConn = DomainTransaction.getConnection();
2323
await knexConn('organization-features')
24-
.insert(organizationFeatures)
24+
.insert(
25+
organizationFeatures.map((organizationFeature) => ({
26+
...organizationFeature,
27+
params: JSON.stringify(organizationFeature.params),
28+
})),
29+
)
2530
.onConflict(['featureId', 'organizationId'])
26-
.ignore();
31+
.merge();
2732
} catch (err) {
2833
if (knexUtils.foreignKeyConstraintViolated(err) && err.constraint.includes('featureid')) {
2934
throw new FeatureNotFound();

api/tests/organizational-entities/integration/infrastructure/repositories/organization-feature-repository_test.js

+40
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,46 @@ describe('Integration | Repository | Organization-for-admin', function () {
5050
expect(result[1].params).to.deep.equal(organizationFeatures[1].params);
5151
});
5252

53+
it('should update existing rows', async function () {
54+
// given
55+
const otherOrganization = databaseBuilder.factory.buildOrganization();
56+
databaseBuilder.factory.buildOrganizationFeature({
57+
featureId: feature.id,
58+
organizationId: organization.id,
59+
params: `{ "id": 0 }`,
60+
});
61+
await databaseBuilder.commit();
62+
63+
const organizationFeatures = [
64+
new OrganizationFeature({
65+
featureId: feature.id,
66+
organizationId: organization.id,
67+
params: `["SOMETHING"]`,
68+
}),
69+
new OrganizationFeature({
70+
featureId: feature.id,
71+
organizationId: otherOrganization.id,
72+
params: `{ "id": 456 }`,
73+
}),
74+
];
75+
76+
// when
77+
await organizationFeatureRepository.saveInBatch(organizationFeatures);
78+
79+
//then
80+
const result = await knex('organization-features').where({
81+
featureId: feature.id,
82+
});
83+
84+
expect(result).to.have.lengthOf(2);
85+
expect(result[0].featureId).to.deep.equal(organizationFeatures[0].featureId);
86+
expect(result[0].organizationId).to.deep.equal(organizationFeatures[0].organizationId);
87+
expect(result[0].params).to.deep.equal(organizationFeatures[0].params);
88+
expect(result[1].featureId).to.deep.equal(organizationFeatures[1].featureId);
89+
expect(result[1].organizationId).to.deep.equal(organizationFeatures[1].organizationId);
90+
expect(result[1].params).to.deep.equal(organizationFeatures[1].params);
91+
});
92+
5393
it('should passe even if organization feature already exists', async function () {
5494
databaseBuilder.factory.buildOrganizationFeature({ organizationId: organization.id, featureId: feature.id });
5595
await databaseBuilder.commit();

0 commit comments

Comments
 (0)