Commit 8aaec6f3 authored by “Yevgeniy's avatar “Yevgeniy

#23 install validator for typeorm, add validation email in User model , fix routers/project

parent 4a49a5f9
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"@types/cors": "^2.8.12", "@types/cors": "^2.8.12",
"@types/express": "^4.17.14", "@types/express": "^4.17.14",
"bcrypt": "^5.1.0", "bcrypt": "^5.1.0",
"class-validator": "^0.13.2",
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.18.2", "express": "^4.18.2",
"mongoose": "^6.7.0", "mongoose": "^6.7.0",
...@@ -2490,6 +2491,15 @@ ...@@ -2490,6 +2491,15 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/class-validator": {
"version": "0.13.2",
"resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.13.2.tgz",
"integrity": "sha512-yBUcQy07FPlGzUjoLuUfIOXzgynnQPPruyK1Ge2B74k9ROwnle1E+NxLWnUv5OLU8hA/qL5leAE9XnXq3byaBw==",
"dependencies": {
"libphonenumber-js": "^1.9.43",
"validator": "^13.7.0"
}
},
"node_modules/cli-highlight": { "node_modules/cli-highlight": {
"version": "2.1.11", "version": "2.1.11",
"resolved": "https://registry.npmjs.org/cli-highlight/-/cli-highlight-2.1.11.tgz", "resolved": "https://registry.npmjs.org/cli-highlight/-/cli-highlight-2.1.11.tgz",
...@@ -3734,6 +3744,11 @@ ...@@ -3734,6 +3744,11 @@
"node": ">= 0.8.0" "node": ">= 0.8.0"
} }
}, },
"node_modules/libphonenumber-js": {
"version": "1.10.14",
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.14.tgz",
"integrity": "sha512-McGS7GV/WjJ2KjfOGhJU1oJn29RYeo7Q+RpANRbUNMQ9gj5XArpbjurSuyYPTejFwbaUojstQ4XyWCrAzGOUXw=="
},
"node_modules/locate-path": { "node_modules/locate-path": {
"version": "6.0.0", "version": "6.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz",
...@@ -5431,6 +5446,14 @@ ...@@ -5431,6 +5446,14 @@
"integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==",
"devOptional": true "devOptional": true
}, },
"node_modules/validator": {
"version": "13.7.0",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz",
"integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw==",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/vary": { "node_modules/vary": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
...@@ -7701,6 +7724,15 @@ ...@@ -7701,6 +7724,15 @@
"resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
"integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==" "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ=="
}, },
"class-validator": {
"version": "0.13.2",
"resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.13.2.tgz",
"integrity": "sha512-yBUcQy07FPlGzUjoLuUfIOXzgynnQPPruyK1Ge2B74k9ROwnle1E+NxLWnUv5OLU8hA/qL5leAE9XnXq3byaBw==",
"requires": {
"libphonenumber-js": "^1.9.43",
"validator": "^13.7.0"
}
},
"cli-highlight": { "cli-highlight": {
"version": "2.1.11", "version": "2.1.11",
"resolved": "https://registry.npmjs.org/cli-highlight/-/cli-highlight-2.1.11.tgz", "resolved": "https://registry.npmjs.org/cli-highlight/-/cli-highlight-2.1.11.tgz",
...@@ -8647,6 +8679,11 @@ ...@@ -8647,6 +8679,11 @@
"type-check": "~0.4.0" "type-check": "~0.4.0"
} }
}, },
"libphonenumber-js": {
"version": "1.10.14",
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.14.tgz",
"integrity": "sha512-McGS7GV/WjJ2KjfOGhJU1oJn29RYeo7Q+RpANRbUNMQ9gj5XArpbjurSuyYPTejFwbaUojstQ4XyWCrAzGOUXw=="
},
"locate-path": { "locate-path": {
"version": "6.0.0", "version": "6.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz",
...@@ -9794,6 +9831,11 @@ ...@@ -9794,6 +9831,11 @@
"integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==",
"devOptional": true "devOptional": true
}, },
"validator": {
"version": "13.7.0",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz",
"integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw=="
},
"vary": { "vary": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
"@types/cors": "^2.8.12", "@types/cors": "^2.8.12",
"@types/express": "^4.17.14", "@types/express": "^4.17.14",
"bcrypt": "^5.1.0", "bcrypt": "^5.1.0",
"class-validator": "^0.13.2",
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.18.2", "express": "^4.18.2",
"mongoose": "^6.7.0", "mongoose": "^6.7.0",
......
...@@ -30,7 +30,7 @@ import { ...@@ -30,7 +30,7 @@ import {
tasks:Task[]|null; tasks:Task[]|null;
createdAt: Date; createdAt: Date;
dateDue: Date| null; dateDue: Date| null;
department:boolean| false; department:boolean;
} }
@Entity({ name: 'Project' }) @Entity({ name: 'Project' })
...@@ -52,14 +52,14 @@ import { ...@@ -52,14 +52,14 @@ import {
@CreateDateColumn({ name: 'createdAt', type: Date, default: new Date() }) @CreateDateColumn({ name: 'createdAt', type: Date, default: new Date() })
createdAt!: Date; createdAt!: Date;
@Column({ name: 'color', type: 'varchar', length:100,nullable: false }) @Column({ name: 'color', type: 'varchar', length:100,nullable: true })
color!: string color!: string
@Column({ name: 'dateDue', type: Date, default: null }) @Column({ name: 'dateDue', type: Date, default: null })
dateDue!: Date| null; dateDue!: Date| null;
@Column({ name: 'department', type: Boolean, default: false }) @Column({ name: 'department', type: Boolean,nullable:true ,default: false})
department!: boolean| false; department!: boolean | false;
@ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects) @ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects)
admin!: User; admin!: User;
......
...@@ -9,6 +9,8 @@ import { ...@@ -9,6 +9,8 @@ import {
OneToMany OneToMany
} from 'typeorm'; } from 'typeorm';
import {IsEmail
} from "class-validator";
import bcrypt from 'bcrypt'; import bcrypt from 'bcrypt';
import {nanoid} from 'nanoid'; import {nanoid} from 'nanoid';
import {Task} from './Task'; import {Task} from './Task';
...@@ -48,6 +50,7 @@ export class User extends BaseEntity implements IUser { ...@@ -48,6 +50,7 @@ export class User extends BaseEntity implements IUser {
displayName!: string displayName!: string
@Column({ name: 'email', type: 'varchar',length:20, unique: true, nullable: false }) @Column({ name: 'email', type: 'varchar',length:20, unique: true, nullable: false })
@IsEmail()
email!: string email!: string
@Column({ name: 'phone', type: 'varchar',length:10, unique: true, nullable: true}) @Column({ name: 'phone', type: 'varchar',length:10, unique: true, nullable: true})
......
import express,{Router, Request, Response} from 'express'; import express,{Router, Request, Response} from 'express';
import {Project} from '../models/Project'; import {Project} from '../models/Project';
import {myDataSource} from '../app-data-source'; import {myDataSource} from '../app-data-source';
import { User } from '../models/User';
const router:Router = express.Router(); const router:Router = express.Router();
const dataSource = myDataSource; const dataSource = myDataSource;
...@@ -21,16 +22,42 @@ router.get("/:project_id",async (req:Request, res:Response): Promise<Response> = ...@@ -21,16 +22,42 @@ router.get("/:project_id",async (req:Request, res:Response): Promise<Response> =
router.post('/', async (req:Request, res:Response): Promise<Response> => { router.post('/', 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 {title, dateDue,department, admin,workers,tasks}= req.body const {title, dateDue,color,department, userId,workers,tasks}= req.body;
const user = await dataSource
.createQueryBuilder()
.select("user")
.from(User, "user")
.where("user.id = :id", { id: userId })
.getOne()
if(!user) return res.status(404).send({Message:'user not found'})
const project : Project= new Project() const project : Project= new Project()
project.title = title; project.title = title;
project.color = color;
project.dateDue = dateDue || null; project.dateDue = dateDue || null;
project.department = department|| null; project.department = department;
project.workers = workers|| null; project.workers = workers|| null;
project.tasks = tasks || null; project.tasks = tasks || null;
project.admin = admin|| null; project.admin = user;
await project.save() await project.save()
return res.send({project}) return res.send({project})
}) })
// router.get('/:userId', async (req : Request, res : Response): Promise<Response>=>{
// const userId:string = req.params.userId
// const user = await dataSource
// .createQueryBuilder()
// .select("user")
// .from(User, "user")
// .where("user.id = :id", { id: userId })
// .getOne()
// console.log('user ', user)
// const userProjects = await dataSource
// .createQueryBuilder()
// .select('project')
// .from(Project, "project")
// .where("Project_adminId = :id", { id: userId })
// return res.send({userProjects})
// })
export default router; export default router;
...@@ -13,7 +13,6 @@ return res.send({users}) ...@@ -13,7 +13,6 @@ return res.send({users})
router.post('/', async (req : Request, res : Response):Promise<object> => { router.post('/', async (req : Request, res : Response):Promise<object> => {
console.log('req.body',req.body)
const {name,surname,password,email} = req.body; const {name,surname,password,email} = req.body;
const displayName = surname+' '+name[0]+'.' const displayName = surname+' '+name[0]+'.'
......
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