Skip to content
This repository has been archived by the owner on Oct 3, 2019. It is now read-only.

Commit

Permalink
#30 Implementando validações com o banco
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriela Barrozo Guedes <gabrielabguedes@gmail.com>
Signed-off-by: Vitor Leal <vitinho2201@gmail.com>

Co-authored-by: Gabriela Barrozo Guedes <gabrielabguedes@gmail.com>
Co-authored-by: Vitor Leal <vitinho2201@gmail.com>
  • Loading branch information
gabibguedes and vitorl-s committed May 12, 2018
1 parent 1189081 commit 6ab305b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Schedule/Server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "app.js",
"scripts": {
"start": "nodemon sector.js"
"start": "nodemon schedule.js"
},
"author": "",
"license": "MIT",
Expand Down
11 changes: 11 additions & 0 deletions Schedule/Server/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ require('seneca')()
schedule.specialty = msg.specialty
schedule.amount_of_hours = msg.amount_of_hours

schedule.list$({date:schedule.date, employee:schedule.employee}, function(err,list){
list.forEach(function(time){
if (Date.parse(schedule.start_time) >= Date.parse(time.start_time) && Date.parse(schedule.start_time) <= Date.parse(time.end_time)) {
respond(null, {success:false, message: 'Este funcionário possui uma escala em conflito com o horário selecionado'})
}else if (Date.parse(schedule.end_time) >= Date.parse(time.start_time) && Date.parse(schedule.end_time) <= Date.parse(time.end_time)) {
respond(null, {success:false, message: 'Este funcionário possui uma escala em conflito com o horário selecionado'})
}else if(Date.parse(schedule.start_time) <= Date.parse(time.start_time) && Date.parse(schedule.end_time) >= Date.parse(time.end_time)){
respond(null, {success:false, message: 'Este funcionário possui uma escala em conflito com o horário selecionado'})
}
})
})
schedule.save$(function(err,schedule){
respond(null,schedule)
})
Expand Down

0 comments on commit 6ab305b

Please sign in to comment.