#74 added displayname request router for Timur

parent 4ea6a7bb
...@@ -7,6 +7,7 @@ import path from 'path'; ...@@ -7,6 +7,7 @@ import path from 'path';
import {config} from "../config" import {config} from "../config"
import { Project } from '../models/Project'; import { Project } from '../models/Project';
import { Member, MemberRole } from '../models/Member'; import { Member, MemberRole } from '../models/Member';
import { auth } from '../helpers';
const router:Router = express.Router(); const router:Router = express.Router();
const dataSource = myDataSource; const dataSource = myDataSource;
...@@ -48,8 +49,24 @@ router.get('/all-fields/', async (req : Request, res : Response):Promise<object> ...@@ -48,8 +49,24 @@ router.get('/all-fields/', async (req : Request, res : Response):Promise<object>
}, },
} }
}) })
console.log('all fields users ', users)
return res.send({users}) return res.send({users})
}) })
//** return displayName of user, requested by userId */
router.get('/display-name/:userId',auth, async (req : Request, res : Response):Promise<object> => {
const {userId} =req.params
const displayName = await dataSource
.createQueryBuilder()
.select(['user.displayName'])
.from(User, "user")
.where("user.id = :userId", { userId })
.getOne()
if (!displayName) return res.status(404).send({message:'displayName not found'})
return res.send({displayName})
})
/**create new user*/ /**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> => {
......
...@@ -52,7 +52,7 @@ const MemberForm = ({ onSubmit, members }) => { ...@@ -52,7 +52,7 @@ const MemberForm = ({ onSubmit, members }) => {
useEffect(() => { useEffect(() => {
dispatch(fetchProject(params.id)) dispatch(fetchProject(params.id))
}, [members, dispatch, params]); }, [ params]);
// console.log(user) // console.log(user)
// const onChange = (e) => { // const onChange = (e) => {
// const value = e.target.value; // const value = e.target.value;
......
...@@ -13,12 +13,13 @@ const SwitchUserForm=({submitFormHandler, users})=> { ...@@ -13,12 +13,13 @@ const SwitchUserForm=({submitFormHandler, users})=> {
setCurrentUser(user) setCurrentUser(user)
setProjectsRole([]) setProjectsRole([])
} }
console.log('projectsRoles ', projectsRoles)
useEffect(()=>{ useEffect(()=>{
if(currentUser?.members.length>0) { if(currentUser?.members.length>0) {
for (let member of currentUser.members ) { for (let member of currentUser.members ) {
const newProjectRole = { let newProjectRole = {
"projectName":member.project.title, "projectName":member.project.title,
"roleName":member.roleProject "roleName":member.roleProject
} }
......
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