Changing the controllers

Since we now have the tests in place and failing, we can change our user and order controllers to start using MongoDB. First, let's change the user controller. The user controller content is as follows:

import { NextFunction, Request, Response } from 'express'import * as halson from 'halson'import { UserModel } from '../schemas/User'import { formatOutput } from '../utility/orderApiUtility'export let getUser = (req: Request, res: Response, next: NextFunction) => {  const username = req.params.username  UserModel.findOne({ username: username }, (err, user) => {    if (!user) {      return res.status(404).send()    }    user = user.toJSON()    user._id = user._id.toString()    user = halson(user).addLink('self', `/users/${user._id}`) return ...

Get Hands-On RESTful Web Services with TypeScript 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.