Skip to content

Commit

Permalink
[TECH] Faciliter le build des seeds en base de données avec JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Jun 10, 2024
2 parents 6838856 + dd64bab commit a02659c
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api/db/database-builder/database-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import { databaseBuffer } from './database-buffer.js';
import * as databaseHelpers from './database-helpers.js';
import { factory } from './factory/index.js';

/**
* @class DatabaseBuilder
* @property {Factory} factory
*/
class DatabaseBuilder {
constructor({ knex, emptyFirst = true, beforeEmptyDatabase = () => undefined }) {
this.knex = knex;
this.databaseBuffer = databaseBuffer;
this.tablesOrderedByDependencyWithDirtinessMap = [];
this.factory = factory;
this.isFirstCommit = true;
this.factory = factory;
this.emptyFirst = emptyFirst;
this._beforeEmptyDatabase = beforeEmptyDatabase;

Expand Down
30 changes: 30 additions & 0 deletions api/db/database-builder/factory/build-data-protection-officer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@ import { databaseBuffer } from '../database-buffer.js';

const TABLE_NAME = 'data-protection-officers';

/**
* @typedef {{
* id: number,
* firstName: string,
* lastName: string,
* email: string,
* certificationCenterId: number,
* createdAt: Date,
* updatedAt: Date,
* }} CertificationCenter
*/

/**
* @typedef {{
* id: number,
* firstName: string,
* lastName: string,
* email: string,
* certificationCenterId: number,
* createdAt: Date,
* updatedAt: Date,
* }} Organization
*/

function buildCertificationCenterDataProtectionOfficer({
id = databaseBuffer.getNextId(),
firstName,
Expand Down Expand Up @@ -52,6 +76,12 @@ function buildOrganizationDataProtectionOfficer({
});
}

/**
* @typedef {{
* withCertificationCenterId: function(Partial<CertificationCenter>): CertificationCenter,
* withOrganizationId: function(Partial<Organization>): Organization,
* }} BuildDataProtectionOfficerFactory
*/
export {
buildCertificationCenterDataProtectionOfficer as withCertificationCenterId,
buildOrganizationDataProtectionOfficer as withOrganizationId,
Expand Down
41 changes: 41 additions & 0 deletions api/db/database-builder/factory/build-organization-learner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@ import { databaseBuffer } from '../database-buffer.js';
import { buildOrganization } from './build-organization.js';
import { buildUser } from './build-user.js';

/**
* @typedef SeedOrganizationLearner
* @type {object}
*
* @property {number} id
* @property {string} firstName
* @property {string} preferredLastName
* @property {string} lastName
* @property {string} middleName
* @property {string} thirdName
* @property {string} sex
* @property {string} birthdate
* @property {string} birthCity
* @property {string} birthCityCode
* @property {string} birthCountryCode
* @property {string} birthProvinceCode
* @property {string} MEFCode
* @property {string} status
* @property {string} nationalStudentId
* @property {string} division
* @property {string} studentNumber
* @property {string} email
* @property {string} educationalTeam
* @property {string} department
* @property {string} group
* @property {string} diploma
* @property {boolean} isDisabled
* @property {Date} createdAt
* @property {Date} updatedAt
* @property {number} organizationId
* @property {number} userId
* @property {number} deletedBy
* @property {Date} deletedAt
* @property {boolean} isCertifiable
* @property {Date} certifiableAt
*/
const buildOrganizationLearner = function ({
id = databaseBuffer.getNextId(),
firstName = 'first-name',
Expand Down Expand Up @@ -80,4 +116,9 @@ const buildOrganizationLearner = function ({
});
};

/**
* @typedef {
* function(Partial<SeedOrganizationLearner>): SeedOrganizationLearner
* } BuildOrganizationLearner
*/
export { buildOrganizationLearner };
20 changes: 20 additions & 0 deletions api/db/database-builder/factory/build-training.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import { databaseBuffer } from '../database-buffer.js';

/**
* @typedef {{
* id: number,
* title: string,
* link: string,
* type: string,
* duration: string,
* locale: string,
* editorName: string,
* editorLogoUrl: string,
* createdAt: Date,
* updatedAt: Date
* }} Training
*/

function buildTraining({
id = databaseBuffer.getNextId(),
title = 'title',
Expand Down Expand Up @@ -32,4 +47,9 @@ function buildTraining({
});
}

/**
* @typedef {
* function(Partial<Training>): Training
* } BuildTraining
*/
export { buildTraining };
37 changes: 37 additions & 0 deletions api/db/database-builder/factory/build-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,37 @@ function _generateAnEmailIfNecessary(email, id, lastName, firstName) {
return null;
}

/**
* @typedef SeedUser
* @type {object}
*
* @property {number} id
* @property {string} firstName
* @property {string} lastName
* @property {string} email
* @property {string} username
* @property {boolean} cgu
* @property {string} lang
* @property {string} locale
* @property {Date} lastTermsOfServiceValidatedAt
* @property {Date} lastPixOrgaTermsOfServiceValidatedAt
* @property {Date} lastPixCertifTermsOfServiceValidatedAt
* @property {boolean} mustValidateTermsOfService
* @property {boolean} pixOrgaTermsOfServiceAccepted
* @property {boolean} pixCertifTermsOfServiceAccepted
* @property {boolean} hasSeenAssessmentInstructions
* @property {boolean} hasSeenNewDashboardInfo
* @property {boolean} hasSeenLevelSevenInfo
* @property {boolean} hasSeenFocusedChallengeTooltip
* @property {boolean} hasSeenOtherChallengesTooltip
* @property {boolean} isAnonymous
* @property {Date} createdAt
* @property {Date} updatedAt
* @property {Date} emailConfirmedAt
* @property {boolean} hasBeenAnonymised
* @property {number} hasBeenAnonymisedBy
* @property {Date} lastDataProtectionPolicySeenAt
*/
const buildUser = function buildUser({
id = databaseBuffer.getNextId(),
firstName = 'Billy',
Expand Down Expand Up @@ -403,4 +434,10 @@ buildUser.withCertificationCenterMembership = function buildUserWithCertificatio
return user;
};

/**
* @typedef {
* function(Partial<SeedUser>): SeedUser
* } BuildUser
*/

export { buildUser };
12 changes: 12 additions & 0 deletions api/db/database-builder/factory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ const organizationLearners = await importNamedExportsFromDirectory({
ignoredFileNames: unwantedFiles,
});

/**
* Travail à continuer en scout-rule
* @see https://github.com/1024pix/pix/pull/8212
* @typedef {
* {
* buildTraining: BuildTraining,
* buildDataProtectionOfficer: BuildDataProtectionOfficerFactory,
* buildUser: BuildUser,
* buildOrganizationLearner: BuildOrganizationLearner,
* }
* } Factory
*/
export const factory = {
...databaseBuilders,
prescription: {
Expand Down

0 comments on commit a02659c

Please sign in to comment.