-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TECH] Refacto des badges des certifications complémentaires (PIX-9862) #7447
Changes from all commits
33b7818
58909bf
6226051
1287cb3
8b95d88
0785cf8
86e3c86
ab718c2
b6728f7
d2e14ab
caafd89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const TABLE_NAME = 'complementary-certification-course-results'; | ||
const REF_TABLE_NAME = 'complementary-certification-badges'; | ||
const COLUMN_NAME = 'complementaryCertificationBadgeId'; | ||
|
||
const up = async function (knex) { | ||
await knex.schema.table(TABLE_NAME, function (table) { | ||
table | ||
.integer(COLUMN_NAME) | ||
.defaultTo(null) | ||
.references(`${REF_TABLE_NAME}.id`) | ||
.withKeyName('cccresults-ccbadgeId_foreignkey'); | ||
}); | ||
|
||
await knex(TABLE_NAME).update({ | ||
[COLUMN_NAME]: knex(`${REF_TABLE_NAME}`) | ||
.select(`${REF_TABLE_NAME}.id`) | ||
.innerJoin('badges', 'badges.id', `${REF_TABLE_NAME}.badgeId`) | ||
// eslint-disable-next-line knex/avoid-injections | ||
.where('badges.key', '=', knex.raw(`"${TABLE_NAME}"."partnerKey"`)), | ||
}); | ||
}; | ||
|
||
const down = async function (knex) { | ||
await knex.schema.table(TABLE_NAME, function (table) { | ||
table.dropColumn(COLUMN_NAME); | ||
}); | ||
}; | ||
|
||
export { up, down }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import Joi from 'joi'; | |
import { identifiersType } from '../../domain/types/identifiers-type.js'; | ||
import { securityPreHandlers } from '../security-pre-handlers.js'; | ||
import { complementaryCertificationCourseResultsController } from './complementary-certification-course-results-controller.js'; | ||
import { juryOptions } from '../../domain/models/ComplementaryCertificationCourseResult.js'; | ||
|
||
const register = async function (server) { | ||
server.route([ | ||
|
@@ -13,7 +14,12 @@ const register = async function (server) { | |
payload: Joi.object({ | ||
data: { | ||
attributes: { | ||
juryLevel: Joi.string().required(), | ||
juryLevel: Joi.alternatives() | ||
.try( | ||
identifiersType.complementaryCertificationBadgeId, | ||
Joi.string().valid(juryOptions.REJECTED).valid(juryOptions.UNSET), | ||
Comment on lines
+19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah oui le juryLevel ça peut soit être un id soit une string dans le cas d'un jury échoué ou en attente ? |
||
) | ||
.required(), | ||
complementaryCertificationCourseId: identifiersType.complementaryCertificationCourseId, | ||
}, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,37 +9,37 @@ const juryOptions = { | |
}; | ||
|
||
class ComplementaryCertificationCourseResult { | ||
constructor({ complementaryCertificationCourseId, partnerKey, source, acquired, label } = {}) { | ||
constructor({ complementaryCertificationCourseId, complementaryCertificationBadgeId, source, acquired, label } = {}) { | ||
this.complementaryCertificationCourseId = complementaryCertificationCourseId; | ||
this.partnerKey = partnerKey; | ||
this.complementaryCertificationBadgeId = complementaryCertificationBadgeId; | ||
this.acquired = acquired; | ||
this.source = source; | ||
this.label = label; | ||
} | ||
|
||
static from({ complementaryCertificationCourseId, partnerKey, acquired, source, label }) { | ||
static from({ complementaryCertificationCourseId, complementaryCertificationBadgeId, acquired, source, label }) { | ||
return new ComplementaryCertificationCourseResult({ | ||
complementaryCertificationCourseId, | ||
partnerKey, | ||
complementaryCertificationBadgeId, | ||
acquired, | ||
source, | ||
label, | ||
}); | ||
} | ||
|
||
static buildFromJuryLevel({ complementaryCertificationCourseId, juryLevel, pixPartnerKey }) { | ||
if (juryLevel === juryOptions.REJECTED) { | ||
static buildFromJuryLevel({ complementaryCertificationCourseId, complementaryCertificationBadgeId, juryLevel }) { | ||
if (juryLevel === 'REJECTED') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question : Je ne sais pas dans quel contexte on se trouve ici mais il n'y a pas un risque d'avoir un juryLevel à UNSET ici et qu'il finisse à la ligne 42 ? |
||
return new ComplementaryCertificationCourseResult({ | ||
complementaryCertificationCourseId, | ||
partnerKey: pixPartnerKey, | ||
complementaryCertificationBadgeId, | ||
acquired: false, | ||
source: sources.EXTERNAL, | ||
}); | ||
} | ||
|
||
return new ComplementaryCertificationCourseResult({ | ||
complementaryCertificationCourseId, | ||
partnerKey: juryLevel, | ||
complementaryCertificationBadgeId: juryLevel, | ||
P-Jeremy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
acquired: true, | ||
source: sources.EXTERNAL, | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pas trop d'inquiétude à se faire niveau perf de cette migration ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a moins de 3000 lignes à mettre à jour, c'est OK