-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Rendre asynchrone l'import SUP sur PixOrga (Pix-13792)
- Loading branch information
Showing
18 changed files
with
404 additions
and
100 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...on/learner-management/application/jobs/import-sup-organization-learners-job-controller.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,47 @@ | ||
import { JobController } from '../../../../shared/application/jobs/job-controller.js'; | ||
import { config } from '../../../../shared/config.js'; | ||
import { DomainError } from '../../../../shared/domain/errors.js'; | ||
import { getI18n } from '../../../../shared/infrastructure/i18n/i18n.js'; | ||
import { logger as l } from '../../../../shared/infrastructure/utils/logger.js'; | ||
import { ImportSupOrganizationLearnersJob } from '../../domain/models/ImportSupOrganizationLearnersJob.js'; | ||
import { usecases } from '../../domain/usecases/index.js'; | ||
|
||
class ImportSupOrganizationLearnersJobController extends JobController { | ||
#logger; | ||
|
||
constructor({ logger = l } = {}) { | ||
super(ImportSupOrganizationLearnersJob.name); | ||
this.#logger = logger; | ||
} | ||
|
||
get isJobEnabled() { | ||
return config.pgBoss.importFileJobEnabled; | ||
} | ||
|
||
async handle({ data }) { | ||
const { organizationImportId, locale, type } = data; | ||
|
||
const i18n = getI18n(locale); | ||
|
||
try { | ||
if (type === 'ADDITIONAL_STUDENT') { | ||
return await await usecases.importSupOrganizationLearners({ | ||
organizationImportId, | ||
i18n, | ||
}); | ||
} else if (type === 'REPLACE_STUDENT') { | ||
return await usecases.replaceSupOrganizationLearners({ | ||
organizationImportId, | ||
i18n, | ||
}); | ||
} | ||
} catch (err) { | ||
if (!(err instanceof DomainError)) { | ||
throw err; | ||
} | ||
this.#logger.error(err); | ||
} | ||
} | ||
} | ||
|
||
export { ImportSupOrganizationLearnersJobController }; |
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
7 changes: 7 additions & 0 deletions
7
api/src/prescription/learner-management/domain/models/ImportSupOrganizationLearnersJob.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 @@ | ||
export class ImportSupOrganizationLearnersJob { | ||
constructor({ organizationImportId, type, locale }) { | ||
this.organizationImportId = organizationImportId; | ||
this.type = type; | ||
this.locale = locale; | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
...ement/infrastructure/repositories/jobs/import-sup-organization-learners-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,18 @@ | ||
import { | ||
JobExpireIn, | ||
JobRepository, | ||
JobRetry, | ||
} from '../../../../../shared/infrastructure/repositories/jobs/job-repository.js'; | ||
import { ImportSupOrganizationLearnersJob } from '../../../domain/models/ImportSupOrganizationLearnersJob.js'; | ||
|
||
class ImportSupOrganizationLearnersJobRepository extends JobRepository { | ||
constructor() { | ||
super({ | ||
name: ImportSupOrganizationLearnersJob.name, | ||
expireIn: JobExpireIn.HIGH, | ||
retry: JobRetry.FEW_RETRY, | ||
}); | ||
} | ||
} | ||
|
||
export const importSupOrganizationLearnersJobRepository = new ImportSupOrganizationLearnersJobRepository(); |
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
Oops, something went wrong.