Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save qodirovshohijahon/36c9dde6ba3b2fa1621829d3d0c56bd8 to your computer and use it in GitHub Desktop.
Save qodirovshohijahon/36c9dde6ba3b2fa1621829d3d0c56bd8 to your computer and use it in GitHub Desktop.
export const update = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const id: string = req.params.id
const data = req.body
const topicRepo = await topicRepository()
const topic = await topicRepo.findOne({ id })
console.log("no updated topic -", topic);
if (!topic) {
return new ApiResponse(res).error(404, 'TOPIC_NOT_FOUND')
}
await topicRepo.update({id: id}, data);
const updatedTopic = await topicRepo.findOne(data)
console.log("updated topic -", updatedTopic);
new ApiResponse(res).success(updatedTopic)
} catch (e) {
console.log(e)
next(e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment