Skip to content

Commit

Permalink
delete project permit to choose field name or id
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalvagno committed Dec 16, 2024
1 parent 8c797e6 commit 37edc7f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 14 deletions.
39 changes: 29 additions & 10 deletions routes/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
}

}

20 changes: 17 additions & 3 deletions services/prisma/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions services/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
Expand Down
12 changes: 11 additions & 1 deletion zooprocess.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 37edc7f

Please sign in to comment.