#136 adding try catch and check title on project creation

parent 6b05046c
......@@ -71,6 +71,7 @@ const loadFixtures = async () => {
user.role = userRoles[i].role;
user.generateToken()
await user.save();
// начало: создание проектов "Личные дела" и "Не определелено" новому юзеру
const newProject = new Project();
newProject.title = 'Личные дела';
newProject.color= '#f595ee';
......@@ -89,6 +90,7 @@ const loadFixtures = async () => {
notDefinedTaskProjectMember.project = notDefinedTaskProject;
notDefinedTaskProjectMember.roleProject = MemberRole.ADMIN;
await notDefinedTaskProjectMember.save();
// конец
users.push(user)
}
......
......@@ -49,9 +49,26 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> {
/**create new project */
router.post('/',auth, async (req:Request, res:Response): Promise<Response> => {
if (!req.body) return res.status(400).send({Message:'problem in incoming req.body'})
const {user, title,color}= req.body;
try{
const projectCheck = await dataSource
.getRepository(Project)
.find({
where:{
title:title
}
})
if(projectCheck.length>0) {return res.status(400).send({message:"suchc Project already exists"})}
} catch(e){
return res.status(502).send({message:(e as Error).message})
}
try{
const member:Member = new Member;
member.user= user;
member.roleProject= MemberRole.ADMIN;
......@@ -62,6 +79,10 @@ router.post('/',auth, async (req:Request, res:Response): Promise<Response> => {
project.members=[member]
await project.save()
return res.send({project})
} catch(e) {
return res.status(502).send({message:(e as Error).message})
}
})
/**get project with all FK & tasks with all FK, by project ID */
router.get("/:id",async (req:Request, res:Response): Promise<Response> => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment