Skip to content

Commit

Permalink
Fix bug that causes incorrect people to be removed from project
Browse files Browse the repository at this point in the history
  • Loading branch information
sopa301 committed Dec 15, 2023
1 parent c96dfc8 commit 65eaa5f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/db/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function updateProject(proj: Project) {
throw new Error('Project not present in database');
}
const id = makeObjectId(proj.getId());
const userId = proj.getUserid();
const userId = proj.getUserId();
const project = await DbProject.findOne({ _id: id, userId: userId });

if (project) {
Expand Down Expand Up @@ -83,7 +83,7 @@ export async function loadProject(projectId: string): Promise<Project> {
*/
export async function createProject(project: Project): Promise<string> {
const dbProject = await DbProject.create({
userId: project.getUserid(),
userId: project.getUserId(),
name: project.getName(),
description: project.getDescription(),
members: project.getPersons(),
Expand Down
13 changes: 3 additions & 10 deletions src/models/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export class Project {
this.name = name;
this.description = description;
this.personArr = stringPersonArr;
// disabled for testing
// this.validateAdjMatrix(adjMatrix);
this.validateAdjMatrix(adjMatrix);
this.adjMatrix = adjMatrix;
}

Expand Down Expand Up @@ -60,7 +59,7 @@ export class Project {

public addPerson(personName: string): void {
Project.validatePerson(personName);
if (personName in this.personArr) {
if (this.personArr.indexOf(personName) !== -1) {
throw new Error('Person already exists in project.');
}
const num_members = this.personArr.length;
Expand All @@ -79,7 +78,7 @@ export class Project {
return this.id;
}

public getUserid(): number {
public getUserId(): number {
return this.userid;
}

Expand Down Expand Up @@ -127,7 +126,6 @@ export class Project {
}
public removePersons(personArr: string[]): void {
Project.validatePeople(personArr);
console.log(personArr);
let indexesToRemove: number[] = [];
for (const person of personArr) {
const index = this.personArr.indexOf(person);
Expand All @@ -136,16 +134,11 @@ export class Project {
}
indexesToRemove.push(index);
}
console.log(indexesToRemove);
// remove rows and columns from adjMatrix
indexesToRemove = indexesToRemove.toSorted();
indexesToRemove.reverse(); // so we don't have to recalculate indexes
console.log(indexesToRemove);
for (const index of indexesToRemove) {
console.log(index);
console.log(this.personArr);
this.personArr.splice(index, 1);
console.log(this.personArr);
this.adjMatrix.splice(index, 1);
}
for (let i = 0; i < this.adjMatrix.length; i++) {
Expand Down

0 comments on commit 65eaa5f

Please sign in to comment.