Skip to content

Commit

Permalink
Fixed search issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ov1n committed Sep 22, 2021
1 parent a4629fa commit 38b1e68
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ exports.create = (req, res) => {

// Retrieve all Employees from the database.
exports.findAll = (req, res) => {
//const id = req.query.id;
//var condition = title ? { title: { [Op.like]: `%${title}%` } } : null;
const name = req.query.name;
var condition = name ? { name: { [Op.like]: `%${name}%` } } : null;

Employee.findAll()
Employee.findAll( {where: condition})
.then(data => {
res.send(data);
})
Expand Down Expand Up @@ -199,5 +199,4 @@ exports.deleteAll = (req, res) => {
});
});
};
///////////////////////////////////
// Improve for pagination as well
///////////////////////////////////
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,25 @@ exports.searchUser = (req,res)=>{
err.message || "Some error occurred while retrieving projects."
});
});
};

exports.addProjectRole = (req,res)=>{

const userId= req.body.userId;
const roleId= req.body.roleId;

//'insert into projectuserp.position, u.username FROM p, users u where p.userId = u.id AND p.projectId = '+id+' AND p.position = "'+position+'";',
const queryy="INSERT into user_roles(createdAt,updatedAt,roleId,userId) VALUES('2021-09-23 12:06:10','2021-09-23 12:06:10',"+roleId+","+userId+")"
console.log(queryy);
db.sequelize.query(queryy,
{ type: db.sequelize.QueryTypes.INSERT})
.then(data => {
res.send(data);
})
.catch(err => {
res.status(500).send({
message:
err.message || "Some error occurred while inserting project user."
});
});
};
3 changes: 3 additions & 0 deletions edifice-backend/node-backend/app/routes/projectuser.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ module.exports = app => {

// Update a Tutorial with id
router.put("/:id", projectuser.update);

// Insert a Role with id
router.post("/role/", projectuser.addProjectRole);

// Delete a Tutorial with id
router.delete("/:id/", projectuser.delete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,25 @@ class Employee extends Component {
constructor(props) {
super(props);
this.getEmployees = this.getEmployees.bind(this);
this.onChangeSearchName = this.onChangeSearchName.bind(this);
this.searchEmpName = this.searchEmpName.bind(this);
this.refreshList = this.refreshList.bind(this);
console.log(this.getEmployee);
this.state = {
currentEmployee: {
employees: [],
currentEmployee: null,
currentId: -1,
searchName: ""

},
message: "",
temp: this.props.match.params.id
temp: this.props.match.params.id,
searchName: ""
};
}

componentDidMount() {
this.getEmployees(this.props.match.params.id);
this.getEmployees();
}

onChangeSearchName(e) {
Expand All @@ -77,12 +80,14 @@ class Employee extends Component {
this.setState({
searchName: searchName
});

console.log(this.state.searchName)
}

refreshList() {
this.getEmployees();
this.setState({
currentEmployeet: null,
currentEmployee: null,
currentIndex: -1,
searchName: ""
});
Expand All @@ -101,8 +106,17 @@ class Employee extends Component {
});
}

searchName() {
//console.log("meka hadala daamu")
searchEmpName() {
EmployeeDataService.findByName(this.state.searchName)
.then(response => {
this.setState({
employees: response.data
});
console.log(response.data);
})
.catch(e => {
console.log(e);
});
}

render() {
Expand Down Expand Up @@ -146,11 +160,13 @@ class Employee extends Component {

<form className="row g-3 mt-2">
<div className="col-auto">
<input className="form-control" type="text" placeholder="Search employee"/>
<input className="form-control" type="text"
onChange={this.onChangeSearchName}
placeholder="Search employee"/>
</div>

<div className="col-auto">
<a href="" className="btn btn-success"><Search/> </a>
<a onClick={this.searchEmpName} className="btn btn-success"><Search/> </a>
</div>

<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ class Subcontractors extends Component {
</div>

<div className="col-auto">
<a href="" className="btn btn-success"><Search/></a>
<a href="" className="btn btn-success mr-2"><Search/></a>
</div>

<div>
<Link to="/addSub"><a className="btn btn-primary"> + Add Sub-contractor</a></Link>
<Link to="/addSub"><a className="btn btn-primary ml-5"> + Add Sub-contractor</a></Link>
</div>
</form>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Vendors extends Component {
</div> */}

<div>
<Link to="/addVendor"> <a className="ml-5 btn btn-primary"> + Add vendor</a></Link>
<Link to="/addVendor"> <a className="ml-5 btn btn-primary"> + Add Vendor</a></Link>
</div>
</form>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import cogoToast from 'cogo-toast';
import emailjs from 'emailjs-com';

import EmployeeDataService from "../services/employee.service";
import ProjectUserDataService from "../services/projectuser.service";
import DesignationDataService from "../services/designation.service";
import AuthService from "../services/auth.service";

Expand Down Expand Up @@ -59,6 +60,7 @@ export default class Register extends Component {
super(props);
this.handleRegister = this.handleRegister.bind(this);
this.onChangeUsername = this.onChangeUsername.bind(this);
this.onChangePrivilege = this.onChangePrivilege.bind(this);
// this.onChangeEmail = this.onChangeEmail.bind(this);
this.onChangePassword = this.onChangePassword.bind(this);
//this.addToRoles=this.addToRoles.bind(this);
Expand All @@ -69,6 +71,7 @@ export default class Register extends Component {
empname: "",
email: "",
password: "",
privilege: "1",
successful: false,
message: "",
rolesSelected: [],
Expand All @@ -86,11 +89,12 @@ export default class Register extends Component {
});
}

// onChangeEmail(e) {
// this.setState({
// email: e.target.value
// });
// }
onChangePrivilege(e) {
this.setState({
privilege: e.target.value
});
console.log(this.state.privilege);
}

onChangePassword(e) {
this.setState({
Expand Down Expand Up @@ -203,6 +207,20 @@ export default class Register extends Component {

//cogoToast.success("Account successfully made for"+this.state.username);
}
var data1={
userId: this.state.id,
roleId: this.state.privilege
}

ProjectUserDataService.addProjectRole(data1)
.then(response => {
console.log(response.data);
})
.catch(e => {
console.log(e);
});

window.location.href ="/employees"
}

}
Expand Down Expand Up @@ -378,22 +396,33 @@ export default class Register extends Component {
{/* row end down*/}
</div>
<div className="col-6">
<h3 className="pd-3">Select Roles </h3>
<p>Allocate roles for employee </p>
<h3 className="pd-3">Select Eligible positions </h3>
<p>Allocate positions for employee </p>
<div className="row">
{roles.map((value,index) => {
return(

<div className="pr-2">
<Chip
className="py-1"
className="py-1 mb-2 ml-2"
label={value.name}
onClick={() =>this.addToRoles(index)}
clickable={true} color={this.state.rolesSelected[index]} />
</div>
)
})}
</div>
<h3 className="mt-4 pd-3">Select Roles for User </h3>
<p>Allocate Roles for user: </p>
<select className="form-control" name="" id="privilege"
required
value={this.state.privilege}
onChange={this.onChangePrivilege}
name="privilege 1" required>
<option onChange={this.onChangePrivilege} value="1" >User</option>
<option onChange={this.onChangePrivilege} value="2">Moderator</option>
<option onChange={this.onChangePrivilege} value="3">Administrator</option>
</select><br />
</div>
<div className="form-group">
<button className="btn btn-primary btn-block" onClick={() =>this.handleRegister()} disabled={this.state.signupDisabled}>Sign Up</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ class Report extends Component {

//WORKING EMPLOYEES
//LOCATION
doc.setFontSize(16);
doc.setFont("times","normal");
doc.text(" No. of Employees :",10, 114, null, null, "left");
// doc.setFontSize(16);
// doc.setFont("times","normal");
// doc.text(" No. of Employees :",10, 114, null, null, "left");

doc.setFont("times", "bold");
doc.text(noUsers,59, 114, null, null, "left");
// doc.setFont("times", "bold");
// doc.text(noUsers,59, 114, null, null, "left");

//final save
//TABLE OF WORKING EMPLOYEES
Expand All @@ -143,7 +143,7 @@ class Report extends Component {

const headers=["empID","name","role","enrollDate","mobileNo"];

doc.table(12, 117, tempdata, headers,{ fontSize: 10 },{ autoSize: true });
//doc.table(12, 117, tempdata, headers,{ fontSize: 10 },{ autoSize: true });

var saveName1="Status_report_"+project.title+"_"+this.state.currentDate+".pdf";
doc.save(saveName1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class EmployeeDataService {
return http.get(`/employee/app/last`);
}

findByName(name) {
return http.get(`/employee?name=${name}`);
}

}

export default new EmployeeDataService();
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class ProjectUserDataService {
create(data) {
return http.post("/projects/user", data);
}

addProjectRole(data){
return http.post("/projects/user/role/", data);
}

getAll(id) {
return http.get(`/projects/user/list/${id}`);
Expand Down

0 comments on commit 38b1e68

Please sign in to comment.