#69 create new personal project while create new user

parent 3d1e05fc
...@@ -19,13 +19,9 @@ import { ...@@ -19,13 +19,9 @@ import {
id: string; id: string;
title: string; title: string;
color: string; color: string;
// admin:User;
// workers:User[];
tasks:Task[]|null; tasks:Task[]|null;
createdAt: Date; createdAt: Date;
active:boolean; active:boolean;
// dateDue: Date| null;
// department:boolean;
members: Member[]; members: Member[];
} }
...@@ -47,22 +43,10 @@ import { ...@@ -47,22 +43,10 @@ import {
@Column({ name: 'active',type: 'boolean', default: true }) @Column({ name: 'active',type: 'boolean', default: true })
active!: boolean; active!: boolean;
// @Column({ name: 'dateDue', type: Date, default: null })
// dateDue!: Date| null;
// @Column({ name: 'department', type: Boolean,nullable:true ,default: false})
// department!: boolean;
// @ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true})
// admin!: User;
@OneToMany(() => Task, (task: { project: Project; })=>task.project,{nullable:true}) @OneToMany(() => Task, (task: { project: Project; })=>task.project,{nullable:true})
tasks!:Task[]; tasks!:Task[];
@OneToMany(() => Member, (member: { project: Project; })=>member.project) @OneToMany(() => Member, (member: { project: Project; })=>member.project)
members!:Member[]; members!:Member[];
// @ManyToMany(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true,cascade: true, onUpdate:'CASCADE',onDelete: 'CASCADE'})
// @JoinTable()
// workers!: User[];
} }
\ No newline at end of file
...@@ -16,7 +16,6 @@ import { Exclude, instanceToPlain } from "class-transformer"; ...@@ -16,7 +16,6 @@ import { Exclude, instanceToPlain } from "class-transformer";
import bcrypt from 'bcrypt'; import bcrypt from 'bcrypt';
import {nanoid} from 'nanoid'; import {nanoid} from 'nanoid';
import {Task} from './Task'; import {Task} from './Task';
import {Project} from './Project';
import {Member} from './Member'; import {Member} from './Member';
const SALT_WORK_FACTOR= 10; const SALT_WORK_FACTOR= 10;
......
...@@ -5,6 +5,8 @@ import { nanoid } from 'nanoid'; ...@@ -5,6 +5,8 @@ import { nanoid } from 'nanoid';
import multer from 'multer'; import multer from 'multer';
import path from 'path'; import path from 'path';
import {config} from "../config" import {config} from "../config"
import { Project } from '../models/Project';
import { Member, MemberRole } from '../models/Member';
const router:Router = express.Router(); const router:Router = express.Router();
const dataSource = myDataSource; const dataSource = myDataSource;
...@@ -24,7 +26,7 @@ const storage = multer.diskStorage({ ...@@ -24,7 +26,7 @@ const storage = multer.diskStorage({
const upload = multer({ storage }) const upload = multer({ storage })
//** return all users of DB */
router.get('/', async (req : Request, res : Response):Promise<object> => { router.get('/', async (req : Request, res : Response):Promise<object> => {
const users = await dataSource const users = await dataSource
.getRepository(User) .getRepository(User)
...@@ -33,7 +35,7 @@ const users = await dataSource ...@@ -33,7 +35,7 @@ const users = await dataSource
return res.send({users}) return res.send({users})
}) })
/**create new user*/
router.post('/', upload.single("avatar"), async (req : Request, res : Response):Promise<object> => { router.post('/', upload.single("avatar"), async (req : Request, res : Response):Promise<object> => {
const {name,surname,password,email, role} = req.body; const {name,surname,password,email, role} = req.body;
const displayName = surname+' '+name[0]+'.' const displayName = surname+' '+name[0]+'.'
...@@ -44,8 +46,18 @@ router.post('/', upload.single("avatar"), async (req : Request, res : Response): ...@@ -44,8 +46,18 @@ router.post('/', upload.single("avatar"), async (req : Request, res : Response):
user.displayName= displayName; user.displayName= displayName;
user.email = email; user.email = email;
user.role = role; user.role = role;
user.generateToken() user.generateToken();
await user.save(); await user.save();
const newProject = new Project();
newProject.title = 'Личные дела';
newProject.color= 'Green';
await newProject.save()
const newMember = new Member();
newMember.user = user;
newMember.project = newProject;
newMember.roleProject = MemberRole.ADMIN;
await newMember.save();
const userToFront:User|null = await dataSource.manager.findOneBy(User, { const userToFront:User|null = await dataSource.manager.findOneBy(User, {
email: user.email email: user.email
}) })
......
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