Commit 6a0bcd24 authored by “Yevgeniy's avatar “Yevgeniy

#32 fix role

parent 9171ead8
......@@ -30,16 +30,19 @@ import {
export class Task extends BaseEntity implements ITask{
@PrimaryGeneratedColumn('uuid')
id!: string
@Column({ name: 'dateTimeStart', type: Date,nullable: true })
dateTimeStart!: Date | null;
@Column({ name: 'dateTimeDue', type: Date,nullable: true })
dateTimeDue!: Date | null;
@Column({ name: 'title', type: 'varchar', length:50,nullable: false })
title!: string
@Column({ name: 'description', type: 'varchar', length:50,nullable: true })
description!: string
@CreateDateColumn({ name: 'created_at', type: Date, default: new Date() })
createdAt!: Date;
@Column({ name: 'dateTimeStart', type: 'varchar',nullable: true })
dateTimeStart!: Date | null;
@Column({ name: 'dateTimeDue', type: 'varchar',nullable: true })
dateTimeDue!: Date | null;
@Column({
type: "enum",
enum: ["opened", "done" , "failed"],
......
......@@ -20,17 +20,17 @@ import {Project} from './Project';
const SALT_WORK_FACTOR= 10;
type userRoleType = ["user" , "director","superuser"];
export enum UserRole {USER="user" ,DIRECTOR= "director",SUPERUSER="superuser"}
interface IUser {
id:string;
role: UserRole;
name: string;
surname: string;
email: string;
displayName: string;
password:string;
token: string;
role: userRoleType;
createdAt: Date;
createdTasks:Task[];
workerInProjects:Project[];
......@@ -67,10 +67,10 @@ export class User extends BaseEntity implements IUser {
@Column({
type: "enum",
enum: ["user", "director","superuser"],
default: "user"
enum: UserRole,
default: UserRole.SUPERUSER
})
role!: userRoleType
role!: UserRole
@Column({ type: 'varchar', nullable: false, select:true })
@Exclude({ toPlainOnly: true })
......
......@@ -17,7 +17,7 @@ export default router;
router.post('/', async(req:Request, res:Response):Promise<Response>=>{
const token = req.get('Authorization');
const newTask = new Task();
const {title,description,project,executors,dateTimeDue,dateTimeStart} = req.body;
const {title,description,project,executors,dateTimeDue,dateTimeStart,accomplish} = req.body;
const user = await dataSource
.createQueryBuilder()
.select("user")
......@@ -32,6 +32,7 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
newTask.dateTimeDue = dateTimeDue;
newTask.dateTimeStart = dateTimeStart;
newTask.author= user;
newTask.accomplish = accomplish;
await newTask.save();
return res.send({newTask})
})
......
......@@ -17,7 +17,7 @@ return res.send({users})
router.post('/', async (req : Request, res : Response):Promise<object> => {
const {name,surname,password,email} = req.body;
const {name,surname,password,email, role} = req.body;
const displayName = surname+' '+name[0]+'.'
const user = new User();
user.name = name;
......@@ -25,6 +25,7 @@ router.post('/', async (req : Request, res : Response):Promise<object> => {
user.password = password;
user.displayName= displayName;
user.email = email;
user.role = role;
user.generateToken()
await user.save();
const userToFront:User|null = await dataSource.manager.findOneBy(User, {
......
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