-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
168 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var mongoose = require('mongoose'); | ||
var Schema = mongoose.Schema; | ||
|
||
|
||
//создаём схему БД | ||
|
||
var historySchema = new Schema({ | ||
userId: { | ||
type: String, | ||
required: true, | ||
// unique: true | ||
}, | ||
weatherData:[{ | ||
type: Object | ||
}], | ||
creationDate: { type: Date, default: Date.now }, | ||
city: {type: String}, | ||
// _id: { type: String }, | ||
}); | ||
|
||
|
||
//создаём модель с использованием схемы | ||
const History = mongoose.model('History', historySchema); | ||
|
||
|
||
//экспорт для доступа извне | ||
module.exports = History; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,67 @@ | ||
const addHistoryData = (param) => { | ||
const History = require('../models/history.model'); | ||
|
||
// const addHistoryData = (param) => { | ||
|
||
// return new Promise((resolve, reject) => { | ||
// User.findOne(param, function(err, user) { | ||
// if (err) { | ||
// reject(err); | ||
// } else { | ||
// resolve(user) | ||
// } | ||
// }) | ||
// }) | ||
|
||
|
||
// } | ||
|
||
|
||
|
||
const addHistoryData = (inputData) => { | ||
return new Promise((resolve, reject) => { | ||
History.create(inputData, function(err, history) { | ||
console.log('err', err) | ||
console.log('user', history) | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(history) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
|
||
const getList = (param) => { | ||
return new Promise((resolve, reject) => { | ||
User.findOne(param, function(err, user) { | ||
History.find(param, function(err, history) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(user) | ||
resolve(history) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
|
||
const getHistory = (param) => { | ||
return new Promise((resolve, reject) => { | ||
History.findOne(param, function(err, history) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(history) | ||
} | ||
}) | ||
}) | ||
|
||
|
||
} | ||
|
||
|
||
module.exports = { | ||
addHistoryData, | ||
getHistory, | ||
getList | ||
} |