Skip to content

Commit

Permalink
First Stable Release 🙈
Browse files Browse the repository at this point in the history
Added authentication support for tests
Added more thorough validators
Fixed missing field types in models

Finalized code styling and indentations

..... and many more bug fixes.
  • Loading branch information
Sithira committed Jun 16, 2018
1 parent 1c72929 commit 15fe809
Show file tree
Hide file tree
Showing 24 changed files with 1,342 additions and 1,189 deletions.
84 changes: 42 additions & 42 deletions app/Models/Hooks/ProjectForceDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ const ProjectForceDelete = exports = module.exports = {};
*/
ProjectForceDelete.removeSprints = async (project) =>
{

// query the object again, with sprints
let projectQueried = await Project.with(['sprints']).find(project._id);

// call the relationship
let sprints = await projectQueried.sprints().fetch();

// check for any matching sprints
if (sprints.rows.length > 0)
{

// loop for the rows count.
for (let i = 0; i < sprints.rows.length; i++)
{

// delete the sprint.
await sprints.rows[i].delete();
}

}
// query the object again, with sprints
let projectQueried = await Project.with(['sprints']).find(project._id);
// call the relationship
let sprints = await projectQueried.sprints().fetch();
// check for any matching sprints
if (sprints.rows.length > 0)
{
// loop for the rows count.
for (let i = 0; i < sprints.rows.length; i++)
{
// delete the sprint.
await sprints.rows[i].delete();
}
}
};

/**
Expand All @@ -40,27 +40,27 @@ ProjectForceDelete.removeSprints = async (project) =>
* @param project
* @return {Promise<void>}
*/
ProjectForceDelete.removeReleases = async(project) =>
ProjectForceDelete.removeReleases = async (project) =>
{

// find the model
let projectQueried = await Project.with(['releases']).find(project._id);

// fetch the relationships
let releases = await projectQueried.releases().fetch();

// check for the array
if (releases.rows.length > 0)
{

// loop the instances
for (let i = 0; i < releases.rows.length; i++)
{

// delete the model
await releases.rows[i].delete();
}

}

// find the model
let projectQueried = await Project.with(['releases']).find(project._id);
// fetch the relationships
let releases = await projectQueried.releases().fetch();
// check for the array
if (releases.rows.length > 0)
{
// loop the instances
for (let i = 0; i < releases.rows.length; i++)
{
// delete the model
await releases.rows[i].delete();
}
}
};
44 changes: 22 additions & 22 deletions app/Models/Hooks/SprintForceDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ const SprintForceDelete = exports = module.exports = {};
*/
SprintForceDelete.removeTickets = async (sprint) =>
{

// Get the model instance
let sprintQueried = await Sprint.with(['tickets']).find(sprint._id);

// get the model instance with with the related model instances
let tickets = await sprintQueried.tickets().fetch();

// get the rows count
if (tickets.rows.length > 0)
{

// run the delete operation for every related instance
for (let i = 0; i < tickets.rows.length; i++)
{

// delete the model.
await tickets.rows[i].delete();

}

}

// Get the model instance
let sprintQueried = await Sprint.with(['tickets']).find(sprint._id);
// get the model instance with with the related model instances
let tickets = await sprintQueried.tickets().fetch();
// get the rows count
if (tickets.rows.length > 0)
{
// run the delete operation for every related instance
for (let i = 0; i < tickets.rows.length; i++)
{
// delete the model.
await tickets.rows[i].delete();
}
}
};
44 changes: 22 additions & 22 deletions app/Models/Hooks/UserForceDeleteHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ const UserForceDeleteHook = exports = module.exports = {};
*/
UserForceDeleteHook.removeProjects = async (user) =>
{

// get a new instance of the model with relations
let userQueried = await User.with(['owned_projects']).find(user._id);

// check for the count
if (userQueried.$relations.owned_projects.rows.length >= 1)
{

// get the projects that a user is associated with
let projects = userQueried.$relations.owned_projects.rows;

// loop through every project
for (let i = 0; i < userQueried.$relations.owned_projects.rows.length; i++)
{

// delete the project from existence.
await projects[i].delete();

}

}

// get a new instance of the model with relations
let userQueried = await User.with(['owned_projects']).find(user._id);
// check for the count
if (userQueried.$relations.owned_projects.rows.length >= 1)
{
// get the projects that a user is associated with
let projects = userQueried.$relations.owned_projects.rows;
// loop through every project
for (let i = 0; i < userQueried.$relations.owned_projects.rows.length; i++)
{
// delete the project from existence.
await projects[i].delete();
}
}
};
151 changes: 73 additions & 78 deletions app/Models/Project.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,81 @@
'use strict'
'use strict';

const Model = use('Model');

class Project extends Model
{

static boot()
{
super.boot();

// mongoDB hook for delete associates sprints.
this.addHook('beforeDelete', 'ProjectForceDelete.removeSprints');

// mongoDB hook for delete associated releases.
this.addHook('beforeDelete', 'ProjectForceDelete.removeReleases');
}

static get primaryKey()
{
return "_id";
}

static get objectIDs()
{
return ['_id', '_client_id', 'team_id'];
}

/**
* Return the manager that belong to the project
*
* @returns {HasOne}
*/
manager()
{
return this.hasOne("App/Models/User", "_manager_id", "_id");
}

/**
* Get the client for the project
*
* @return {BelongsTo}
*/
client()
{
return this.belongsTo("App/Models/User", "_client_id", "_id");
}

/**
* Get the Phases of a project
*
* @return {HasMany}
*/
sprints()
{
return this.hasMany('App/Models/Sprint', '_id', '_project_id')
}

/**
* Get the project version
*
* @return {HasMany}
*/
releases()
{
return this.hasMany('App/Models/Release', '_id', '_project_id');
}

team()
{
return this.hasOne('App/Models/Team', '_team_id', '_id');
}

/**
* Get the requirements of the project
*
* @return {HasMany}
*/
requirements()
{
return this.hasMany('App/Models/Requirement', '_id', '_project_id');
}


static get primaryKey()
{
return "_id";
}

static get objectIDs()
{
return ['_id', '_client_id', '_manager_id', '_team_id'];
}

static boot()
{
super.boot();

// mongoDB hook for delete associates sprints.
this.addHook('beforeDelete', 'ProjectForceDelete.removeSprints');

// mongoDB hook for delete associated releases.
this.addHook('beforeDelete', 'ProjectForceDelete.removeReleases');
}

/**
* Return the manager that belong to the project
*
* @returns {HasOne}
*/
manager()
{
return this.hasOne("App/Models/User", "_manager_id", "_id");
}

/**
* Get the client for the project
*
* @return {BelongsTo}
*/
client()
{
return this.belongsTo("App/Models/User", "_client_id", "_id");
}

/**
* Get the Phases of a project
*
* @return {HasMany}
*/
sprints()
{
return this.hasMany('App/Models/Sprint', '_id', '_project_id')
}

/**
* Get the project version
*
* @return {HasMany}
*/
releases()
{
return this.hasMany('App/Models/Release', '_id', '_project_id');
}

/**
* Get the team that the project has been assigned to
*
* @return {HasOne}
*/
team()
{
return this.hasOne('App/Models/Team', '_team_id', '_id');
}

}

module.exports = Project;
Loading

0 comments on commit 15fe809

Please sign in to comment.