mirror of
https://github.com/NinjaSurge/Project-Manager.git
synced 2026-05-01 12:29:02 -05:00
Edit functionality
This commit is contained in:
@@ -1,14 +1,8 @@
|
||||
const { v4: uuidv4, validate } = require('uuid');
|
||||
const e = require('express');
|
||||
const fs = require('fs');
|
||||
const { get } = require('http');
|
||||
|
||||
let projectsList = [];
|
||||
|
||||
console.error = (info) => {
|
||||
console.error(`\x1b[31m${info}\x1b[0m'`);
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Checks if the project directory exists
|
||||
* @author NinjaSurge
|
||||
@@ -41,9 +35,7 @@ const listProjects = (project_directory) => {
|
||||
const project = JSON.parse(data);
|
||||
projectsList.push(project);
|
||||
} catch (err) {
|
||||
emsg = `Error reading file from disk: ${err}`;
|
||||
console.error(emsg);
|
||||
throw Error(emsg);
|
||||
throw Error(`Error reading file from disk: ${err}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -77,7 +69,6 @@ const getProject = (project_directory, id) => {
|
||||
|
||||
if (!validate(id)) throw Error('Unable to validate id');
|
||||
projectsList.forEach((p) => {
|
||||
// console.log(p);
|
||||
if (p._id === id) {
|
||||
return (project = p);
|
||||
}
|
||||
@@ -85,6 +76,34 @@ const getProject = (project_directory, id) => {
|
||||
return project;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description changes project information
|
||||
* @author NinjaSurge
|
||||
* @param {*} project_directory - The directory containing all the projects
|
||||
* @param {*} id - The id of the project to change
|
||||
* @param {*} project_info - The information needed to change the project
|
||||
* @return {*}
|
||||
*/
|
||||
const editProject = (project_directory, id, project_info) => {
|
||||
// Checks for project folder
|
||||
checkFS(project_directory);
|
||||
|
||||
let project = getProject(project_directory, id);
|
||||
|
||||
// Create the folder structure and config file
|
||||
const dir = `${project_directory}/${project.name}`;
|
||||
if (!fs.existsSync(dir)) return { error: "Folder or Project Doesn't Exist" };
|
||||
try {
|
||||
fs.writeFileSync(`${dir}/.pm.json`, JSON.stringify(project_info), 'utf8');
|
||||
fs.renameSync(dir, `${project_directory}/${project_info.name}`);
|
||||
} catch (err) {
|
||||
throw Error('[pmfs]: ' + err);
|
||||
}
|
||||
project = getProject(project_directory, id);
|
||||
// Return the edited Project
|
||||
return project;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Handles the creation of a new project directory/config file
|
||||
* @author NinjaSurge
|
||||
@@ -152,7 +171,7 @@ const deleteProject = (project_directory, id) => {
|
||||
module.exports = {
|
||||
getProjects,
|
||||
getProject,
|
||||
// editProject
|
||||
editProject,
|
||||
makeProject,
|
||||
deleteProject,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user