From c5aeb5e67319be6cac366e2ba50f2ee498e25865 Mon Sep 17 00:00:00 2001 From: Shubhi Sareen Date: Sat, 23 Jul 2016 02:01:36 +0530 Subject: [PATCH] Create,cancel, update a Special Interest Group for IEEE DTU --- api/controllers/SIG.js | 60 ++++++++++++++++++++++++++++++++++++++++++ api/models/Sig.js | 29 ++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 api/controllers/SIG.js create mode 100644 api/models/Sig.js diff --git a/api/controllers/SIG.js b/api/controllers/SIG.js new file mode 100644 index 0000000..77db692 --- /dev/null +++ b/api/controllers/SIG.js @@ -0,0 +1,60 @@ +/** + * SIGController + * + * @description :: Server-side logic for managing comments + * @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers + */ + +module.exports = { + + + + /** + * `SIGController.create()` + */ + create: function (req, res) { + var instructor = req.param('instructorName'); + var title = req.param('title'); + var date = req.param('date'); + Sig.create({ + instructorName = instructor, + title = title, + date = date, + }).exec(function create(err, created){ + console.log('Created SIG with title ' + created.title); +}); + }, + + + /** + * `SIGController.cancel()` + */ + cancel: function (req, res) { + Sig.destroy({ + title: req.param('title'); +}).exec(function (err){ + if (err) { + return res.negotiate(err); + } + sails.log('Deleted SIG with title' + title +', if it existed.'); + return res.ok(); +}); + }, + + + /** + * `SIGController.update()` + */ + update: function (req, a, res) { + Sig.update({date:'req.date'},{date: a}).exec(function afterwards(err, updated){ + + if (err) { + // handle error here- e.g. `res.serverError(err);` + return; + } + + console.log('Updated SIG to have date ' + updated[0].date); +}); + +}; + diff --git a/api/models/Sig.js b/api/models/Sig.js new file mode 100644 index 0000000..9b9957f --- /dev/null +++ b/api/models/Sig.js @@ -0,0 +1,29 @@ +module.exports = { + + attributes: { + instructorName: { + type: 'string', + defaultsTo: '' + }, + topic: { + type: 'string', + defaultsTo: '' + }, + date: { + type: 'string' + defaultsTo: '' + }, + + getName: function (){ + return this.instructorName; + }, + getTopic: function () { + return this.topic; + }, + getDate: function (){ + return this.date; + }, + + } +}; +