Sfoglia il codice sorgente

(fix) version 1.0.2

formation 4 anni fa
parent
commit
04b78a799e
34 ha cambiato i file con 2183 aggiunte e 4128 eliminazioni
  1. 1 1
      .vscode/launch.json
  2. 8 0
      angular-client/3.7.1
  3. 7 3
      angular-client/angular.json
  4. 1954 4043
      angular-client/package-lock.json
  5. 29 32
      angular-client/package.json
  6. 3 2
      angular-client/src/app/app-routing.module.ts
  7. 0 3
      angular-client/src/app/app.component.ts
  8. 2 0
      angular-client/src/app/app.module.ts
  9. 5 5
      angular-client/src/app/components/admin/statistic/statistic.component.html
  10. 8 1
      angular-client/src/app/components/admin/statistic/statistic.component.ts
  11. 1 1
      angular-client/src/app/components/auth/gain/gain-form/gain-form.component.ts
  12. 7 4
      angular-client/src/app/components/auth/gain/gain-list/gain-list.component.html
  13. 2 2
      angular-client/src/app/components/auth/gain/gain.component.html
  14. 11 5
      angular-client/src/app/components/auth/gain/gain.component.ts
  15. 1 1
      angular-client/src/app/components/login/login.component.ts
  16. 1 1
      angular-client/src/app/components/register/register.component.ts
  17. 1 1
      angular-client/src/app/components/shared/not-found/not-found.component.scss
  18. 1 0
      angular-client/src/app/models/userResponse.ts
  19. 8 1
      angular-client/src/app/services/auth.service.ts
  20. 1 0
      angular-client/src/app/services/statistic.service.ts
  21. 1 1
      angular-client/src/environments/environment.ts
  22. 1 1
      angular-client/src/polyfills.ts
  23. 1 1
      angular-client/src/test.ts
  24. 88 0
      express-server/admin/admin.js
  25. 1 0
      express-server/controllers/auth.js
  26. 1 1
      express-server/controllers/employee.js
  27. 21 6
      express-server/controllers/gain.js
  28. 2 1
      express-server/controllers/statistique.js
  29. 3 1
      express-server/index.js
  30. 1 1
      express-server/middleware/authorize.js
  31. 5 5
      express-server/models/user.model.js
  32. 1 1
      express-server/package.json
  33. 3 3
      express-server/routes/user.js
  34. 3 0
      package-lock.json

+ 1 - 1
.vscode/launch.json

@@ -5,7 +5,7 @@
           "name": "Run & debug my app on chrome",
           "type": "chrome",
           "request": "launch",
-          "url": "https://angular-preprod.foodgame.fr/",
+          "url": "http://localhost:4200",
           "webRoot": "${workspaceFolder}",
           "preLaunchTask": "start"
       }

+ 8 - 0
angular-client/3.7.1

@@ -0,0 +1,8 @@
++ jasmine-core@3.5.0
+updated 1 package and audited 1528 packages in 9.462s
+
+91 packages are looking for funding
+  run `npm fund` for details
+
+found 4 vulnerabilities (3 moderate, 1 high)
+  run `npm audit fix` to fix them, or `npm audit` for details

+ 7 - 3
angular-client/angular.json

@@ -22,7 +22,6 @@
             "main": "src/main.ts",
             "polyfills": "src/polyfills.ts",
             "tsConfig": "tsconfig.app.json",
-            "aot": true,
             "assets": [
               "src/favicon.ico",
               "src/assets"
@@ -32,7 +31,13 @@
               "src/styles.scss",
               "./node_modules/leaflet/dist/leaflet.css"
             ],
-            "scripts": []
+            "scripts": [],
+            "vendorChunk": true,
+            "extractLicenses": false,
+            "buildOptimizer": false,
+            "sourceMap": true,
+            "optimization": false,
+            "namedChunks": true
           },
           "configurations": {
             "production": {
@@ -45,7 +50,6 @@
               "optimization": true,
               "outputHashing": "all",
               "sourceMap": false,
-              "extractCss": true,
               "namedChunks": false,
               "extractLicenses": true,
               "vendorChunk": false,

File diff suppressed because it is too large
+ 1954 - 4043
angular-client/package-lock.json


+ 29 - 32
angular-client/package.json

@@ -12,61 +12,58 @@
   },
   "private": true,
   "dependencies": {
-    "@angular/animations": "^11.2.6",
-    "@angular/cdk": "^7.3.7",
-    "@angular/common": "^11.2.6",
-    "@angular/compiler": "^11.2.6",
-    "@angular/core": "10.1.3",
-    "@angular/flex-layout": "^9.0.0-beta.31",
-    "@angular/forms": "^11.2.6",
-    "@angular/material": "^7.3.7",
-    "@angular/platform-browser": "^11.2.6",
-    "@angular/platform-browser-dynamic": "^11.2.6",
-    "@angular/router": "^11.2.6",
+    "@angular/animations": "~9.1.4",
+    "@angular/cdk": "^9.2.2",
+    "@angular/common": "~9.1.4",
+    "@angular/compiler": "~9.1.4",
+    "@angular/core": "~9.1.4",
+    "@angular/flex-layout": "^9.0.0-beta.29",
+    "@angular/forms": "~9.1.4",
+    "@angular/material": "^9.2.2",
+    "@angular/platform-browser": "~9.1.4",
+    "@angular/platform-browser-dynamic": "~9.1.4",
+    "@angular/router": "~9.1.4",
     "@types/jwt-decode": "^2.2.1",
-    "@types/leaflet": "^1.7.0",
-    "bootstrap": "^4.6.0",
-    "chart.js": "^2.9.4",
+    "@types/leaflet": "^1.5.12",
+    "bootstrap": "^4.4.1",
+    "chart.js": "^2.9.3",
     "jwt-decode": "^2.2.0",
     "karma-coverage": "^2.0.3",
     "karma-firefox-launcher": "^1.3.0",
     "karma-jenkins-reporter": "0.0.2",
     "karma-phantomjs-launcher": "^1.0.4",
-    "leaflet": "^1.7.1",
-    "ng2-charts": "^2.4.2",
+    "leaflet": "^1.6.0",
+    "ng2-charts": "^2.3.0",
     "rxjs": "~6.5.4",
     "saturn-datepicker": "^8.0.5",
-    "tslib": "^1.14.1",
+    "tslib": "^1.10.0",
     "zone.js": "~0.10.2"
   },
   "devDependencies": {
     "@angular-devkit/build-angular": "^0.901.15",
-    "@angular/cli": "^10.1.7",
-    "@angular/compiler-cli": "^11.2.6",
-    "@angular/language-service": "^11.2.6",
-    "@types/jasmine": "^3.6.7",
+    "@angular/cli": "~9.1.4",
+    "@angular/compiler-cli": "~9.1.4",
+    "@angular/language-service": "~9.1.4",
+    "@types/jasmine": "~3.5.0",
     "@types/jasminewd2": "~2.0.3",
-    "@types/node": "^12.20.6",
-    "chai": "^4.3.4",
+    "@types/node": "^12.11.1",
+    "chai": "^4.2.0",
     "codelyzer": "^5.1.2",
     "jasmine-core": "~3.5.0",
     "jasmine-spec-reporter": "~4.2.1",
-    "karma": "^5.2.3",
+    "karma": "^6.3.4",
     "karma-chai": "^0.1.0",
     "karma-chrome-launcher": "^3.1.0",
     "karma-coverage-istanbul-reporter": "~2.1.0",
     "karma-jasmine": "~3.0.1",
-    "karma-jasmine-html-reporter": "^1.5.4",
+    "karma-jasmine-html-reporter": "^1.4.2",
     "karma-junit-reporter": "^2.0.1",
     "karma-mocha": "^2.0.1",
-    "mocha": "^8.3.2",
+    "mocha": "^8.1.1",
     "protractor": "^7.0.0",
-    "puppeteer": "^5.5.0",
+    "puppeteer": "^5.2.1",
     "ts-node": "~8.3.0",
-    "tslint": "^5.15.0",
-    "typescript": "^4.1.5"
-  },
-  "optionalDependencies": {
-    "fsevents": "^2.3.2"
+    "tslint": "~6.1.0",
+    "typescript": "~3.8.3"
   }
 }

+ 3 - 2
angular-client/src/app/app-routing.module.ts

@@ -14,7 +14,7 @@ import { NgModule } from '@angular/core';
 import { Routes, RouterModule } from '@angular/router';
 import { LoginComponent } from 'src/app/components/login/login.component';
 import { RegisterComponent } from 'src/app/components/register/register.component';
-import { NavbarComponent } from 'src/app/components/shared/navbar/navbar.component';
+//import { NavbarComponent } from 'src/app/components/shared/navbar/navbar.component';
 import { ContactComponent } from 'src/app/components/shared/contact/contact.component';
 import { HomeComponent } from './components/home/home.component';
 import { AuthGuard } from './guards/auth.guard';
@@ -44,7 +44,8 @@ const routes: Routes = [
 ];
 
 @NgModule({
-  imports: [RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' })],
+  imports: [RouterModule.forRoot(routes)],
   exports: [RouterModule]
 })
 export class AppRoutingModule { }
+

+ 0 - 3
angular-client/src/app/app.component.ts

@@ -7,7 +7,4 @@ import { Component } from '@angular/core';
 })
 export class AppComponent {
   title = 'fatboar';
-
-  // Link to our api, pointing to api-preprod.foodgame.fr
-  //API = 'https://api-preprod.foodgame.fr';
 }

+ 2 - 0
angular-client/src/app/app.module.ts

@@ -60,6 +60,7 @@ import { ResponseContactComponent } from './components/admin/assistance/response
 
 
 
+
 @NgModule({
   declarations: [
     AppComponent,
@@ -102,6 +103,7 @@ import { ResponseContactComponent } from './components/admin/assistance/response
     ResetPasswordComponent,
     ConfirmMessageComponent,
     
+    
   ],
   imports: [
     BrowserModule,

+ 5 - 5
angular-client/src/app/components/admin/statistic/statistic.component.html

@@ -27,14 +27,14 @@
       <!-- gain Column -->
       <ng-container matColumnDef="gain">
         <th mat-header-cell *matHeaderCellDef>Gain</th>
-        <td mat-cell *matCellDef="let element" class="text-left"> {{element.gain }} </td>
+        <td mat-cell *matCellDef="let element" class="text-left"> {{element.gain}} </td>
         <td mat-footer-cell *matFooterCellDef class="text-left">Totale</td>
       </ng-container>
 
       <!-- used Column -->
       <ng-container matColumnDef="used">
         <th mat-header-cell *matHeaderCellDef class="text-center">Utilisé</th>
-        <td mat-cell *matCellDef="let element"> {{element.used  }} </td>
+        <td mat-cell *matCellDef="let element"> {{element.used}} </td>
         <td mat-footer-cell *matFooterCellDef> {{getUsed()}} </td>
       </ng-container>
 
@@ -42,14 +42,14 @@
       <ng-container matColumnDef="served">
         <th mat-header-cell *matHeaderCellDef class="text-center">Server</th>
         <td mat-cell *matCellDef="let element"> {{element.served}} </td>
-        <td mat-footer-cell *matFooterCellDef> {{getServed()  }} </td>
+        <td mat-footer-cell *matFooterCellDef> {{getServed()}} </td>
       </ng-container>
 
       <!-- total Column -->
       <ng-container matColumnDef="total">
         <th mat-header-cell *matHeaderCellDef class="text-center">Totalité</th>
-        <td mat-cell *matCellDef="let element"> {{element.total  }} </td>
-        <td mat-footer-cell *matFooterCellDef> {{getTotal()  }} </td>
+        <td mat-cell *matCellDef="let element"> {{element.total}} </td>
+        <td mat-footer-cell *matFooterCellDef> {{getTotal()}} </td>
       </ng-container>
 
       <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>

+ 8 - 1
angular-client/src/app/components/admin/statistic/statistic.component.ts

@@ -32,14 +32,20 @@ export class StatisticComponent implements OnInit {
   subscribeToStatistic() {
 
     this.StatisticService.getStatistic().subscribe((res) => {
+      
       this.statisticArray = res.data;
+      
+    
 
       this.barChartData = [
         { data: this.statisticArray.map(res => res.total), label: 'totalité' },
         { data: this.statisticArray.map(res => res.used), label: 'utiliser' },
         { data: this.statisticArray.map(res => res.served), label: 'server' }
       ];
-    })
+      
+})
+    
+    
 
   }
 
@@ -70,6 +76,7 @@ export class StatisticComponent implements OnInit {
 
   getTotal() {
     return this.statisticArray.map(t => t.total).reduce((acc, value) => acc + value, 0);
+    
   }
   getUsed() {
     return this.statisticArray.map(t => t.used).reduce((acc, value) => acc + value, 0);

+ 1 - 1
angular-client/src/app/components/auth/gain/gain-form/gain-form.component.ts

@@ -36,7 +36,6 @@ export class GainFormComponent implements OnInit {
 
 
   sendCodeGain() {
-    console.log('toto')
     
     if (this.formGroup.invalid) {
       return;
@@ -47,3 +46,4 @@ export class GainFormComponent implements OnInit {
 
 
 }
+

+ 7 - 4
angular-client/src/app/components/auth/gain/gain-list/gain-list.component.html

@@ -1,6 +1,6 @@
  <!-- table of users -->
-
-    <table mat-table [dataSource]="lots" class="tablegain">
+{{lots.code}}
+    <table *ngIf="lots" mat-table  [dataSource]="lots" class="tablegain">
 
 
       <!-- index -->
@@ -39,13 +39,16 @@
 
       
 
-      <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
-      <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
+        <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
+        <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
+
+
     </table>
 
 
 
 
+
     <!-- <mat-paginator [length]="length" [pageSize]="pageSize" [pageSizeOptions]="[2,3,10]" [showFirstLastButtons]="true"
       (page)="handlePage($event)">
     </mat-paginator> -->

+ 2 - 2
angular-client/src/app/components/auth/gain/gain.component.html

@@ -2,7 +2,7 @@
     <div>
         <app-gain-form (code)="receiveCode($event)"></app-gain-form>
     </div>
-    <div class="my-3">
-        <app-gain-list [lots]="lots"></app-gain-list>
+    <div class="my-3" *ngIf="lots">
+        <app-gain-list  [lots]="lots"></app-gain-list>
     </div>
 </div>

+ 11 - 5
angular-client/src/app/components/auth/gain/gain.component.ts

@@ -2,7 +2,7 @@ import { UsersService } from './../../../services/users.service';
 import { Ticket } from './../../../models/ticket';
 import { User } from './../../../models/userResponse';
 import { AuthService } from './../../../services/auth.service';
-import { Component, OnInit } from '@angular/core';
+import { Component, Input, OnInit } from '@angular/core';
 
 @Component({
   selector: 'app-gain',
@@ -14,7 +14,8 @@ export class GainComponent implements OnInit {
   constructor(private authService : AuthService, private userService : UsersService)
    { }
 
-  lots : Ticket[]=[];
+  //  @Input() lots;
+   @Input() lots:Ticket[];
   user : User;
 
   ngOnInit(): void {
@@ -28,9 +29,14 @@ export class GainComponent implements OnInit {
 
   receiveCode($event : Ticket){
     let id = this.authService.userValue._id
-    console.log('coe',$event)
-    console.log('id',id)
-    this.userService.verifyLotUser(id, $event).subscribe( res => console.log(res))
+    this.userService.verifyLotUser(id, $event).subscribe( (res) => {
+      if(res) {
+      this.lots = [];
+      this.lots.push(res);
+      }
+    }
+      ); 
+       console.log(' Retour de la requete',this.lots)
   }
 
 

+ 1 - 1
angular-client/src/app/components/login/login.component.ts

@@ -85,7 +85,7 @@ export class LoginComponent implements OnInit {
     // this.router.navigate(['/']);
 
    
-   
+    
   }
 
 }

+ 1 - 1
angular-client/src/app/components/register/register.component.ts

@@ -139,7 +139,7 @@ export class RegisterComponent implements OnInit {
     if (this.formGroup.invalid) {
       return;
     }
-    this.loading = true;
+   this.loading = true;
    this.authService.signUP(this.formGroup.value).subscribe(
     data => {
         // this.router.navigate([this.returnUrl]);

+ 1 - 1
angular-client/src/app/components/shared/not-found/not-found.component.scss

@@ -45,7 +45,7 @@
     display: inline-block;
     width: 120px;
     height: 120px;
-    background-image: url('src/assets/img/emoji/emoji.png');
+    // background-image: url('src/assets/img/emoji/emoji.png');
     background-size: cover;
     -webkit-transform: scale(1.4);
         -ms-transform: scale(1.4);

+ 1 - 0
angular-client/src/app/models/userResponse.ts

@@ -1,4 +1,5 @@
 import { Ticket } from './ticket';
+
 export interface UserResponse {
     success: boolean;
     page: number;

+ 8 - 1
angular-client/src/app/services/auth.service.ts

@@ -26,6 +26,9 @@ export class AuthService {
   private user_infoSubject: BehaviorSubject<User>;
   public user_info: Observable<User>;
 
+  private messageSource = new BehaviorSubject('default message');
+  currentMessage = this.messageSource.asObservable();
+
   constructor(private http: HttpClient, public router: Router, public snackBar: MatSnackBar) {
 
     this.tokenSubject = new BehaviorSubject<Token>(JSON.parse(localStorage.getItem('token')));
@@ -36,6 +39,10 @@ export class AuthService {
 
   }
 
+  changeMessage(message: string) {
+    this.messageSource.next(message)
+  }
+
   //get token
   public get tokenValue(): Token {
     return this.tokenSubject.value;
@@ -48,7 +55,7 @@ export class AuthService {
 
   // login get  token on login 
   signIn(credentials): Observable<Token> {
-    debugger;
+    // debugger;
     console.log("url ========",this.apiUrl);
 
     return this.http.post<Token>(`${this.apiUrl}/api/auth/login`, credentials)

+ 1 - 0
angular-client/src/app/services/statistic.service.ts

@@ -32,3 +32,4 @@ const options = { headers: this.headers};
 
 
 }
+

+ 1 - 1
angular-client/src/environments/environment.ts

@@ -15,4 +15,4 @@ export const environment = {
  * This import should be commented out in production mode because it will have a negative impact
  * on performance if an error is thrown.
  */
-// import 'zone.js/dist/zone-error';  // Included with Angular CLI.
+// import 'zone.js/plugins/zone-error';  // Included with Angular CLI.

+ 1 - 1
angular-client/src/polyfills.ts

@@ -55,7 +55,7 @@
 /***************************************************************************************************
  * Zone JS is required by default for Angular itself.
  */
-import 'zone.js/dist/zone';  // Included with Angular CLI.
+import 'zone.js';  // Included with Angular CLI.
 
 
 /***************************************************************************************************

+ 1 - 1
angular-client/src/test.ts

@@ -1,6 +1,6 @@
 // This file is required by karma.conf.js and loads recursively all the .spec and framework files
 
-import 'zone.js/dist/zone-testing';
+import 'zone.js/testing';
 import { getTestBed } from '@angular/core/testing';
 import {
   BrowserDynamicTestingModule,

+ 88 - 0
express-server/admin/admin.js

@@ -0,0 +1,88 @@
+
+const role = require('../lib/role');
+const bcrypt = require('bcrypt');
+const { User } = require('../models/user.model');
+const jwt = require('jsonwebtoken');
+const config = require('../config/config.json');
+var validator = require('validator');
+
+
+
+//inscription admin
+
+console.log('process.argv =>', process.argv)
+
+const email = process.argv[2];
+const password = process.argv[3];
+console.log('email =>', email);
+console.log('password =>', password);
+
+const user = new User();
+user.role = role.Admin;
+user.email = email;
+//user.password = await bcrypt.hash(password, 12) 
+user.password = password;
+console.log('User =>', user)
+
+user.save().then(() => {
+    const token = jwt.sign({ _id: user._id, email: user.email, role: user.role }, config.secret_key, { expiresIn: '10 h' });
+    res.status(201).json(
+        { success: true, token, expireIn: `${new Date().getTime() + 120000}` });
+
+})
+.catch((err) => console.log('Mon message => ', err))
+
+
+// exports.signup = async (req, res, next) => {
+
+//     try {
+
+//         // génère une exception
+//         if (!req.body.firstname) { throw new Error('Nom introuvable') }
+//         if (!req.body.lastname) { throw new Error('Prénom introuvable') }
+//         if (!req.body.email) { throw new Error('Adresse email introuvable') }
+//         if (!req.body.birthday) { throw new Error('Date de naissance introuvable') }
+//         if (!req.body.phonenumber) { throw new Error('Numéro de téléphone introuvable') }
+//         if (!req.body.adress) { throw new Error('Adresse introuvable') }
+//         if (!validator.isEmail(req.body.email)) { throw new Error('Adresse email invalide') }
+//         if (isNaN(Date.parse(req.body.birthday)) || (Date.parse(req.body.birthday)) > 1073692800000) { throw new Error('Date de naissance invalide') }
+
+
+//         const user = await User.findOne({ email: req.body.email }, { email: 1 })
+
+//         if (user) {
+//             res.status(401).json({ success: false, message: 'Adresse email existe déja veuillez renseigner une autre adresse email' })
+//         } else {
+
+//             bcrypt.hash(req.body.password, 12)
+//                 .then(hash => {
+//                     const user = new User({
+//                         firstname: req.body.firstname,
+//                         lastname: req.body.lastname,
+//                         email: req.body.email,
+//                         role: role.Client,
+//                         birthday: req.body.birthday,
+//                         phonenumber: req.body.phonenumber,
+//                         adress: req.body.adress,
+//                         isActive: true,
+//                         isGain: false,
+//                         password: hash
+//                     });
+
+//                     user.save()
+//                         .then(() => {
+//                             const token = jwt.sign({ userId: user._id, email: user.email, role: user.role }, config.secret_key, { expiresIn: '10 h' })
+//                             res.status(201).json(
+//                                 { success: true, token, expireIn: `${new Date().getTime() + 120000}` })
+//                         })
+//                         .catch((err) => res.status(500).json({ success: false, message: err.message }))
+//                 })
+//                 .catch(() => res.status(400).json({ success: false, message: 'Erreur dans le mot de passe' }));
+//         }
+
+//     }
+//     catch (err) {
+//         res.status(400).json({ success: false, message: err.message })
+//     }
+
+// };

+ 1 - 0
express-server/controllers/auth.js

@@ -47,6 +47,7 @@ exports.signup = async (req, res, next) => {
 
                     user.save()
                         .then(() => {
+                            console.log('utilisateur =>', user)
                             const token = jwt.sign({ userId: user._id, email: user.email, role: user.role }, config.secret_key, { expiresIn: '10 h' })
                             res.status(201).json(
                                 { success: true, token, expireIn: `${new Date().getTime() + 120000}` })

+ 1 - 1
express-server/controllers/employee.js

@@ -1,7 +1,7 @@
 const { Ticket } = require('../models/ticket.model');
 const { User } = require('../models/user.model');
 const bcrypt = require('bcrypt');
-const Role = require('../lib/role')
+const Role = require('../lib/role');
 var validator = require('validator');
 
 

+ 21 - 6
express-server/controllers/gain.js

@@ -6,8 +6,8 @@ const { User } = require('../models/user.model');
 //consulter les gains
 exports.gain = async (req, res, next) => {
 
-    try {
-        
+    try {   
+        //Ticket.save(); console.log('Test début', Ticket.code);
         // génère une exception
         if (!req.query.id) { throw new Error(`Identifiant utilisateur introuvable`) }
         if (!req.body.code) { throw new Error(`Code introuvable`) }
@@ -16,10 +16,25 @@ exports.gain = async (req, res, next) => {
 
         
         User.findById(req.query.id)
-            .then((user) => {
+            .then((user) => { 
+                 Ticket.findOne({ code: req.body.code })
+                    .then((ticket) => { 
+                    console.log('Tickets list :', ticket) 
+                    res.status(200).send(ticket);
+                    return;
+                    //  for (i = 0; i < 50; i++) {
+                    //      const ticke = new Ticket({
+                    //          code: req.body.code + i,
+                    //          isUsed: true,
+                    //          gains: "30% de réduction dessert et un menu du jour",
+                    //          date_used: new Date(),
+                    //          index: 'index',
+                    //          isServed: true
+                    //     });
+                        
+                    //      ticke.save();
+                    //  }
 
-                Ticket.findOne({ code: req.body.code })
-                    .then((ticket) => {
                         if (ticket) {
                             if (ticket.isUsed === false) {
 
@@ -47,4 +62,4 @@ exports.gain = async (req, res, next) => {
 
     }
     catch (err) { res.status(400).json({ success: false, message: err.message }) }
-};
+};

+ 2 - 1
express-server/controllers/statistique.js

@@ -42,8 +42,9 @@ exports.getStatistique = async (req, res, next) => {
       { gain: 'un menu au choix', used: m_c_used, served: m_c_served, total: m_c_total },
       { gain: '70% de réduction', used: r_used, served: r_served, total: r_total }
       ]
+      
     })
-
+    
   }
   catch (err) {
     res.status(500).json({ success: false, message: err.message })

+ 3 - 1
express-server/index.js

@@ -45,11 +45,13 @@ app.get("/api", (req, res) => {
 
 //Définition des CORS Middleware 
 app.use(function(req, res, next) {
+  
+    //res.header("Access-Control-Allow-Origin", "*");
+    res.setHeader("Access-Control-Allow-Origin", "*");
     res.setHeader(
       "Access-Control-Allow-Headers",
       "X-Requested-With,content-type, Accept,Authorization,Origin"
     );
-    res.setHeader("Access-Control-Allow-Origin", "*");
     res.setHeader(
       "Access-Control-Allow-Methods",
       "GET, POST, OPTIONS, PUT, PATCH, DELETE"

+ 1 - 1
express-server/middleware/authorize.js

@@ -23,7 +23,7 @@ function authorize(roles = []) {
                     const decodedToken = jwt.verify(token, config.secret_key);
                     const token_role = decodedToken.role;
                     if (roles.length && !roles.includes(token_role)) {
-                        throw new Error('Unauthorized');
+                        throw new Error('rrrrrrrrrrrr');
                     } else {
                         next()
                     }

+ 5 - 5
express-server/models/user.model.js

@@ -6,7 +6,7 @@ const UserSchema = new mongoose.Schema(
     {
         firstname: {
             type: String,
-            required: true,
+            required: false,
             trim: true,
             lowercase: true,
             minlength: 2,
@@ -15,7 +15,7 @@ const UserSchema = new mongoose.Schema(
         },
         lastname: {
             type: String,
-            required: true,
+            required: false,
             trim: true,
             minlength: 2,
             maxlength: 50,
@@ -38,16 +38,16 @@ const UserSchema = new mongoose.Schema(
         },
         birthday: {
             type: Date,
-            required: true
+            required: false
         },
         register_date: {
             type: Date,
             default: Date.now,
-            required: true
+            required: false
         },
         phonenumber: {
             type: Number,
-            required: true,
+            required: false,
             minlength: 3,
             maxlength: 50,
             match: [/^(?:(?:\+|00)33|0)\s*[1-9](?:[\s.-]*\d{2}){4}$/]

+ 1 - 1
express-server/package.json

@@ -27,7 +27,7 @@
     "mkdirp": "^1.0.4",
     "moment": "^2.25.3",
     "mongoose": "^5.12.2",
-    "mongoose-unique-validator": "^2.0.3",
+    "mongoose-unique-validator": "^2.0.1",
     "nodemailer": "^6.4.6",
     "nodemon": "^2.0.2",
     "passport": "^0.4.1",

+ 3 - 3
express-server/routes/user.js

@@ -13,19 +13,19 @@ const { LimitRequests } = require ('../middleware/limit-requests')
 router.get("/",  UserController.getAllUsers);
 
 //get user by id
-router.get('/:id',  UserController.getUserById);
+//router.get('/:id',  UserController.getUserById);
 router.get('/:id', authorize([Role.Client,Role.Employee,Role.Admin]), UserController.getUserById);
 
 //delete user by id
 router.delete('/:id', UserController.deleteUserById);
 
 //patch by id
-router.patch('/:id',  UserController.patchUserById)
+//router.patch('/:id',  UserController.patchUserById)
 router.patch('/:id', authorize([Role.Client,Role.Employee,Role.Admin]), UserController.patchUserById)
 
 //post code gain
 router.post('/gain', authorize(Role.Client), GainController.gain);
-router.post('/gain', GainController.gain);
+//router.post('/gain', GainController.gain);
 
 
 module.exports = router; 

+ 3 - 0
package-lock.json

@@ -0,0 +1,3 @@
+{
+  "lockfileVersion": 1
+}