Skip to content

Commit

Permalink
[FEATURE] affiche les lots de place dans orga (PIX-14009) (#10103)
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelB committed Sep 16, 2024
1 parent 2ffea5c commit 89338d0
Show file tree
Hide file tree
Showing 35 changed files with 415 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { REAL_PIX_SUPER_ADMIN_ID } from '../common/constants.js';
import { PRO_ORGANIZATION_ID } from '../common/constants.js';

function _buildPlaceLotsForProOrganization(databaseBuilder) {
function _buildPlacesLotsForProOrganization(databaseBuilder) {
databaseBuilder.factory.buildOrganizationPlace({
organizationId: PRO_ORGANIZATION_ID,
category: T3,
Expand Down Expand Up @@ -57,7 +57,7 @@ function _buildPlaceLotsForProOrganization(databaseBuilder) {
});
}

export function buildPlaceLots(databaseBuilder) {
_buildPlaceLotsForProOrganization(databaseBuilder);
export function buildPlacesLots(databaseBuilder) {
_buildPlacesLotsForProOrganization(databaseBuilder);
return databaseBuilder.commit();
}
4 changes: 2 additions & 2 deletions api/db/seeds/data/team-prescription/data-builder.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { buildCampaigns } from './build-campaigns.js';
import { buildOrganizationLearners } from './build-learners.js';
import { buildPlaceLots } from './build-place-lots.js';
import { buildPlacesLots } from './build-places-lots.js';
import { buildQuests } from './build-quests.js';
import { buildTargetProfiles } from './build-target-profiles.js';

async function teamPrescriptionDataBuilder({ databaseBuilder }) {
await buildTargetProfiles(databaseBuilder);
await buildCampaigns(databaseBuilder);
await buildOrganizationLearners(databaseBuilder);
await buildPlaceLots(databaseBuilder);
await buildPlacesLots(databaseBuilder);
await buildQuests(databaseBuilder);
}

Expand Down
6 changes: 3 additions & 3 deletions api/scripts/prod/create-organization-places-lot.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function prepareOrganizationPlacesLot(organizationPlacesLotData, log = tru
const activationDateInCorrectFormat = activationDate?.split('/').reverse().join('-');
const expirationDateInCorrectFormat = expirationDate?.split('/').reverse().join('-');

const organizationPlaceLot = new OrganizationPlacesLotForManagement({
const organizationPlacesLot = new OrganizationPlacesLotForManagement({
createdBy,
organizationId,
count,
Expand All @@ -33,9 +33,9 @@ async function prepareOrganizationPlacesLot(organizationPlacesLotData, log = tru
});

_log(
`Lot de ${organizationPlaceLot.count} places ${organizationPlaceLot.category} pour l'organisation ${organizationPlaceLot.organizationId} ===> ✔\n`,
`Lot de ${organizationPlacesLot.count} places ${organizationPlacesLot.category} pour l'organisation ${organizationPlacesLot.organizationId} ===> ✔\n`,
);
return organizationPlaceLot;
return organizationPlacesLot;
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const deleteOrganizationPlacesLot = async function (request, h) {
const organizationPlaceId = request.params.placeId;
const userId = request.auth.credentials.userId;

await usecases.deleteOrganizationPlaceLot({ organizationPlaceId, userId });
await usecases.deleteOrganizationPlacesLot({ organizationPlaceId, userId });

return h.response(null).code(204);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Joi = BaseJoi.extend(JoiDate);
import { validateEntity } from '../../../../shared/domain/validators/entity-validator.js';

const validationSchema = Joi.object({
id: Joi.number().required(),
count: Joi.number().required().allow(null),
organizationId: Joi.number(),
activationDate: Joi.date().required(),
Expand All @@ -18,18 +19,24 @@ const statuses = {
};

export class PlacesLot {
#id;
#activationDate;
#expirationDate;
#deletedAt;
constructor(params = {}) {
validateEntity(validationSchema, params);
this.#id = params.id;
this.count = params.count;
this.organizationId = params.organizationId;
this.#activationDate = params.activationDate;
this.#expirationDate = params.expirationDate;
this.#deletedAt = params.deletedAt;
}

get id() {
return this.#id;
}

get isActive() {
return this.status === statuses.ACTIVE && !this.#deletedAt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const createOrganizationPlacesLot = async function ({
}) {
await organizationRepository.get(organizationId);

const organizationPlaceLot = new OrganizationPlacesLotForManagement({
const organizationPlacesLot = new OrganizationPlacesLotForManagement({
...organizationPlacesLotData,
organizationId,
createdBy,
});

const id = await organizationPlacesLotRepository.create(organizationPlaceLot);
const id = await organizationPlacesLotRepository.create(organizationPlacesLot);
return await organizationPlacesLotRepository.get(id);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const deleteOrganizationPlaceLot = async function ({ organizationPlaceId, userId, organizationPlacesLotRepository }) {
const deleteOrganizationPlacesLot = async function ({ organizationPlaceId, userId, organizationPlacesLotRepository }) {
await organizationPlacesLotRepository.get(organizationPlaceId);
await organizationPlacesLotRepository.remove({ id: organizationPlaceId, deletedBy: userId });
};

export { deleteOrganizationPlaceLot };
export { deleteOrganizationPlacesLot };
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @typedef {object} payload
* @property {number} organizationId
* @property {organizationPlacesLotRepository} organizationPlacesLotRepository
* @returns {Promise<Array<PlaceLots>>}
* @returns {Promise<Array<PlacesLots>>}
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ const findByOrganizationId = async function (organizationId) {
const findAllByOrganizationId = async function (organizationId) {
const knexConn = DomainTransaction.getConnection();
const placesLots = await knexConn('organization-places')
.select('count', 'activationDate', 'expirationDate', 'deletedAt')
.select('id', 'count', 'activationDate', 'expirationDate', 'deletedAt')
.where({ organizationId });
return placesLots.map((e) => new PlacesLot(e));
};

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

return placesLots.map((e) => new PlacesLot(e));
Expand All @@ -51,7 +51,7 @@ const findAllByOrganizationIds = async function (organizationIds) {
const findAllNotDeletedByOrganizationId = async function (organizationId) {
const knexConn = DomainTransaction.getConnection();
const placesLots = await knexConn('organization-places')
.select('count', 'activationDate', 'expirationDate', 'deletedAt')
.select('id', 'count', 'activationDate', 'expirationDate', 'deletedAt')
.where({ organizationId })
.whereNull('deletedAt')
.orderBy(
Expand All @@ -64,7 +64,7 @@ const findAllNotDeletedByOrganizationId = async function (organizationId) {
.orderBy('activationDate', 'desc')
.orderBy('createdAt', 'desc');

return placesLots.map((placeLot) => new PlacesLot(placeLot));
return placesLots.map((placesLot) => new PlacesLot(placesLot));
};

const get = async function (id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import jsonapiSerializer from 'jsonapi-serializer';
const { Serializer } = jsonapiSerializer;

const serialize = function (places) {
return new Serializer('organization-place', {
return new Serializer('organization-places-lot', {
attributes: ['organizationId', 'count', 'activationDate', 'expirationDate', 'status'],
}).serialize(places);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ describe('Integration | Repository | Organization', function () {
expect(organizationsWithPlaces[0].type).to.equal(firstOrganization.type);
});

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Acceptance | Route | Get Organizations Places Lots', function () {
const response = await server.inject(options);

// then
expect(response.result.data[0].type).to.equal('organization-places');
expect(response.result.data[0].type).to.equal('organization-places-lots');
expect(response.statusCode).to.equal(200);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('Integration | Repository | Organization Places Lot', function () {
await databaseBuilder.commit();
});

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

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

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

const places = await organizationPlacesLotRepository.findAllByOrganizationId(organizationId);

expect(places).to.be.empty;
});

it('should return placelots if there are places for given organizationId', async function () {
it('should return placeslots if there are places for given organizationId', async function () {
databaseBuilder.factory.buildOrganizationPlace({
organizationId,
count: 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('Unit | Domain | ReadModels | DataOrganizationPlacesStatistics', functi
const placeStatistics = new PlaceStatistics({
placesLots: [
new PlacesLot({
id: 1,
count: 10,
expirationDate: new Date('2022-05-02'),
activationDate: new Date('2019-04-01'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
const statistics = new PlaceStatistics({
placesLots: [
new PlacesLot({
id: 1,
count: 1,
expirationDate: new Date('2021-05-02'),
activationDate: new Date('2021-04-01'),
Expand All @@ -68,12 +69,14 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
const statistics = new PlaceStatistics({
placesLots: [
new PlacesLot({
id: 1,
count: 1,
expirationDate: new Date('2021-05-02'),
activationDate: new Date('2021-04-01'),
deletedAt: null,
}),
new PlacesLot({
id: 2,
count: 1,
expirationDate: new Date('2021-05-02'),
activationDate: new Date('2021-04-01'),
Expand Down Expand Up @@ -118,6 +121,7 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
const statistics = new PlaceStatistics({
placesLots: [
new PlacesLot({
id: 1,
count: 1,
expirationDate: new Date('2021-05-02'),
activationDate: new Date('2021-04-01'),
Expand All @@ -134,6 +138,7 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
const statistics = new PlaceStatistics({
placesLots: [
new PlacesLot({
id: 1,
count: 2,
expirationDate: new Date('2021-05-02'),
activationDate: new Date('2021-04-01'),
Expand All @@ -149,7 +154,13 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
it('should return 0 when there are more participant than total places', function () {
const statistics = new PlaceStatistics({
placesLots: [
{ count: 2, expirationDate: new Date('2021-05-02'), activationDate: new Date('2021-04-01'), deletedAt: null },
{
id: 1,
count: 2,
expirationDate: new Date('2021-05-02'),
activationDate: new Date('2021-04-01'),
deletedAt: null,
},
],
placeRepartition: { totalUnRegisteredParticipant: 0, totalRegisteredParticipant: 3 },
});
Expand All @@ -169,6 +180,7 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
const statistics = new PlaceStatistics({
placesLots: [
new PlacesLot({
id: 1,
count: 3,
expirationDate: new Date('2021-05-02'),
activationDate: new Date('2021-04-01'),
Expand All @@ -184,18 +196,21 @@ describe('Unit | Domain | ReadModels | PlaceStatistics', function () {
const statistics = new PlaceStatistics({
placesLots: [
new PlacesLot({
id: 1,
count: 1,
expirationDate: new Date('2021-05-02'),
activationDate: new Date('2021-04-01'),
deletedAt: null,
}),
new PlacesLot({
id: 2,
count: 10,
expirationDate: new Date('2021-05-02'),
activationDate: new Date('2021-04-01'),
deletedAt: null,
}),
new PlacesLot({
id: 3,
count: 10,
expirationDate: new Date('2020-05-02'),
activationDate: new Date('2019-04-01'),
Expand Down
Loading

0 comments on commit 89338d0

Please sign in to comment.