How to get particular object of collection using foreign objectid
How to get json object multiple values or properties from frontend
get single question and set a variable for task created by user
how to format a date and time
How to send some parameter to appcontext by excluding using function
How to sets a minimum date allowed for the input field in datepicker
Task1
In backend
How to get particular object of collection using foreign objectid
const getSingleTask = async (req, res) => {
const { id: taskId } = req.params
if (!taskId) {
throw new BadRequestError("please provide task id")
}
const task = await Task.findOne({ _id: taskId })
const task_createdby = task.createdBy
console.log(task_createdby)
const user = await User.findById(task_createdby)
console.log(user)
if (!task) {
throw new NotFoundError("no task with this id")
}
if(task.createdBy)
{
const task_createdby = task.createdBy
const user = await User.findById(task_createdby)
res.status(200).json({ task,createdby:user.name })
}
else
{
res.status(200).json({ task })
}
}
How to get json object multiple values or properties from frontend
In app.context
const getSingleTask = async (id) => {
try {
const response = await authFetch.get(`task/${id}`)
return response.data
} catch (error) {}
}
use setter method
const [taskcreatedby, setTaskcreatedby] = useState('');
const [taskcreatedby_time, setTaskcreatedbytime] = useState('');
const [taskupdatedbytime, setTaskupdatedbytime] = useState('');
get single question and set a variable for task created by user
how to format a date and time
useEffect(() => {
if (editingTask !== null) {
getSingleTask(editingTask._id).then((data) => {
const createdBy = data.createdby;
const time = data.task.createdAt;
const updatedtime = data.task.updatedAt;
const formattedTime = moment(time).format('MMMM Do YYYY, h:mm:ss a');
const formattedupdateTime = moment(updatedtime).format('MMMM Do YYYY, h:mm:ss a');
const createdbytime = createdBy + " In " + formattedTime;
console.log("task createdBy")
setTaskcreatedby(createdBy)
setTaskcreatedbytime(createdbytime)
setTaskupdatedbytime(formattedupdateTime)
setTask(data.task)
if (data.task.goal) {
const goalTitle = goals.find((i) => i._id === data.task.goal)
// console.log(goalTitle)
if (goalTitle) {
setValues({ ...values, goalTitle: goalTitle.title })
}
}
})
}
Display the task created by and time
{taskcreatedby?(<label>Created by:{taskcreatedby_time} </label>):null}
<label>Task Updated:{taskupdatedbytime} </label>
Task2
After editing name should not updated
const { user } = useAppContext()
useEffect(() => {
setValues({
...values,
name: user.name,
userId: user._id,
userRole: user.role,
taskId: editingTask._id,
projectId: selectedProject,
profilePic: user.profileUrl,
})
}, [isWorklogModalOpen])
const handleSubmit = (e) => {
e.preventDefault()
if (isEditingWorklog) {
if (values.workDescription !== "") {
const regex = /^(\d+)(m|h|d|w)(\s(\d+)(m|h|d|w))*$/g
if (!regex.test(values.timeSpent)) {
toast.error("enter value in m h d w")
}
else
{
console.log("Values before dispatch:", values);
const { name, ...filteredValues } = values;
console.log("Values after dispatch:", filteredValues);
dispatch(
updateWorklog({
...filteredValues,
_id: editingWorklog._id,
timeSpent: getMinutes(values.timeSpent)
})
)
setValues(initialState)
dispatch(closeWorklogModal())
}
How to send some parameter to appcontext by excluding using function
console.log("Values before dispatch:", values);
const { name, ...filteredValues } = values;
console.log("Values after dispatch:", filteredValues);
dispatch(
updateWorklog({
...filteredValues,
_id: editingWorklog._id,
timeSpent: getMinutes(values.timeSpent)
})
How to sets a minimum date allowed for the input field in datepicker
==============================
**
solution**
index.js
export { raiseTicket, getAllTicket, closeTicket,getAlluserTicket } from "./ticket/ticketActions"
Top comments (0)