Tasks: presave active task, able to edit on button action
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { Request, Response } from 'express'
|
||||
import Task from '../models/Task'
|
||||
import { Err, Succ } from '../services/globalService'
|
||||
|
||||
export async function get(req: Request, res: Response) {
|
||||
try {
|
||||
@ -20,3 +21,25 @@ export async function add(req: Request, res: Response) {
|
||||
res.status(500).send(error)
|
||||
}
|
||||
}
|
||||
|
||||
export async function edit(req: Request, res: Response) {
|
||||
try {
|
||||
const payload = req.body
|
||||
payload.author_id = res.locals.user._id
|
||||
const task: any = await Task.findByPk(payload._id)
|
||||
|
||||
if (!task) {
|
||||
return res.status(400).json(new Err(400, 'Task not found'))
|
||||
}
|
||||
|
||||
task.title = payload.title
|
||||
task.timeEnd = payload.timeEnd
|
||||
task.timeStart = payload.timeStart
|
||||
|
||||
await task.save()
|
||||
|
||||
return res.json(new Succ(200, 'Task updated succesfully'))
|
||||
} catch (error) {
|
||||
return res.status(500).json(new Err(400, 'something went wrong', error))
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ export const router = Router()
|
||||
|
||||
router.get('/task/get', requireAuth, taskController.get)
|
||||
router.post('/task/add', requireAuth, taskController.add)
|
||||
router.post('/task/edit', requireAuth, taskController.edit)
|
||||
|
||||
router.post('/auth/signup', userController.signup)
|
||||
router.post('/auth/signin', userController.signin)
|
||||
|
Reference in New Issue
Block a user