diff --git a/microservices/auth/src/app.ts b/microservices/auth/src/app.ts index 0cfc19e9064b697069d545d48fda044c419861ab..9d5972d9dba0c0b82a5d5ed29ed564a74589e5a3 100644 --- a/microservices/auth/src/app.ts +++ b/microservices/auth/src/app.ts @@ -1,4 +1,4 @@ -import Server from './express/Server'; +import Server from './express/Server.js'; new Server().run(); \ No newline at end of file diff --git a/microservices/auth/src/express/Server.ts b/microservices/auth/src/express/Server.ts index d59d2a2bf154ca81f3daaa9754f99be6b9ed3ebe..252d947a7c05875433ccbf3e22c06e154f3a8365 100644 --- a/microservices/auth/src/express/Server.ts +++ b/microservices/auth/src/express/Server.ts @@ -1,14 +1,14 @@ import { Express } from 'express-serve-static-core'; import cors from 'cors'; -import morganMiddleware from '../logging/MorganMiddleware'; -import logger from '../logging/WinstonLogger'; +import morganMiddleware from '../logging/MorganMiddleware.js'; +import logger from '../logging/WinstonLogger.js'; import { AddressInfo } from 'net'; import http from 'http'; import helmet from 'helmet'; import express from 'express'; import multer from 'multer'; -import Config from '../config/Config'; -import questions_routes from '../routes/Auth'; +import Config from '../config/Config.js'; +import questions_routes from '../routes/Auth.js'; import db from '../helpers/DatabaseHelper.js'; import bodyParser from 'body-parser'; diff --git a/microservices/auth/src/logging/MorganMiddleware.ts b/microservices/auth/src/logging/MorganMiddleware.ts index 9030416de6eee704e4b54dd50e8f8286674e896f..eb3626734112b6bfbeb362c5b4b0c129b6f98d7f 100644 --- a/microservices/auth/src/logging/MorganMiddleware.ts +++ b/microservices/auth/src/logging/MorganMiddleware.ts @@ -1,6 +1,6 @@ import morgan, { StreamOptions } from 'morgan'; -import logger from './WinstonLogger'; +import logger from './WinstonLogger.js'; const stream: StreamOptions = { diff --git a/microservices/auth/src/logging/WinstonLogger.ts b/microservices/auth/src/logging/WinstonLogger.ts index 6f6a2b1a8880e01d5de0fa8828efb144ecbb57fb..f35be89892f472146484e8a89d66cf5ccada14a2 100644 --- a/microservices/auth/src/logging/WinstonLogger.ts +++ b/microservices/auth/src/logging/WinstonLogger.ts @@ -1,6 +1,6 @@ import winston from 'winston'; import * as Transport from 'winston-transport'; -import Config from '../config/Config'; +import Config from '../config/Config.js'; const levels = { diff --git a/microservices/frontend/src/app/affichage-creation-qcm/creation/creation.component.ts b/microservices/frontend/src/app/affichage-creation-qcm/creation/creation.component.ts index 6607a272364ae7b363421f9a38639f7d7da05138..abbbcf8af653d491426713b238ebdb371c9b5fa4 100644 --- a/microservices/frontend/src/app/affichage-creation-qcm/creation/creation.component.ts +++ b/microservices/frontend/src/app/affichage-creation-qcm/creation/creation.component.ts @@ -35,7 +35,7 @@ export class CreationComponent { console.error('ID param is null'); } Fetch.getInfosQcm(this.idQcm ? this.idQcm : 0) - .then(data => {this.qcm = data; this.qcm.tempsMax /= 60}) + .then(data => {this.qcm = data}) .catch(error => console.error('Erreur lors de la requête pour Contact:', error)) } this.auth = inject(AuthConfigService) @@ -81,10 +81,8 @@ export class CreationComponent { }); } update(): void{ - //Envoie à la base de donnée + // Envoie à la base de donnée console.log(this.qcm) - this.qcm.tempsMax *= 60; Fetch.putQcm(this.qcm).then(() => this.router.navigate(['/qcmCree'])); } - } diff --git a/microservices/frontend/src/app/auth-config.service.ts b/microservices/frontend/src/app/auth-config.service.ts index 36e4a116a818f684fd4c1d8c978ff8de3a9e9827..70cee8ef04be6822bab79799605d0e834656b0d2 100644 --- a/microservices/frontend/src/app/auth-config.service.ts +++ b/microservices/frontend/src/app/auth-config.service.ts @@ -30,6 +30,7 @@ export class AuthConfigService { }) .then(response => response.json()) .then(data => {localStorage.setItem('access_token', data["token"]); localStorage.setItem('idUser', data["idUser"]); resolve(data)}) + .then(() => window.location.reload()) .catch(error => reject(error)); }); } diff --git a/microservices/frontend/src/app/classes/Fetch.ts b/microservices/frontend/src/app/classes/Fetch.ts index c10380ad025441df825cb3217b2ae312adde0908..d0b1a1e12a206fd1835e16693b219009f41434b3 100644 --- a/microservices/frontend/src/app/classes/Fetch.ts +++ b/microservices/frontend/src/app/classes/Fetch.ts @@ -436,12 +436,12 @@ export class Fetch{ method: 'POST', headers: this.headersObject, body: JSON.stringify({ - qcm: qcmData, + qcm: qcmData.toJSON(), idUser: idUser, }) }) .then(response => { - console.log("response de la creation qcm:") + console.log("response de la creation qcm:") console.log(response) if (!response.ok) { reject(`HTTP error! status: ${response.status}`); @@ -511,13 +511,11 @@ export class Fetch{ } static putQcm(qcmData: QcmData): Promise<Response> { return new Promise<Response>((resolve, reject) => { - - fetch(Fetch.address+'/QCM', { method: 'PUT', headers: this.headersObject, body: JSON.stringify({ - qcm: qcmData, + qcm: qcmData.toJSON(), }) }) .then(response => { diff --git a/microservices/frontend/src/app/classes/qcm/QcmData.ts b/microservices/frontend/src/app/classes/qcm/QcmData.ts index 58a947b0e2e08a29b84d36fe142fa780eca91f05..cc2d381847a734d7e68fa365a1dcbb81e1905066 100644 --- a/microservices/frontend/src/app/classes/qcm/QcmData.ts +++ b/microservices/frontend/src/app/classes/qcm/QcmData.ts @@ -1,24 +1,49 @@ import { Question } from "./Question" +import "tslib" export class QcmData{ idQcm: number nomQcm: string - tempsMax: number + #tempsMax: number tempsStart: number randomQuestion: boolean questions : Question[] constructor(nomQcm: string, tempsMax: number, randomQuestion: boolean, questions : Question[], tempsStart: number, idQcm?: number) { - this.idQcm = idQcm ?? 0; - this.nomQcm = nomQcm - this.questions = questions - this.randomQuestion = randomQuestion - this.tempsMax = tempsMax - this.tempsStart = tempsStart + this.idQcm = idQcm ?? 0; + this.nomQcm = nomQcm + this.questions = questions + this.randomQuestion = randomQuestion + this.#tempsMax = tempsMax + this.tempsStart = tempsStart } + + get tempsMaxRaw(): number { + return this.#tempsMax + } + + get tempsMax(): number { + return this.#tempsMax / 60 + } + + set tempsMax(value: number) { + this.#tempsMax = value * 60 + } + public delQuestion(q: Question): void{ if (this.questions) { - this.questions = this.questions.filter(choice => choice !== q); + this.questions = this.questions.filter(choice => choice !== q); } - } + } + + toJSON() { + return { + idQcm: this.idQcm, + nomQcm: this.nomQcm, + tempsMax: this.tempsMaxRaw, + tempsStart: this.tempsStart, + randomQuestion: this.randomQuestion, + questions : this.questions, + }; + } } \ No newline at end of file