-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from sensebox/update/tutorial-model
Update/tutorial model
- Loading branch information
Showing
8 changed files
with
189 additions
and
26 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
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,69 @@ | ||
// jshint esversion: 8 | ||
// jshint node: true | ||
"use strict"; | ||
|
||
const express = require("express"); | ||
const mongoose = require("mongoose"); | ||
|
||
const Tutorial = require("../../models/tutorial"); | ||
|
||
/** | ||
* @api {get} /tutorial Get tutorials | ||
* @apiName getTutorials | ||
* @apiDescription Get all tutorials as admin. | ||
* @apiGroup Tutorial | ||
* | ||
* @apiSuccess (Success 200) {String} message `Tutorials found successfully.` | ||
* @apiSuccess (Success 200) {Object} tutorials `[ | ||
{ | ||
"_id": "5fcf7caabd63e209146d3e85", | ||
"creator": "[email protected]", | ||
"title": "Test", | ||
"steps": [ | ||
{ | ||
"_id": "5fcf7caabd63e209146d3e87", | ||
"type": "instruction", | ||
"headline": "Einführung", | ||
"text": "In diesem Tutorial lernst du wie man die senseBox mit dem Internet verbindest.", | ||
"hardware": [ | ||
"senseboxmcu", | ||
"wifi-bee" | ||
] | ||
}, | ||
{ | ||
"_id": "5fcf7caabd63e209146d3e88", | ||
"type": "task", | ||
"headline": "Aufgabe 1", | ||
"text": "Stelle eine WLAN-Verbindung mit einem beliebigen Netzwerk her.", | ||
"xml": "<xml xmlns='https://developers.google.com/blockly/xml'><block type='arduino_functions' id='QWW|$jB8+*EL;}|#uA' deletable='false' x='27' y='16'><statement name='SETUP_FUNC'><block type='sensebox_wifi' id='W}P2Y^g,muH@]|@anou}'><field name='SSID'>SSID</field><field name='Password'>Password</field></block></statement></block></xml>" | ||
} | ||
], | ||
"createdAt": "2020-12-08T13:16:26.722Z", | ||
"updatedAt": "2020-12-13T19:25:40.529Z", | ||
"__v": 0 | ||
} | ||
]` | ||
* | ||
* @apiError (On error) {Obejct} 500 Complications during querying the database. | ||
*/ | ||
const getAllTutorials = async function (req, res) { | ||
try { | ||
if (req.user.role === "admin") { | ||
var result = await Tutorial.find({}); | ||
return res.status(200).send({ | ||
message: "Tutorials found successfully.", | ||
tutorials: result, | ||
}); | ||
} else { | ||
return res.status(403).send({ | ||
message: "No permission getting all the tutorial.", | ||
}); | ||
} | ||
} catch (err) { | ||
return res.status(500).send(err); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
getAllTutorials, | ||
}; |
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,65 @@ | ||
// jshint esversion: 8 | ||
// jshint node: true | ||
"use strict"; | ||
|
||
const express = require("express"); | ||
const mongoose = require("mongoose"); | ||
|
||
const Tutorial = require("../../models/tutorial"); | ||
|
||
/** | ||
* @api {get} /tutorial Get tutorials | ||
* @apiName getTutorials | ||
* @apiDescription Get all tutorials by one user. | ||
* @apiGroup Tutorial | ||
* | ||
* @apiSuccess (Success 200) {String} message `Tutorials found successfully.` | ||
* @apiSuccess (Success 200) {Object} tutorials `[ | ||
{ | ||
"_id": "5fcf7caabd63e209146d3e85", | ||
"creator": "[email protected]", | ||
"title": "Test", | ||
"steps": [ | ||
{ | ||
"_id": "5fcf7caabd63e209146d3e87", | ||
"type": "instruction", | ||
"headline": "Einführung", | ||
"text": "In diesem Tutorial lernst du wie man die senseBox mit dem Internet verbindest.", | ||
"hardware": [ | ||
"senseboxmcu", | ||
"wifi-bee" | ||
] | ||
}, | ||
{ | ||
"_id": "5fcf7caabd63e209146d3e88", | ||
"type": "task", | ||
"headline": "Aufgabe 1", | ||
"text": "Stelle eine WLAN-Verbindung mit einem beliebigen Netzwerk her.", | ||
"xml": "<xml xmlns='https://developers.google.com/blockly/xml'><block type='arduino_functions' id='QWW|$jB8+*EL;}|#uA' deletable='false' x='27' y='16'><statement name='SETUP_FUNC'><block type='sensebox_wifi' id='W}P2Y^g,muH@]|@anou}'><field name='SSID'>SSID</field><field name='Password'>Password</field></block></statement></block></xml>" | ||
} | ||
], | ||
"createdAt": "2020-12-08T13:16:26.722Z", | ||
"updatedAt": "2020-12-13T19:25:40.529Z", | ||
"__v": 0 | ||
} | ||
]` | ||
* | ||
* @apiError (On error) {Obejct} 500 Complications during querying the database. | ||
*/ | ||
const getUserTutorials = async function (req, res) { | ||
try { | ||
var userTutorials = await Tutorial.find({ creator: req.user.email }); | ||
var publicTutorials = await Tutorial.find({ public: true }); | ||
var result = userTutorials.concat(publicTutorials); | ||
return res.status(200).send({ | ||
message: "All User Tutorials found successfully.", | ||
tutorials: result, | ||
}); | ||
} catch (err) { | ||
return res.status(500).send(err); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
getUserTutorials, | ||
}; |
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
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