#136 adding try catch and check title on project creation

parent 6b05046c
...@@ -71,6 +71,7 @@ const loadFixtures = async () => { ...@@ -71,6 +71,7 @@ const loadFixtures = async () => {
user.role = userRoles[i].role; user.role = userRoles[i].role;
user.generateToken() user.generateToken()
await user.save(); await user.save();
// начало: создание проектов "Личные дела" и "Не определелено" новому юзеру
const newProject = new Project(); const newProject = new Project();
newProject.title = 'Личные дела'; newProject.title = 'Личные дела';
newProject.color= '#f595ee'; newProject.color= '#f595ee';
...@@ -89,6 +90,7 @@ const loadFixtures = async () => { ...@@ -89,6 +90,7 @@ const loadFixtures = async () => {
notDefinedTaskProjectMember.project = notDefinedTaskProject; notDefinedTaskProjectMember.project = notDefinedTaskProject;
notDefinedTaskProjectMember.roleProject = MemberRole.ADMIN; notDefinedTaskProjectMember.roleProject = MemberRole.ADMIN;
await notDefinedTaskProjectMember.save(); await notDefinedTaskProjectMember.save();
// конец
users.push(user) users.push(user)
} }
......
...@@ -49,19 +49,40 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> { ...@@ -49,19 +49,40 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> {
/**create new project */ /**create new project */
router.post('/',auth, async (req:Request, res:Response): Promise<Response> => { router.post('/',auth, async (req:Request, res:Response): Promise<Response> => {
if (!req.body) return res.status(400).send({Message:'problem in incoming req.body'}) if (!req.body) return res.status(400).send({Message:'problem in incoming req.body'})
const {user, title,color}= req.body; const {user, title,color}= req.body;
const member:Member = new Member; try{
member.user= user; const projectCheck = await dataSource
member.roleProject= MemberRole.ADMIN; .getRepository(Project)
await member.save(); .find({
const project : Project= new Project() where:{
project.title = title; title:title
project.color = color; }
project.members=[member] })
await project.save() if(projectCheck.length>0) {return res.status(400).send({message:"suchc Project already exists"})}
return res.send({project})
} 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;
await member.save();
const project : Project= new Project()
project.title = title;
project.color = color;
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 */ /**get project with all FK & tasks with all FK, by project ID */
router.get("/:id",async (req:Request, res:Response): Promise<Response> => { 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