Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back end #25

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Logs
front-end/logs
front-end/*.log
front-end/npm-debug.log*
front-end/yarn-debug.log*
front-end/yarn-error.log*
front-end/pnpm-debug.log*
front-end/lerna-debug.log*

front-end/node_modules
front-end/dist
front-end/dist-ssr
front-end/*.local

# Editor directories and files
front-end/.vscode/*
front-end/!.vscode/extensions.json
front-end/.idea
front-end/.DS_Store
front-end/*.suo
front-end/*.ntvs*
front-end/*.njsproj
front-end/*.sln
front-end/*.sw?

# server files
back-end/node_modules
bacl-end/package-lock.json
5 changes: 5 additions & 0 deletions back-end/helpers/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const constants = {
USER_API : 'http://localhost:4000/api/user'
}

export default constants;
19 changes: 19 additions & 0 deletions back-end/helpers/user-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { Products } = require('../model/model');

module.exports = {
randomItems: () => {
return new Promise(async (resolve,reject) => {
const products = await Products.find();

arr = [];

for (let i = 0; i < 4; i++) {
product = products[Math.floor(Math.random() * products.length)];
if (!arr.some(item => item === product))
arr.push(product);
}

resolve(arr);
})
}
}
56 changes: 56 additions & 0 deletions back-end/model/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const UserSchema = new Schema({
username: {
type: String,
required: [true, 'username field is required']
},
email: {
type: String,
required: [true, 'Email field is required']
},
password:{
type: String,
required: [true, 'password field is required']
},
date : {
type: Date,
default : Date.now
}
});

const contactSchema = new Schema({
_id: {
type: Schema.Types.ObjectId, auto: true
},
name : {
type: String,
required: [true, 'name field is required']
},
phone : {
type: String,
required: [true, 'phone_no field is required']
},
email : {
type: String,
required: [true, 'email field is required']
},
address : {
type: String,
required: [true, 'address field is required']
}

})

const userContacts = new Schema({
contacts: [contactSchema] // Array to store contacts
});

const User = mongoose.model('users',UserSchema);
const Contact = mongoose.model('contacts',userContacts);

module.exports = {
User,
Contact
};
Loading