Browse Source

pagination

master
arnaucode 7 years ago
parent
commit
af912e3a3b
5 changed files with 22 additions and 120 deletions
  1. +8
    -112
      README.md
  2. +2
    -1
      config.js
  3. +6
    -4
      controllers/searchController.js
  4. +2
    -1
      controllers/travelController.js
  5. +4
    -2
      controllers/userController.js

+ 8
- 112
README.md

@ -1,6 +1,7 @@
#CollectiveCar app
# CarsInCommonServer
frontend app code: https://github.com/idoctnef/collectivecarApp
frontend app code: https://github.com/idoctnef/carsincommonApp
images server: https://github.com/arnaucode/goImgServer
**Backend:**
Nodejs + Express + MongoDB
@ -11,121 +12,16 @@ frontend app code: https://github.com/idoctnef/collectivecarApp
##To Do List:
**Backend and Frontend:**
**To Do Backend and Frontend:**
```
-signup user --> done
-signup unique username --> done
-loggin user --> done
-update user profile --> done
-create new travel --> done
-update travel --> done
-delete travel --> done
-create offeringCar --> done
-update offeringCar
-delete offeringCar --> done
-create askingForTravel (needtravel) --> done
-update askingForTravel
-delete askgingForTravel --> done
-create askingPackage (need transport package) --> done
-update askingPackage
-delete askgingPackage --> done
-user joins a car --> done
-user offer car to a travel --> done
-user offer car to a askingpackage --> done
-user unjoins a car --> done
-user unoffer car to a travel --> done
-user unoffer car to a askingpackage --> done
-comment publication(car, travel, package) --> done
-valorating users system --> done
-passed dates not shown from server --> done
-don't allow to add travels with passed date (on frontend and backend)
-acabar de fer robust quan esborres un travel
-GUI admin page
-UX design
-interface graphic design
-icons
-api more secure and robust (comprovations, hash passwords, ...)
-web page (webapp) --> (de moment es pot penjar la app en versió web tal qual,
que es podrà fer servir des d'un navegador com si fós la app)
-es veu el telèfon dels users?
-com evitem q algú xungu es registri a la app i vegi els viatges i info dels users?
-falta acabar notification system
quan mires les notificacions, que avisi al server q ja les has vist, i que el server les marqui com a llegides
link a les notificacions
acabar de mirar q a la app, quan agafa els users del server, tingui actualitzades les notificacions del user al menu
```
--------------------
####**PARA LA BASE DE DATOS** [para definir como queremos q esté estructurado, pensando en las funcionalidades que queremos tener]:
- pagination search
- https (tls/ssl)
```
var userSchema = new Schema({
username: { type: String },
password: { type: String },
description: { type: String },
avatar: { type: String },
mail: { type: String },
phone: { type: String },
telegram: { type: String }
})
var travelSchema = new Schema({
title: { type: String },
description: { type: String },
owner: { type: String },
from: { type: String },
to: { type: String },
date: { type: Date },
periodic: { type: Boolean },
generateddate: { type: Date },
seats: { type: Number },
package: { type: Boolean },
icon: { type: String },
phone: { type: Number },
telegram: { type: String },
collectivized: { type: Boolean },
modality: { type: String } //if is an offering travel or asking for travel
})
var joinSchema = new Schema({
travelId: { type: String },
joinedUserId: { type: String },
joinedUsername: { type: String },
acceptedUserId: { type: String },
joinedAvatar: { type: String }
});
var commentSchema = new Schema({
travelId: { type: String },
commentUserId: { type: String },
commentUsername: { type: String },
comment: { type: String },
commentAvatar: { type: String }
});
```
--------------------
####**RESOURCES using**:
car icons [http://www.flaticon.com/packs/transportation-7](http://www.flaticon.com/packs/transportation-7)
css para la app: matterializeCSS [http://materializecss.com/](http://materializecss.com/)
avatars users: [http://www.flaticon.com/packs/animal-icon-collection](http://www.flaticon.com/packs/animal-icon-collection)
#### RESOURCES using:
mirar per fer hash de passwords https://www.npmjs.com/package/bcrypt-nodejs
initial avatars users: [http://www.flaticon.com/packs/animal-icon-collection](http://www.flaticon.com/packs/animal-icon-collection)

+ 2
- 1
config.js

@ -3,6 +3,7 @@ module.exports = {
'database': process.env.MONGO_DSN,*/
'secret': 'secretfortoken',// local version
'database': 'mongodb://localhost/carsincommon',
"port" : process.env.PORT || 3000
"port" : process.env.PORT || 3000,
"pageSize": 20
};

+ 6
- 4
controllers/searchController.js

@ -4,6 +4,8 @@ var userModel = mongoose.model('userModel');
var notificationModel = mongoose.model('notificationModel');
var travelModel = mongoose.model('travelModel');
var config = require('../config');
var pageSize=config.pageSize;
/* */
var jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens
@ -21,8 +23,8 @@ exports.searchByString = function (req, res) {
userModel.find({
username: new RegExp(req.params.searchstring, "i")
})//perquè retorni tots els objectes que continguin l'string sense necessitat de que sigui exactament la mateixa string
.limit(Number(req.query.pageSize))
.skip(Number(req.query.pageSize) * Number(req.query.page))
.limit(pageSize)
.skip(pageSize * Number(req.query.page))
.lean()
.select('username avatar')
.exec(function (err, users) {
@ -34,8 +36,8 @@ exports.searchByString = function (req, res) {
{title: new RegExp(req.params.searchstring, "i")}
]
})//perquè retorni tots els objectes que continguin l'string sense necessitat de que sigui exactament la mateixa string
.limit(Number(req.query.pageSize))
.skip(Number(req.query.pageSize) * Number(req.query.page))
.limit(pageSize)
.skip(pageSize * Number(req.query.page))
.lean()
.select('title from to date type')
.exec(function (err, travels) {

+ 2
- 1
controllers/travelController.js

@ -5,8 +5,9 @@ var notificationModel = mongoose.model('notificationModel');
var travelModel = mongoose.model('travelModel');
var commentModel = mongoose.model('commentModel');
var config = require('../config');
var pageSize=config.pageSize;
//GET
var pageSize=20;
exports.getAllTravels = function(req, res) {
//get travels with futures dates ($gte - greater than and equal than)
travelModel.find({date: {$gte: new Date()}})

+ 4
- 2
controllers/userController.js

@ -4,6 +4,8 @@ var userModel = mongoose.model('userModel');
var notificationModel = mongoose.model('notificationModel');
var travelModel = mongoose.model('travelModel');
var config = require('../config');
var pageSize=config.pageSize;
/* */
var jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens
@ -153,8 +155,8 @@ exports.login = function(req, res) {
//GET - Return all Users in the DB
exports.getAllUsers = function(req, res) {
userModel.find()
.limit(Number(req.query.pageSize))
.skip(Number(req.query.pageSize) * Number(req.query.page))
.limit(pageSize)
.skip(pageSize * Number(req.query.page))
.exec(function(err, users) {
if (err) return res.send(500, err.message);
res.status(200).jsonp(users);

Loading…
Cancel
Save