formation 4 سال پیش
والد
کامیت
4bf4ee324a

+ 41 - 0
express-server/models/contact.model.js

@@ -0,0 +1,41 @@
+const mongoose = require('mongoose');
+
+const ContactSchema = new mongoose.Schema(
+    {
+        
+        lastname: {
+            type: String,
+            required: true,
+            minlength: 2
+        },
+        email: {
+            type: String,
+            required: true,
+            minlength: 2
+        },
+        created_date: {
+            type: Date,
+            default: Date.now,
+            required: true
+        },
+        message: {
+            type: String,
+            required: true,
+            minlength: 2
+        },
+        response: {
+            type: String,
+        },
+        is_closed: {
+            type: Boolean,
+        },
+        response_date: {
+            type: Date
+        },
+    }
+);
+
+exports.ContactSchema = ContactSchema;
+
+Contact = mongoose.model('Contact', ContactSchema );
+ exports.Contact = Contact;

+ 35 - 0
express-server/models/email.model.js

@@ -0,0 +1,35 @@
+const mongoose = require('mongoose');
+
+const EmailSchema = new mongoose.Schema(
+    {
+        
+        title: {
+            type: String,
+            required: true,
+            minlength: 2
+        },
+        description: {
+            type: String,
+            required: true,
+            minlength: 2
+        },
+        created_date: {
+            type: Date,
+            default: Date.now,
+            required: true
+        },
+        text: {
+            type: String,
+            required: true
+        },
+        subject: {
+            type: String,
+            required: true,
+        }
+    }
+);
+
+exports.EmailSchema = EmailSchema;
+
+Email = mongoose.model('Email', EmailSchema );
+ exports.Email = Email;

+ 63 - 0
express-server/models/employee.model.js

@@ -0,0 +1,63 @@
+const mongoose = require('mongoose');
+const uniqueValidator = require('mongoose-unique-validator');
+ 
+
+const EmployeeSchema = new mongoose.Schema(
+    {
+        firstname: {
+            type: String,
+            required: true,
+            trim: true,
+            lowercase: true,
+            minlength: 2,
+            maxlength: 50
+        },
+        lastname: {
+            type: String,
+            required: true,
+            minlength: 2,
+            maxlength: 50
+        },
+        username: {
+            type: String,
+            required: true,
+            minlength: 2,
+            maxlength: 2500
+        },
+        email: {
+            type: String,
+            required: true,
+            minlength: 2
+        },
+        password: {
+            type: String,
+            required: true,
+            minlength: 2
+        },
+        role: {
+            type: String,
+            enum: ['admin', 'employee']
+        },
+        register_date: {
+            type: Date,
+            default: Date.now,
+            required: true
+        },
+        phonenumber: {
+            type: Number,
+            required: true,
+            minlength: 3,
+            maxlength: 50,
+        },
+        isActive: {
+            type: Boolean,
+        }
+    }
+);
+
+
+
+exports.EmployeeSchema = EmployeeSchema;
+
+Employee = mongoose.model('Employee', EmployeeSchema );
+ exports.Employee = Employee;

+ 38 - 0
express-server/models/message.model.js

@@ -0,0 +1,38 @@
+const mongoose = require('mongoose');
+
+const MessageSchema = new mongoose.Schema(
+    {
+        
+        title: {
+            type: String,
+            required: true,
+            minlength: 2
+        },
+        email: {
+            type: String,
+            required: true,
+            minlength: 2
+        },
+        created_date: {
+            type: Date,
+            default: Date.now,
+            required: true
+        },
+        text: {
+            type: String,
+            required: true
+        },
+        subject: {
+            type: String,
+            required: true,
+        },
+        isClosed: {
+            type: Boolean,
+        }
+    }
+);
+
+exports.MessageSchema = MessageSchema;
+
+Message = mongoose.model('Message', MessageSchema );
+ exports.Message = Message;

+ 27 - 0
express-server/models/restaurant.model.js

@@ -0,0 +1,27 @@
+const mongoose = require('mongoose');
+
+
+const RestaurantSchema = new mongoose.Schema(
+    {
+        name: {
+            type: String,
+        },
+        index: {
+            type: Number,
+        },
+        adress: {
+            type: String,
+        },
+        latitude: {
+            type: Number
+        },
+        longitude: {
+            type: Number
+        },
+    }
+);
+
+exports.RestaurantSchema = RestaurantSchema;
+
+Restaurant = mongoose.model('Restaurant', RestaurantSchema );
+ exports.Restaurant = Restaurant;

+ 40 - 0
express-server/models/ticket.model.js

@@ -0,0 +1,40 @@
+const mongoose = require('mongoose');
+
+const TicketSchema = new mongoose.Schema(
+    {
+        index: {
+            type: String,
+            required: true,
+        },
+        gains: {
+            type: String,
+            required: true,
+            minlength: 2
+        },
+        date_used: {
+            type: Date,
+            required: true
+        },
+        // date_expired: {
+        //     type: Date,
+        //     required: true
+        // },
+        isUsed: {
+            type: Boolean,
+            required: true
+        },
+        code: {
+            type: Number,
+            required: true,
+        },
+        isServed: {
+            type: Boolean,
+            required: true
+        }
+    }
+);
+
+exports.TicketSchema = TicketSchema;
+
+Ticket = mongoose.model('Ticket', TicketSchema );
+ exports.Ticket = Ticket;

+ 29 - 0
express-server/models/tirage.model.js

@@ -0,0 +1,29 @@
+const mongoose = require('mongoose');
+const { UserSchema } = require('./user.model');  
+
+const TirageSchema = new mongoose.Schema(
+    {
+        nb_users: {
+            type: Number,
+        },
+        random_user: {
+            type: Number,
+        },
+        executed_date: {
+            type: Date,
+        },
+        tirage_date: {
+            type: Date,
+        },
+        isExecuted: {
+            type: Boolean,
+            default: false
+        },
+        winner:  UserSchema  
+    }
+);
+
+exports.TirageSchema = TirageSchema;
+
+Tirage = mongoose.model('Tirage', TirageSchema );
+ exports.Tirage = Tirage;

+ 96 - 0
express-server/models/user.model.js

@@ -0,0 +1,96 @@
+const mongoose = require('mongoose');
+const uniqueValidator = require('mongoose-unique-validator');
+const {TicketSchema} = require('./ticket.model');  
+
+const UserSchema = new mongoose.Schema(
+    {
+        firstname: {
+            type: String,
+            required: true,
+            trim: true,
+            lowercase: true,
+            minlength: 2,
+            maxlength: 50,
+            match: [/^[a-zA-ZàáâäãåąčćęèéêëėįìíîïłńòóôöõøùúûüųūÿýżźñçčšžÀÁÂÄÃÅĄĆČĖĘÈÉÊËÌÍÎÏĮŁŃÒÓÔÖÕØÙÚÛÜŲŪŸÝŻŹÑßÇŒÆČŠŽ∂ð ,.'-]+$/]
+        },
+        lastname: {
+            type: String,
+            required: true,
+            trim: true,
+            minlength: 2,
+            maxlength: 50,
+            match: [/^[a-zA-ZàáâäãåąčćęèéêëėįìíîïłńòóôöõøùúûüųūÿýżźñçčšžÀÁÂÄÃÅĄĆČĖĘÈÉÊËÌÍÎÏĮŁŃÒÓÔÖÕØÙÚÛÜŲŪŸÝŻŹÑßÇŒÆČŠŽ∂ð ,.'-]+$/]
+        },
+        email: {
+            type: String,
+            required: true,
+            lowercase: true,
+            match: [/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/]
+        },
+        password: {
+            type: String,
+            required: true,
+            minlength: 2
+        },
+        role: {
+            type: String,
+            enum: ['client', 'employee', 'admin']
+        },
+        birthday: {
+            type: Date,
+            required: true
+        },
+        register_date: {
+            type: Date,
+            default: Date.now,
+            required: true
+        },
+        phonenumber: {
+            type: Number,
+            required: true,
+            minlength: 3,
+            maxlength: 50,
+            match: [/^(?:(?:\+|00)33|0)\s*[1-9](?:[\s.-]*\d{2}){4}$/]
+            //pour faire des validations
+
+            // validate(value) {
+            //     if(value < 0){
+            //         throw new Error('numero de telephone must be a positive number')
+            //     }
+            // }
+        },
+        adress: {
+            type: String,
+            minlength: 5,
+            maxlength: 300,
+            match: [/^[A-z0-9À-ž\s ,.'-]+$/]
+        },
+        isActive: {
+            type: Boolean,
+        },
+        isGain: {
+            type: Boolean,
+        },
+        googleId: {
+            type: String
+        },
+        facebookId: {
+            type: String
+        },
+        resetLink: {
+            type: String,
+            default: ''
+        },
+        gains: {
+            type:  [TicketSchema]
+        } 
+    }
+);
+
+//unique validator
+UserSchema.plugin(uniqueValidator);
+
+exports.UserSchema = UserSchema;
+
+User = mongoose.model('User', UserSchema );
+ exports.User = User;