Skip to content

Commit

Permalink
✨ certif: Call specific endpoint fro session
Browse files Browse the repository at this point in the history
  • Loading branch information
aceol committed May 17, 2024
1 parent 541aaa1 commit 1f7502d
Show file tree
Hide file tree
Showing 43 changed files with 552 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const serialize = function ({ session, hasSupervisorAccess, hasSomeCleaAcquired
'hasSupervisorAccess',
'hasSomeCleaAcquired',
];
return new Serializer('session', {
return new Serializer('session-management', {
transform(record) {
if (hasSupervisorAccess !== undefined) {
record.hasSupervisorAccess = hasSupervisorAccess;
Expand All @@ -29,15 +29,6 @@ const serialize = function ({ session, hasSupervisorAccess, hasSomeCleaAcquired
return record;
},
attributes,
certificationCandidates: {
ref: 'id',
ignoreRelationshipData: true,
relationshipLinks: {
related(record, current, parent) {
return `/api/sessions/${parent.id}/certification-candidates`;
},
},
},
certificationReports: {
ref: 'id',
ignoreRelationshipData: true,
Expand Down
36 changes: 36 additions & 0 deletions certif/app/adapters/session-enrolment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { service } from '@ember/service';

import ApplicationAdapter from './application';

export default class SessionEnrolmentAdapter extends ApplicationAdapter {
@service currentUser;

pathForType(_) {
return 'sessions';
}

urlForCreateRecord() {
const certificationCenterId = this.currentUser.currentAllowedCertificationCenterAccess.id;
return `${this.host}/${this.namespace}/certification-centers/${certificationCenterId}/session`;
}

updateRecord(store, type, snapshot) {
if (snapshot.adapterOptions) {
if (snapshot.adapterOptions.studentListToAdd.length) {
const url = this.urlForUpdateRecord(snapshot.id, type.modelName, snapshot) + '/enrol-students-to-session';
const organizationLearnerIds = snapshot.adapterOptions.studentListToAdd.map((student) => student.id);
const data = {
data: {
attributes: {
'organization-learner-ids': organizationLearnerIds,
},
},
};

return this.ajax(url, 'PUT', { data });
}
}

return super.updateRecord(...arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ import { service } from '@ember/service';

import ApplicationAdapter from './application';

export default class SessionAdapter extends ApplicationAdapter {
export default class SessionManagementAdapter extends ApplicationAdapter {
@service currentUser;

pathForType(_) {
return 'sessions';
}

urlForFindRecord(_) {
return `${super.urlForFindRecord(...arguments)}/management`;
}

urlForUpdateRecord(id, modelName, { adapterOptions }) {
const url = super.urlForUpdateRecord(...arguments);
if (adapterOptions && adapterOptions.finalization) {
Expand All @@ -15,11 +23,6 @@ export default class SessionAdapter extends ApplicationAdapter {
return url;
}

urlForCreateRecord() {
const certificationCenterId = this.currentUser.currentAllowedCertificationCenterAccess.id;
return `${this.host}/${this.namespace}/certification-centers/${certificationCenterId}/session`;
}

updateRecord(store, type, snapshot) {
if (snapshot.adapterOptions) {
if (snapshot.adapterOptions.finalization) {
Expand All @@ -45,20 +48,6 @@ export default class SessionAdapter extends ApplicationAdapter {
};
return this.ajax(this.urlForUpdateRecord(snapshot.id, type.modelName, snapshot), 'PUT', { data });
}

if (snapshot.adapterOptions.studentListToAdd.length) {
const url = this.urlForUpdateRecord(snapshot.id, type.modelName, snapshot) + '/enrol-students-to-session';
const organizationLearnerIds = snapshot.adapterOptions.studentListToAdd.map((student) => student.id);
const data = {
data: {
attributes: {
'organization-learner-ids': organizationLearnerIds,
},
},
};

return this.ajax(url, 'PUT', { data });
}
}

return super.updateRecord(...arguments);
Expand Down
2 changes: 1 addition & 1 deletion certif/app/components/session-summary-row.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { service } from '@ember/service';
import Component from '@glimmer/component';

import { CREATED, FINALIZED, PROCESSED } from '../models/session';
import { CREATED, FINALIZED, PROCESSED } from '../models/session-management.js';

export default class SessionSummaryRow extends Component {
@service intl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default class CandidateInList extends Component {
@action
async rejectLiveAlert() {
try {
const adapter = this.store.adapterFor('session');
const adapter = this.store.adapterFor('session-management');
await adapter.dismissLiveAlert(this.args.sessionId, this.args.candidate.userId);
this.isLiveAlertValidated = false;
this.displayedModal = Modals.HandledLiveAlertSuccess;
Expand All @@ -169,7 +169,7 @@ export default class CandidateInList extends Component {
@action
async validateLiveAlert(subcategory) {
try {
const adapter = this.store.adapterFor('session');
const adapter = this.store.adapterFor('session-management');
await adapter.validateLiveAlert({
sessionId: this.args.sessionId,
candidateId: this.args.candidate.userId,
Expand Down
3 changes: 2 additions & 1 deletion certif/app/controllers/authenticated/sessions/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ export default class SessionsDetailsController extends Controller {
async fetchInvigilatorKit() {
try {
const token = this.session.data.authenticated.access_token;
await this.fileSaver.save({ url: this.model.session.urlToDownloadSupervisorKitPdf, token });
await this.fileSaver.save({ url: this.model.sessionManagement.urlToDownloadSupervisorKitPdf, token });
} catch (err) {
console.log({ err });
this.notifications.error(this.intl.t('common.api-error-messages.internal-server-error'));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { tracked } from '@glimmer/tracking';

export default class SessionParametersController extends Controller {
@alias('model.session') session;
@alias('model.sessionManagement') sessionManagement;
@alias('model.certificationCandidates') certificationCandidates;
@tracked sessionNumberTooltipText = '';
@tracked accessCodeTooltipText = '';
Expand Down
40 changes: 40 additions & 0 deletions certif/app/models/session-enrolment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// eslint-disable-next-line ember/no-computed-properties-in-native-classes
import { computed } from '@ember/object';
import { service } from '@ember/service';
import Model, { attr } from '@ember-data/model';
import ENV from 'pix-certif/config/environment';

export const CREATED = 'created';

export default class Session extends Model {
@service session;
@service featureToggles;
@service intl;

@attr('string') address;
@attr('string') accessCode;
@attr('date-only') date;
@attr('string') time;
@attr('string') description;
@attr('string') examiner;
@attr('string') room;
@attr('string') status;
@attr('string') supervisorPassword;
@attr() certificationCenterId;
@attr('number') version;

@computed('id')
get urlToDownloadAttendanceSheet() {
return `${ENV.APP.API_HOST}/api/sessions/${this.id}/attendance-sheet`;
}

@computed('id')
get urlToDownloadCandidatesImportTemplate() {
return `${ENV.APP.API_HOST}/api/sessions/${this.id}/candidates-import-sheet`;
}

@computed('id')
get urlToUpload() {
return `${ENV.APP.API_HOST}/api/sessions/${this.id}/certification-candidates/import`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,12 @@ export default class Session extends Model {
@service featureToggles;
@service intl;

@attr('string') address;
@attr('string') accessCode;
@attr('date-only') date;
@attr('string') time;
@attr('string') description;
@attr('string') examiner;
@attr('string') room;
@attr('string') status;
@attr('string') examinerGlobalComment;
@attr('string') supervisorPassword;
@attr('boolean') hasSupervisorAccess;
@attr('boolean') hasSomeCleaAcquired;
@attr('boolean') hasIncident;
@attr('boolean') hasJoiningIssue;
@attr() certificationCenterId;
@attr('number') version;
@hasMany('certificationReport', { async: true, inverse: null }) certificationReports;

Expand All @@ -37,26 +28,11 @@ export default class Session extends Model {
return this.status === FINALIZED || this.status === IN_PROCESS || this.status === PROCESSED;
}

@computed('id')
get urlToDownloadAttendanceSheet() {
return `${ENV.APP.API_HOST}/api/sessions/${this.id}/attendance-sheet`;
}

@computed('id')
get urlToDownloadCandidatesImportTemplate() {
return `${ENV.APP.API_HOST}/api/sessions/${this.id}/candidates-import-sheet`;
}

@computed('id')
get urlToDownloadSupervisorKitPdf() {
return `${ENV.APP.API_HOST}/api/sessions/${this.id}/supervisor-kit`;
}

@computed('id')
get urlToUpload() {
return `${ENV.APP.API_HOST}/api/sessions/${this.id}/certification-candidates/import`;
}

get completedCertificationReports() {
return this.hasMany('certificationReports')
.value()
Expand Down
2 changes: 1 addition & 1 deletion certif/app/routes/authenticated/sessions/add-student.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class AuthenticatedSessionsDetailsAddStudentRoute extends Route {
}

async model(params) {
const session = await this.store.findRecord('session', params.session_id);
const session = await this.store.findRecord('session-enrolment', params.session_id);
const certificationCenterId = this.currentUser.currentAllowedCertificationCenterAccess.id;
const certificationCandidates = await this.store.query('certification-candidate', { sessionId: params.session_id });
const divisions = await this.store.query('division', { certificationCenterId });
Expand Down
6 changes: 4 additions & 2 deletions certif/app/routes/authenticated/sessions/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ export default class SessionsDetailsRoute extends Route {
}

async model(params) {
const session = await this.store.findRecord('session', params.session_id);
const sessionEnrolment = await this.store.findRecord('session-enrolment', params.session_id);
const sessionManagement = await this.store.findRecord('session-management', params.session_id);
const loadCertificationCandidates = () =>
this.store.query('certification-candidate', {
sessionId: params.session_id,
});
const certificationCandidates = await loadCertificationCandidates();

return EmberObject.create({
session,
session: sessionEnrolment,
sessionManagement,
certificationCandidates,
async reloadCertificationCandidate() {
const certificationCandidates = await loadCertificationCandidates();
Expand Down
5 changes: 3 additions & 2 deletions certif/app/routes/authenticated/sessions/finalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export default class SessionsFinalizeRoute extends Route {

async model({ session_id }) {
try {
const session = await this.store.findRecord('session', session_id, { reload: true });
const session = await this.store.findRecord('session-management', session_id, {
reload: true,
});
await session.certificationReports;

return session;
Expand All @@ -30,6 +32,5 @@ export default class SessionsFinalizeRoute extends Route {

transition.abort();
}
this.currentUser.updateCurrentCertificationCenter(model.certificationCenterId);
}
}
2 changes: 1 addition & 1 deletion certif/app/routes/authenticated/sessions/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class SessionsNewRoute extends Route {
}

model() {
return this.store.createRecord('session', {
return this.store.createRecord('session-enrolment', {
certificationCenterId: parseInt(this.currentUser.currentAllowedCertificationCenterAccess.id),
});
}
Expand Down
2 changes: 1 addition & 1 deletion certif/app/routes/authenticated/sessions/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class SessionsUpdateRoute extends Route {
}

async model({ session_id }) {
const session = await this.store.findRecord('session', session_id);
const session = await this.store.findRecord('session-enrolment', session_id);
this.dayjs.extend('customParseFormat');
session.time = this.dayjs.self(session.time, 'HH:mm:ss').format('HH:mm');
return session;
Expand Down
4 changes: 2 additions & 2 deletions certif/app/templates/authenticated/sessions/details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
</div>
</div>

{{#if this.model.session.shouldDisplayCleaResultDownloadSection}}
<SessionCleaResultsDownload @session={{this.model.session}} />
{{#if this.model.sessionManagement.shouldDisplayCleaResultDownloadSection}}
<SessionCleaResultsDownload @session={{this.model.sessionManagement}} />
{{/if}}

<div class="panel session-details__controls">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<PixButtonLink @route="authenticated.sessions.update" @model={{this.session.id}}>
{{t "common.actions.update"}}
</PixButtonLink>
{{#if this.session.isFinalized}}
{{#if this.sessionManagement.isFinalized}}
<p class="session-details-row__session-finalized-warning">
{{t "pages.sessions.detail.parameters.finalization-info"}}
</p>
Expand Down

0 comments on commit 1f7502d

Please sign in to comment.