We want a mongo instance of both winner and wine.
The inputs to these functions are objects, if we want to use mongoose we need to get a new instance of wine and winner.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
const Winner = require(path.join(__dirname, "/schemas/Highscore"));
|
const Winner = require(path.join(__dirname, "/schemas/Highscore"));
|
||||||
const Wine = require(path.join(__dirname, "/schemas/Wine"));
|
const WineRepository = require(path.join(__dirname, "/wine"));
|
||||||
|
|
||||||
class HistoryByDateNotFound extends Error {
|
class HistoryByDateNotFound extends Error {
|
||||||
constructor(message = "History for given date not found.") {
|
constructor(message = "History for given date not found.") {
|
||||||
@@ -24,10 +24,15 @@ const addWinnerWithWine = async (winner, wine) => {
|
|||||||
const exisitingWinner = await Winner.findOne({
|
const exisitingWinner = await Winner.findOne({
|
||||||
name: winner.name
|
name: winner.name
|
||||||
});
|
});
|
||||||
|
const savedWine = await WineRepository.addWine(wine);
|
||||||
|
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
date.setHours(5, 0, 0, 0);
|
date.setHours(5, 0, 0, 0);
|
||||||
const winObject = { date, wine, color: winner.color };
|
const winObject = {
|
||||||
|
date: date,
|
||||||
|
wine: savedWine,
|
||||||
|
color: winner.color
|
||||||
|
};
|
||||||
|
|
||||||
if (exisitingWinner == undefined) {
|
if (exisitingWinner == undefined) {
|
||||||
const newWinner = new Winner({
|
const newWinner = new Winner({
|
||||||
|
|||||||
Reference in New Issue
Block a user