Skip to content

Commit 89338d0

Browse files
authored
[FEATURE] affiche les lots de place dans orga (PIX-14009) (#10103)
1 parent 2ffea5c commit 89338d0

File tree

35 files changed

+415
-71
lines changed

35 files changed

+415
-71
lines changed

api/db/seeds/data/team-prescription/build-place-lots.js api/db/seeds/data/team-prescription/build-places-lots.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { REAL_PIX_SUPER_ADMIN_ID } from '../common/constants.js';
88
import { PRO_ORGANIZATION_ID } from '../common/constants.js';
99

10-
function _buildPlaceLotsForProOrganization(databaseBuilder) {
10+
function _buildPlacesLotsForProOrganization(databaseBuilder) {
1111
databaseBuilder.factory.buildOrganizationPlace({
1212
organizationId: PRO_ORGANIZATION_ID,
1313
category: T3,
@@ -57,7 +57,7 @@ function _buildPlaceLotsForProOrganization(databaseBuilder) {
5757
});
5858
}
5959

60-
export function buildPlaceLots(databaseBuilder) {
61-
_buildPlaceLotsForProOrganization(databaseBuilder);
60+
export function buildPlacesLots(databaseBuilder) {
61+
_buildPlacesLotsForProOrganization(databaseBuilder);
6262
return databaseBuilder.commit();
6363
}

api/db/seeds/data/team-prescription/data-builder.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { buildCampaigns } from './build-campaigns.js';
22
import { buildOrganizationLearners } from './build-learners.js';
3-
import { buildPlaceLots } from './build-place-lots.js';
3+
import { buildPlacesLots } from './build-places-lots.js';
44
import { buildQuests } from './build-quests.js';
55
import { buildTargetProfiles } from './build-target-profiles.js';
66

77
async function teamPrescriptionDataBuilder({ databaseBuilder }) {
88
await buildTargetProfiles(databaseBuilder);
99
await buildCampaigns(databaseBuilder);
1010
await buildOrganizationLearners(databaseBuilder);
11-
await buildPlaceLots(databaseBuilder);
11+
await buildPlacesLots(databaseBuilder);
1212
await buildQuests(databaseBuilder);
1313
}
1414

api/scripts/prod/create-organization-places-lot.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function prepareOrganizationPlacesLot(organizationPlacesLotData, log = tru
2222
const activationDateInCorrectFormat = activationDate?.split('/').reverse().join('-');
2323
const expirationDateInCorrectFormat = expirationDate?.split('/').reverse().join('-');
2424

25-
const organizationPlaceLot = new OrganizationPlacesLotForManagement({
25+
const organizationPlacesLot = new OrganizationPlacesLotForManagement({
2626
createdBy,
2727
organizationId,
2828
count,
@@ -33,9 +33,9 @@ async function prepareOrganizationPlacesLot(organizationPlacesLotData, log = tru
3333
});
3434

3535
_log(
36-
`Lot de ${organizationPlaceLot.count} places ${organizationPlaceLot.category} pour l'organisation ${organizationPlaceLot.organizationId} ===> ✔\n`,
36+
`Lot de ${organizationPlacesLot.count} places ${organizationPlacesLot.category} pour l'organisation ${organizationPlacesLot.organizationId} ===> ✔\n`,
3737
);
38-
return organizationPlaceLot;
38+
return organizationPlacesLot;
3939
},
4040
);
4141

api/src/prescription/organization-place/application/organization-place-controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const deleteOrganizationPlacesLot = async function (request, h) {
3030
const organizationPlaceId = request.params.placeId;
3131
const userId = request.auth.credentials.userId;
3232

33-
await usecases.deleteOrganizationPlaceLot({ organizationPlaceId, userId });
33+
await usecases.deleteOrganizationPlacesLot({ organizationPlaceId, userId });
3434

3535
return h.response(null).code(204);
3636
};

api/src/prescription/organization-place/domain/read-models/PlacesLot.js

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const Joi = BaseJoi.extend(JoiDate);
44
import { validateEntity } from '../../../../shared/domain/validators/entity-validator.js';
55

66
const validationSchema = Joi.object({
7+
id: Joi.number().required(),
78
count: Joi.number().required().allow(null),
89
organizationId: Joi.number(),
910
activationDate: Joi.date().required(),
@@ -18,18 +19,24 @@ const statuses = {
1819
};
1920

2021
export class PlacesLot {
22+
#id;
2123
#activationDate;
2224
#expirationDate;
2325
#deletedAt;
2426
constructor(params = {}) {
2527
validateEntity(validationSchema, params);
28+
this.#id = params.id;
2629
this.count = params.count;
2730
this.organizationId = params.organizationId;
2831
this.#activationDate = params.activationDate;
2932
this.#expirationDate = params.expirationDate;
3033
this.#deletedAt = params.deletedAt;
3134
}
3235

36+
get id() {
37+
return this.#id;
38+
}
39+
3340
get isActive() {
3441
return this.status === statuses.ACTIVE && !this.#deletedAt;
3542
}

api/src/prescription/organization-place/domain/usecases/create-organization-places-lot.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ const createOrganizationPlacesLot = async function ({
99
}) {
1010
await organizationRepository.get(organizationId);
1111

12-
const organizationPlaceLot = new OrganizationPlacesLotForManagement({
12+
const organizationPlacesLot = new OrganizationPlacesLotForManagement({
1313
...organizationPlacesLotData,
1414
organizationId,
1515
createdBy,
1616
});
1717

18-
const id = await organizationPlacesLotRepository.create(organizationPlaceLot);
18+
const id = await organizationPlacesLotRepository.create(organizationPlacesLot);
1919
return await organizationPlacesLotRepository.get(id);
2020
};
2121

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const deleteOrganizationPlaceLot = async function ({ organizationPlaceId, userId, organizationPlacesLotRepository }) {
1+
const deleteOrganizationPlacesLot = async function ({ organizationPlaceId, userId, organizationPlacesLotRepository }) {
22
await organizationPlacesLotRepository.get(organizationPlaceId);
33
await organizationPlacesLotRepository.remove({ id: organizationPlaceId, deletedBy: userId });
44
};
55

6-
export { deleteOrganizationPlaceLot };
6+
export { deleteOrganizationPlacesLot };

api/src/prescription/organization-place/domain/usecases/get-organization-places-lots.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @typedef {object} payload
55
* @property {number} organizationId
66
* @property {organizationPlacesLotRepository} organizationPlacesLotRepository
7-
* @returns {Promise<Array<PlaceLots>>}
7+
* @returns {Promise<Array<PlacesLots>>}
88
*/
99

1010
/**

api/src/prescription/organization-place/infrastructure/repositories/organization-places-lot-repository.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ const findByOrganizationId = async function (organizationId) {
3232
const findAllByOrganizationId = async function (organizationId) {
3333
const knexConn = DomainTransaction.getConnection();
3434
const placesLots = await knexConn('organization-places')
35-
.select('count', 'activationDate', 'expirationDate', 'deletedAt')
35+
.select('id', 'count', 'activationDate', 'expirationDate', 'deletedAt')
3636
.where({ organizationId });
3737
return placesLots.map((e) => new PlacesLot(e));
3838
};
3939

4040
const findAllByOrganizationIds = async function (organizationIds) {
4141
const knexConn = DomainTransaction.getConnection();
4242
const placesLots = await knexConn('organization-places')
43-
.select('count', 'organizationId', 'activationDate', 'expirationDate', 'deletedAt')
43+
.select('id', 'count', 'organizationId', 'activationDate', 'expirationDate', 'deletedAt')
4444
.whereIn('organizationId', organizationIds);
4545

4646
return placesLots.map((e) => new PlacesLot(e));
@@ -51,7 +51,7 @@ const findAllByOrganizationIds = async function (organizationIds) {
5151
const findAllNotDeletedByOrganizationId = async function (organizationId) {
5252
const knexConn = DomainTransaction.getConnection();
5353
const placesLots = await knexConn('organization-places')
54-
.select('count', 'activationDate', 'expirationDate', 'deletedAt')
54+
.select('id', 'count', 'activationDate', 'expirationDate', 'deletedAt')
5555
.where({ organizationId })
5656
.whereNull('deletedAt')
5757
.orderBy(
@@ -64,7 +64,7 @@ const findAllNotDeletedByOrganizationId = async function (organizationId) {
6464
.orderBy('activationDate', 'desc')
6565
.orderBy('createdAt', 'desc');
6666

67-
return placesLots.map((placeLot) => new PlacesLot(placeLot));
67+
return placesLots.map((placesLot) => new PlacesLot(placesLot));
6868
};
6969

7070
const get = async function (id) {

api/src/prescription/organization-place/infrastructure/serializers/jsonapi/organization-places-lots-serializer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import jsonapiSerializer from 'jsonapi-serializer';
33
const { Serializer } = jsonapiSerializer;
44

55
const serialize = function (places) {
6-
return new Serializer('organization-place', {
6+
return new Serializer('organization-places-lot', {
77
attributes: ['organizationId', 'count', 'activationDate', 'expirationDate', 'status'],
88
}).serialize(places);
99
};

api/tests/integration/infrastructure/repositories/organization-repository_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ describe('Integration | Repository | Organization', function () {
10961096
expect(organizationsWithPlaces[0].type).to.equal(firstOrganization.type);
10971097
});
10981098

1099-
it('should return only once an organization with many placeLots', async function () {
1099+
it('should return only once an organization with many placesLots', async function () {
11001100
// given
11011101
const superAdminUserId = databaseBuilder.factory.buildUser().id;
11021102

api/tests/prescription/organization-place/acceptance/application/get-organization-places-lots_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Acceptance | Route | Get Organizations Places Lots', function () {
4444
const response = await server.inject(options);
4545

4646
// then
47-
expect(response.result.data[0].type).to.equal('organization-places');
47+
expect(response.result.data[0].type).to.equal('organization-places-lots');
4848
expect(response.statusCode).to.equal(200);
4949
});
5050
});

api/tests/prescription/organization-place/integration/infrastructure/repositories/organization-places-lot-repository_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ describe('Integration | Repository | Organization Places Lot', function () {
218218
await databaseBuilder.commit();
219219
});
220220

221-
it('should return array of PlaceLot model', async function () {
221+
it('should return array of PlacesLot model', async function () {
222222
databaseBuilder.factory.buildOrganizationPlace({ organizationId });
223223
await databaseBuilder.commit();
224224

@@ -227,15 +227,15 @@ describe('Integration | Repository | Organization Places Lot', function () {
227227
expect(places[0]).to.be.instanceOf(PlacesLot);
228228
});
229229

230-
it('should return empty array if there is no placelots', async function () {
230+
it('should return empty array if there is no placeslots', async function () {
231231
await databaseBuilder.commit();
232232

233233
const places = await organizationPlacesLotRepository.findAllByOrganizationId(organizationId);
234234

235235
expect(places).to.be.empty;
236236
});
237237

238-
it('should return placelots if there are places for given organizationId', async function () {
238+
it('should return placeslots if there are places for given organizationId', async function () {
239239
databaseBuilder.factory.buildOrganizationPlace({
240240
organizationId,
241241
count: 7,

api/tests/prescription/organization-place/unit/domain/read-models/DataOrganizationPlacesStatistics_test.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('Unit | Domain | ReadModels | DataOrganizationPlacesStatistics', functi
2525
const placeStatistics = new PlaceStatistics({
2626
placesLots: [
2727
new PlacesLot({
28+
id: 1,
2829
count: 10,
2930
expirationDate: new Date('2022-05-02'),
3031
activationDate: new Date('2019-04-01'),

api/tests/prescription/organization-place/unit/domain/read-models/PlaceStatistics_test.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
5252
const statistics = new PlaceStatistics({
5353
placesLots: [
5454
new PlacesLot({
55+
id: 1,
5556
count: 1,
5657
expirationDate: new Date('2021-05-02'),
5758
activationDate: new Date('2021-04-01'),
@@ -68,12 +69,14 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
6869
const statistics = new PlaceStatistics({
6970
placesLots: [
7071
new PlacesLot({
72+
id: 1,
7173
count: 1,
7274
expirationDate: new Date('2021-05-02'),
7375
activationDate: new Date('2021-04-01'),
7476
deletedAt: null,
7577
}),
7678
new PlacesLot({
79+
id: 2,
7780
count: 1,
7881
expirationDate: new Date('2021-05-02'),
7982
activationDate: new Date('2021-04-01'),
@@ -118,6 +121,7 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
118121
const statistics = new PlaceStatistics({
119122
placesLots: [
120123
new PlacesLot({
124+
id: 1,
121125
count: 1,
122126
expirationDate: new Date('2021-05-02'),
123127
activationDate: new Date('2021-04-01'),
@@ -134,6 +138,7 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
134138
const statistics = new PlaceStatistics({
135139
placesLots: [
136140
new PlacesLot({
141+
id: 1,
137142
count: 2,
138143
expirationDate: new Date('2021-05-02'),
139144
activationDate: new Date('2021-04-01'),
@@ -149,7 +154,13 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
149154
it('should return 0 when there are more participant than total places', function () {
150155
const statistics = new PlaceStatistics({
151156
placesLots: [
152-
{ count: 2, expirationDate: new Date('2021-05-02'), activationDate: new Date('2021-04-01'), deletedAt: null },
157+
{
158+
id: 1,
159+
count: 2,
160+
expirationDate: new Date('2021-05-02'),
161+
activationDate: new Date('2021-04-01'),
162+
deletedAt: null,
163+
},
153164
],
154165
placeRepartition: { totalUnRegisteredParticipant: 0, totalRegisteredParticipant: 3 },
155166
});
@@ -169,6 +180,7 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
169180
const statistics = new PlaceStatistics({
170181
placesLots: [
171182
new PlacesLot({
183+
id: 1,
172184
count: 3,
173185
expirationDate: new Date('2021-05-02'),
174186
activationDate: new Date('2021-04-01'),
@@ -184,18 +196,21 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
184196
const statistics = new PlaceStatistics({
185197
placesLots: [
186198
new PlacesLot({
199+
id: 1,
187200
count: 1,
188201
expirationDate: new Date('2021-05-02'),
189202
activationDate: new Date('2021-04-01'),
190203
deletedAt: null,
191204
}),
192205
new PlacesLot({
206+
id: 2,
193207
count: 10,
194208
expirationDate: new Date('2021-05-02'),
195209
activationDate: new Date('2021-04-01'),
196210
deletedAt: null,
197211
}),
198212
new PlacesLot({
213+
id: 3,
199214
count: 10,
200215
expirationDate: new Date('2020-05-02'),
201216
activationDate: new Date('2019-04-01'),

0 commit comments

Comments
 (0)