Skip to content

Commit

Permalink
Plans Create/Modify/Archive/Delete - Client & Server [Not including t…
Browse files Browse the repository at this point in the history
…asks selecting]

Topics Create/Modify/Archive/Delete - Client & Server [Not including tasks reordering & Not including rounded dependency validation]
  • Loading branch information
Korel Kashri committed Apr 4, 2020
1 parent 68935a2 commit e0a31eb
Show file tree
Hide file tree
Showing 20 changed files with 750 additions and 200 deletions.
2 changes: 1 addition & 1 deletion controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ exports.view_tasks_management_page = async (req, res, next) => {
try {
let cat_name = "tasks-management";
let route_param_name = "task_id";
//let render_params = await standard_management_params_to_render(req, cat_name, route_param_name, tasks_model.is_task_exists);
//let render_params = await standard_management_params_to_render(req, cat_name, route_param_name, tasks_model.is_task_exists); // TODO uncomment this line
res.render("pages/admin_panel", render_params);
} catch (e) {
return responses_gen.generate_response(res, 400, null, e.message);
Expand Down
52 changes: 52 additions & 0 deletions controllers/tasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const hash = require('../helpers/hash').get_hash_code;
const responses_gen = require('../helpers/responses');
const requests_handler = require('../helpers/requests_handler');
let tasks_model = require('../models/tasks');
const access_limitations = require('../helpers/configurations/access_limitations');

// API

exports.get_tasks = async (req, res, next) => {
try {
let tasks = await tasks_model.get(req, res, next);
return responses_gen.generate_response(res, 200, tasks, "Tasks successfully restored");
} catch (e) {
return responses_gen.generate_response(res, 400, null, e.message);
}
};

exports.get_task = async (req, res, next) => {
try {
let task = await tasks_model.get(req, res, next);
return responses_gen.generate_response(res, 200, task, "Task successfully restored");
} catch (e) {
return responses_gen.generate_response(res, 400, null, e.message);
}
};

exports.create = async (req, res, next) => {
try {
let task = await tasks_model.create(req, res, next);
return responses_gen.generate_response(res, 200, task, "Task successfully created");
} catch (e) {
return responses_gen.generate_response(res, 400, null, e.message);
}
};

exports.modify = async (req, res, next) => {
try {
let task = await tasks_model.modify(req, res, next);
return responses_gen.generate_response(res, 200, task, "Task successfully modified");
} catch (e) {
return responses_gen.generate_response(res, 400, null, e.message);
}
};

exports.remove = async (req, res, next) => {
try {
let result = await tasks_model.remove(req, res, next);
return responses_gen.generate_response(res, 200, null, "Task successfully removed");
} catch (e) {
return responses_gen.generate_response(res, 400, null, e.message);
}
};
8 changes: 8 additions & 0 deletions helpers/db_controllers/services/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ let init_plans_schema = async _ => {
estimated_days: {
type: Number,
required: true
},
is_active: {
type: Boolean,
default: true
}
});

Expand All @@ -39,6 +43,10 @@ let init_topics_schema = async _ => {
type: String,
required: true
},
is_active: {
type: Boolean,
default: true
},
dependencies_topics: [String] // Topics ids that should be done before this topic
});

Expand Down
7 changes: 6 additions & 1 deletion helpers/db_controllers/services/example_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"name": "Developer",
"route": [1000],
"description": "plan_description",
"estimated_days": 60
"estimated_days": 60,
"is_active": true
}
],

Expand Down Expand Up @@ -57,21 +58,25 @@
"_id": 2000,
"name": "topic_name",
"description": "topic_description",
"is_active": false,
"dependencies_topics": []
}, {
"_id": 2001,
"name": "topic_name_1",
"description": "topic_description_1",
"is_active": true,
"dependencies_topics": []
}, {
"_id": 2002,
"name": "c++",
"description": "topic_description_1",
"is_active": true,
"dependencies_topics": [2003]
}, {
"_id": 2003,
"name": "git",
"description": "topic_description_1",
"is_active": true,
"dependencies_topics": []
}
],
Expand Down
52 changes: 30 additions & 22 deletions models/plans.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ exports.get = async (req, res, next) => {
// Prepare query
let query;
if (target_plan) {
let req = {query: {}};
req.query.username = req.session.user.username;
req.query.plan_name = target_plan;
assert.ok(is_user_registered_to_plan(req, {}, {}), "You have no access to this plan.");
let validation_data = {query: {}};
validation_data.query.username = req.session.user.username;
validation_data.query.plan_name = target_plan;
assert.ok(is_user_registered_to_plan(validation_data, {}, {}), "You have no access to this plan.");
query = {name: target_plan};
} else {
query = {};
Expand All @@ -97,25 +97,30 @@ exports.create = async (req, res, next) => {
let plans_db_model = database.plans_model();

// Get main param
let target_plan = requests_handler.optional_param(req, "route","plan_name");
let target_plan = requests_handler.require_param(req, "route","plan_name");

// Validation
let plan_exists = await is_plan_exists({ query: { plan_name: target_plan } });
assert.equal(plan_exists, false, "Plan already exists"); // if exists, throw error

// Get params
let plan_description = requests_handler.optional_param(req, "post", "description");
let plan_estimated_days = requests_handler.optional_param(req, "post", "estimated_days");
let plan_description = requests_handler.require_param(req, "post", "description");
let plan_estimated_days = requests_handler.require_param(req, "post", "estimated_days");
let plan_route = requests_handler.optional_param(req, "post", "tasks_route");
let plan_active_status = requests_handler.optional_param(req, "post", "active_status");

// Perform action
let new_plan;
new_plan = new plans_db_model({
// Arrange data
let data = {
name: target_plan,
description: plan_description,
estimated_days: plan_estimated_days,
route: plan_route
});
estimated_days: plan_estimated_days
};
if (typeof plan_route != "undefined") data.roue = plan_route;
if (typeof plan_active_status != "undefined") data.is_active = plan_active_status;

// Perform action
let new_plan;
new_plan = new plans_db_model(data);
new_plan = new_plan.save();

return new_plan;
Expand All @@ -126,24 +131,27 @@ exports.modify = async (req, res, next) => {
let plans_db_model = database.plans_model();

// Get main param
let target_plan = requests_handler.optional_param(req, "route","plan_name");
let target_plan = requests_handler.require_param(req, "route","plan_name");

// Get params
let new_plan_name = requests_handler.optional_param(req, "post", "new_plan_name");
let new_plan_description = requests_handler.optional_param(req, "post", "new_description");
let new_plan_estimated_days = requests_handler.optional_param(req, "post", "new_estimated_days");
let new_plan_route = requests_handler.optional_param(req, "post", "new_tasks_route");
let new_active_status = requests_handler.optional_param(req, "post", "active_status");

// Arrange new data
let data = {};
if (typeof new_plan_name != "undefined") data.name = new_plan_name;
if (typeof new_plan_description != "undefined") data.description = new_plan_description;
if (typeof new_plan_estimated_days != "undefined") data.estimated_days = new_plan_estimated_days;
if (typeof new_plan_route != "undefined") data.roue = new_plan_route;
if (typeof new_active_status != "undefined") data.is_active = new_active_status;

// Prepare query
let filter = {name: target_plan};
let update = {
$set:
{
name: new_plan_name,
description: new_plan_description,
estimated_days: new_plan_estimated_days,
route: new_plan_route
}
$set: data
};

// Perform action
Expand All @@ -162,7 +170,7 @@ exports.remove = async (req, res, next) => {
let plans_db_model = database.plans_model();

// Get params
let target_plan = requests_handler.optional_param(req, "route","plan_name");
let target_plan = requests_handler.require_param(req, "route","plan_name");

// Validation
assert.ok(is_plan_exists({query: {plan_name: target_plan}}, {}, {}), "Plan not found.");
Expand Down
43 changes: 30 additions & 13 deletions models/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,31 @@ exports.create = async (req, res, next) => {
let topics_db_model = database.topics_model();

// Get main param
let target_topic = requests_handler.optional_param(req, "route","topic_name");
let target_topic = requests_handler.require_param(req, "route","topic_name");

// Validation
let topic_exists = await is_topic_exists({ query: { topic_name: target_topic } });
assert.equal(topic_exists, false, "Topic already exists"); // if exists, throw error

// Get params
let topic_description = requests_handler.optional_param(req, "post", "description");
let topic_description = requests_handler.require_param(req, "post", "description");
let topic_dependencies = requests_handler.optional_param(req, "post", "dependencies");
let topic_active_status = requests_handler.optional_param(req, "post", "active_status");

// Arrange data
let data = {
name: target_topic,
description: topic_description
};
if (typeof topic_dependencies != "undefined") {
topic_dependencies = topic_dependencies && topic_dependencies.split(',');
data.dependencies_topics = topic_dependencies || [];
}
if (typeof topic_active_status != "undefined") data.is_active = topic_active_status;

// Perform action
let new_topic;
new_topic = new topics_db_model({
name: target_topic,
description: topic_description,
dependencies_topics: topic_dependencies
});
new_topic = new topics_db_model(data);
new_topic = new_topic.save();

return new_topic;
Expand All @@ -103,16 +111,23 @@ exports.modify = async (req, res, next) => {
let new_topic_name = requests_handler.optional_param(req, "post", "new_topic_name");
let new_topic_description = requests_handler.optional_param(req, "post", "new_topic_description");
let new_topic_dependencies = requests_handler.optional_param(req, "post", "new_topic_dependencies");
let new_topic_active_status = requests_handler.optional_param(req, "post", "new_topic_active_status");


// Arrange new data
let data = {};
if (typeof new_topic_name != "undefined") data.name = new_topic_name;
if (typeof new_topic_description != "undefined") data.description = new_topic_description;
if (typeof new_topic_dependencies != "undefined") {
new_topic_dependencies = new_topic_dependencies && new_topic_dependencies.split(',');
data.dependencies_topics = new_topic_dependencies || [];
}
if (typeof new_topic_active_status != "undefined") data.is_active = new_topic_active_status;

// Prepare query
let filter = {name: target_topic};
let update = {
$set:
{
name: new_topic_name,
description: new_topic_description,
dependencies_topics: new_topic_dependencies
}
$set: data
};

// Perform action
Expand All @@ -138,6 +153,8 @@ exports.remove = async (req, res, next) => {

// Perform action
return topics_db_model.remove({name: target_topic}).exec();

// TODO delete as well all topic related tasks
};

exports.get_topic_id = get_topic_id;
Expand Down
2 changes: 1 addition & 1 deletion private/resources/scss/materialize/components/_chips.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
outline: 0;
margin: 0;
padding: 0 !important;
width: 120px !important;
width: 150px !important;
}

.input:focus {
Expand Down
Loading

0 comments on commit e0a31eb

Please sign in to comment.