#69 create new personal project while create new user

parent 3d1e05fc
......@@ -19,13 +19,9 @@ import {
id: string;
title: string;
color: string;
// admin:User;
// workers:User[];
tasks:Task[]|null;
createdAt: Date;
active:boolean;
// dateDue: Date| null;
// department:boolean;
members: Member[];
}
......@@ -47,22 +43,10 @@ import {
@Column({ name: 'active',type: 'boolean', default: true })
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})
tasks!:Task[];
@OneToMany(() => Member, (member: { project: Project; })=>member.project)
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";
import bcrypt from 'bcrypt';
import {nanoid} from 'nanoid';
import {Task} from './Task';
import {Project} from './Project';
import {Member} from './Member';
const SALT_WORK_FACTOR= 10;
......
......@@ -5,6 +5,8 @@ import { nanoid } from 'nanoid';
import multer from 'multer';
import path from 'path';
import {config} from "../config"
import { Project } from '../models/Project';
import { Member, MemberRole } from '../models/Member';
const router:Router = express.Router();
const dataSource = myDataSource;
......@@ -24,7 +26,7 @@ const storage = multer.diskStorage({
const upload = multer({ storage })
//** return all users of DB */
router.get('/', async (req : Request, res : Response):Promise<object> => {
const users = await dataSource
.getRepository(User)
......@@ -33,7 +35,7 @@ const users = await dataSource
return res.send({users})
})
/**create new user*/
router.post('/', upload.single("avatar"), async (req : Request, res : Response):Promise<object> => {
const {name,surname,password,email, role} = req.body;
const displayName = surname+' '+name[0]+'.'
......@@ -44,8 +46,18 @@ router.post('/', upload.single("avatar"), async (req : Request, res : Response):
user.displayName= displayName;
user.email = email;
user.role = role;
user.generateToken()
user.generateToken();
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, {
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