Created
July 13, 2020 18:57
-
-
Save qodirovshohijahon/36c9dde6ba3b2fa1621829d3d0c56bd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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