diff --git a/routes/projects.js b/routes/projects.js index 27b6061..594ceeb 100644 --- a/routes/projects.js +++ b/routes/projects.js @@ -95,17 +95,36 @@ module.exports = { delete: async (req,res) => { console.log("Projects::delete"); - console.log("id: ", req.params.projectId); - return projects.deleteid(req.params.projectId) - .then(project => { - return res.status(200).json({message:"Project " + string(req.params.projectId) + " deleted"}) - }) - .catch(async(e) =>{ - console.error("Error:",e ); - return res.status - }) - }, + const type = req.query.by || "name" + switch ( type ) { + case "name": + console.log("name: ", req.params.projectId); + return projects.deletename(req.params.projectId) + .then(project => { + return res.status(200).json({message:"Project " + string(req.params.projectId) + " deleted"}) + }) + .catch(async(e) =>{ + console.error("Error:",e ); + return res.status(500).json({error:e}); + }) + break; + case "id": + console.log("id: ", req.params.projectId); + return projects.deleteid(req.params.projectId) + .then(project => { + return res.status(200).json({message:"Project " + string(req.params.projectId) + " deleted"}) + }) + .catch(async(e) =>{ + console.error("Error:",e ); + return res.status(500).json({error:e}); + }) + break; + default: + // return projects.deleteByName(req.params.projectId) + return res.status(500).json({error:"unknown field" + type}); + } + } } diff --git a/services/prisma/projects.js b/services/prisma/projects.js index 665c753..58ee10c 100644 --- a/services/prisma/projects.js +++ b/services/prisma/projects.js @@ -346,19 +346,33 @@ module.exports.Projects = class { async deleteid(id){ - const project = await this.prisma.project.delete({ + console.debug("Project::deleteid: ", id) + //const project = + await this.prisma.project.delete({ where:{ id:id } }) - return project + + // return project + console.log( "" + id + "deleted") + return {} + } + + async deletename(name){ + await this.prisma.project.delete({ + where:{ + name:id + } + }) } async delete({params}){ console.log("projects:delete:",params); const {id} = params; - return this.deleteid(+id) + // return this.deleteid(+id) + return this.deletename(string(id)) .then(res => { console.log("rrrr",res); // this.prisma.$disconnect() diff --git a/services/projects.js b/services/projects.js index f214b3d..5dd0639 100644 --- a/services/projects.js +++ b/services/projects.js @@ -291,6 +291,11 @@ module.exports.Projects = class { return this.projects.deleteid(id) } + async deletename(id){ + console.debug("Project deleteid: ", id) + return this.projects.deletename(id) + } + async delete({params}){ return this.projects.delete({params}) } diff --git a/zooprocess.openapi.yaml b/zooprocess.openapi.yaml index 8601deb..fb96ecf 100644 --- a/zooprocess.openapi.yaml +++ b/zooprocess.openapi.yaml @@ -119,7 +119,7 @@ paths: parameters: - name: projectId in: path - description: The project id + description: The project name or the project id example: "42" explode: false required: true @@ -166,6 +166,16 @@ paths: - BearerAuth: [ ] delete: + parameters: + - name: by + in: query + description: use field to choose which method to delete (id or name(default)) + required: false + schema: + type: string + # default: false + nullable: true + allowEmptyValue: true description: Delete the project operationId: Projects.delete