-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Ecoute les évènements questions répondue et détermine si un…
…e quête est validée (PIX-13819). (#10108) Co-authored-by: Guillaume Olejniczak <[email protected]> Co-authored-by: Quentin Lebouc <[email protected]>
- Loading branch information
1 parent
7141a64
commit 43927ad
Showing
47 changed files
with
1,218 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
api/src/evaluation/application/api/knowledge-elements-api.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { evaluationUsecases } from '../../domain/usecases/index.js'; | ||
import { KnowledgeElementDTO } from './models/KnowledgeElementDTO.js'; | ||
|
||
/** | ||
* @typedef KnowledgeElementDTO | ||
* @type {object} | ||
* @property {string} status | ||
*/ | ||
|
||
/** | ||
* @typedef Payload | ||
* @type {object} | ||
* @property {number} userId | ||
* @property {Array<string>} skillIds | ||
*/ | ||
|
||
/** | ||
* @function | ||
* @name findFilteredMostRecentByUser | ||
* | ||
* @param {Payload} payload | ||
* @returns {Promise<Array<KnowledgeElementDTO>>} | ||
*/ | ||
export async function findFilteredMostRecentByUser({ userId, skillIds }) { | ||
const knowledgeElements = await evaluationUsecases.findFilteredMostRecentKnowledgeElementsByUser({ | ||
userId, | ||
skillIds, | ||
}); | ||
|
||
return knowledgeElements.map(_toApi); | ||
} | ||
|
||
const _toApi = (knowledgeElement) => new KnowledgeElementDTO(knowledgeElement); |
5 changes: 5 additions & 0 deletions
5
api/src/evaluation/application/api/models/KnowledgeElementDTO.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export class KnowledgeElementDTO { | ||
constructor({ status }) { | ||
this.status = status; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
api/src/evaluation/domain/usecases/find-filtered-most-recent-knowledge-elements-by-user.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const findFilteredMostRecentKnowledgeElementsByUser = async ({ | ||
userId, | ||
skillIds = [], | ||
knowledgeElementRepository, | ||
} = {}) => knowledgeElementRepository.findUniqByUserId({ userId, skillIds }); | ||
|
||
export { findFilteredMostRecentKnowledgeElementsByUser }; |
12 changes: 12 additions & 0 deletions
12
api/src/evaluation/infrastructure/repositories/answer-job-repository.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { AnswerJob } from '../../../quest/domain/models/AnwserJob.js'; | ||
import { JobRepository } from '../../../shared/infrastructure/repositories/jobs/job-repository.js'; | ||
|
||
class AnswerJobRepository extends JobRepository { | ||
constructor() { | ||
super({ | ||
name: AnswerJob.name, | ||
}); | ||
} | ||
} | ||
|
||
export const answerJobRepository = new AnswerJobRepository(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { usecases } from '../../domain/usecases/index.js'; | ||
|
||
export const save = async (userId, rewardId) => { | ||
return usecases.rewardUser({ userId, rewardId }); | ||
}; | ||
|
||
export const getByUserId = async (userId) => { | ||
return usecases.getProfileRewardsByUserId({ userId }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class ProfileReward { | ||
constructor({ id, rewardId, rewardType } = {}) { | ||
this.id = id; | ||
this.rewardId = rewardId; | ||
this.rewardType = rewardType; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
api/src/profile/domain/usecases/get-profile-rewards-by-user-id.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const getProfileRewardsByUserId = async function ({ userId, profileRewardRepository }) { | ||
return profileRewardRepository.getByUserId({ userId }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { dirname, join } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
import * as profileRewardRepository from '../../../profile/infrastructure/repositories/profile-reward-repository.js'; | ||
import { injectDependencies } from '../../../shared/infrastructure/utils/dependency-injection.js'; | ||
import { importNamedExportsFromDirectory } from '../../../shared/infrastructure/utils/import-named-exports-from-directory.js'; | ||
|
||
const path = dirname(fileURLToPath(import.meta.url)); | ||
|
||
const usecasesWithoutInjectedDependencies = { | ||
...(await importNamedExportsFromDirectory({ path: join(path, './'), ignoredFileNames: ['index.js'] })), | ||
}; | ||
|
||
const dependencies = { | ||
profileRewardRepository, | ||
}; | ||
|
||
const usecases = injectDependencies(usecasesWithoutInjectedDependencies, dependencies); | ||
|
||
export { usecases }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const rewardUser = async function ({ userId, rewardId, profileRewardRepository }) { | ||
return profileRewardRepository.save({ userId, rewardId }); | ||
}; |
33 changes: 33 additions & 0 deletions
33
api/src/profile/infrastructure/repositories/profile-reward-repository.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { PROFILE_REWARDS_TABLE_NAME } from '../../../../db/migrations/20240820101213_add-profile-rewards-table.js'; | ||
import { REWARD_TYPES } from '../../../quest/domain/constants.js'; | ||
import { DomainTransaction } from '../../../shared/domain/DomainTransaction.js'; | ||
import { ProfileReward } from '../../domain/models/ProfileReward.js'; | ||
|
||
/** | ||
* @param {number} userId | ||
* @param {number} rewardId | ||
* @param {('ATTESTATION')} rewardType | ||
* @returns {Promise<*>} | ||
*/ | ||
export const save = async ({ userId, rewardId, rewardType = REWARD_TYPES.ATTESTATION }) => { | ||
const knexConnection = await DomainTransaction.getConnection(); | ||
await knexConnection(PROFILE_REWARDS_TABLE_NAME).insert({ | ||
userId, | ||
rewardId, | ||
rewardType, | ||
}); | ||
}; | ||
|
||
/** | ||
* @param {number} userId | ||
* @returns {Promise<*>} | ||
*/ | ||
export const getByUserId = async ({ userId }) => { | ||
const knexConnection = await DomainTransaction.getConnection(); | ||
const profileRewards = await knexConnection(PROFILE_REWARDS_TABLE_NAME).where({ userId }); | ||
return profileRewards.map(toDomain); | ||
}; | ||
|
||
const toDomain = (profileReward) => { | ||
return new ProfileReward(profileReward); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { JobController, JobGroup } from '../../../shared/application/jobs/job-controller.js'; | ||
import { AnswerJob } from '../../domain/models/AnwserJob.js'; | ||
import { usecases } from '../../domain/usecases/index.js'; | ||
|
||
export class AnswerJobController extends JobController { | ||
constructor() { | ||
super(AnswerJob.name, { jobGroup: JobGroup.FAST }); | ||
} | ||
|
||
async handle({ data }) { | ||
const { userId } = data; | ||
|
||
return usecases.rewardUser({ userId }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ATTESTATIONS_TABLE_NAME } from '../../../db/migrations/20240820101115_add-attestations-table.js'; | ||
|
||
export const REWARD_TYPES = { ATTESTATION: ATTESTATIONS_TABLE_NAME }; |
Oops, something went wrong.