'use strict';

const models = require("models"),
    HTTPStatus = require('http-status'),
    <% if (locals.useSequelize) {%>
    sequelize = require('utils/sequelize'),
    <%}%>
_ = require('lodash');

/**
 * GET /api/v1/users
 * @param req req
 * @param res res
 */

async function list(req, res) {
    <% if (locals.useMongo) {%>
    res.json({
        users: await models.User.find({})
    });
    <%}%>
    <% if (locals.useSequelize) {%>
    let users = await sequelize.transaction(async t => {
                // chain all your queries here. make sure you return them.
                return await models.User.findAll({transaction: t});
            }
        );
    res.json({
        users: users
    });
    <%}%>
}

/**
 * GET /api/v1/users/:id
 * @param req req
 * @param res res
 */

async function get(req, res) {
    <% if (locals.useMongo) {%>
    res.json({
        user: await models.User.findById(req.params.id)
    });
    <%}%>
    <% if (locals.useSequelize) {%>
    let user = await sequelize.transaction(async t => {
                // chain all your queries here. make sure you return them.
                return await models.User.find({
                    where: {
                        id : req.params.id
                    },
                    transaction: t
                });
            }
        );
    res.json({
        user: user
    });
    <%}%>
}

/**
 * POST /api/v1/users
 * @param req req
 * @param res res
 */

async function create(req, res) {
    <% if (locals.useMongo) {%>
    let newUser = await models.User.create(req.body);
    <%}%>
    <% if (locals.useSequelize) {%>
    let newUser = await sequelize.transaction(async t => {
                // chain all your queries here. make sure you return them.
                return await models.User.create(req.body, {transaction: t});
            }
        );
    <%}%>
    res.json({
        id: newUser.id
    });
}

/**
 * PUT /api/v1/users/:id
 * @param req req
 * @param res res
 */

async function update(req, res) {
    <% if (locals.useMongo) {%>
    let user = await models.User.findById(req.params.id);
    <%}%>
    <% if (locals.useSequelize) {%>
    let user = await sequelize.transaction(async t => {
                // chain all your queries here. make sure you return them.
                return await models.User.find({
                    where: {
                        id : req.params.id
                    },
                    transaction: t
                });
            }
        );
    <%}%>

    _.assign(user, req.body);

    <% if (locals.useMongo) {%>
        await user.save();
    <%}%>
    <% if (locals.useSequelize) {%>
        await sequelize.transaction(async t => {
                // chain all your queries here. make sure you return them.
                await user.save({transaction: t});
            }
        );
    <%}%>
    res.status(HTTPStatus.NO_CONTENT).send();
}

/**
 * DELETE /api/v1/users/:id
 * @param req req
 * @param res res
 */

async function remove(req, res) {
    <% if (locals.useMongo) {%>
        await models.User.findByIdAndRemove(req.params.id);
    <%}%>
    <% if (locals.useSequelize) {%>
        await sequelize.transaction(async t => {
                // chain all your queries here. make sure you return them.
                await models.User.destroy({
                    where: {
                        id: req.params.id
                    },
                    transaction: t
                });
            }
        );
    <%}%>

    res.status(HTTPStatus.NO_CONTENT).send();
}

module.exports = {
    list: list,
    get: get,
    create: create,
    update: update,
    remove: remove
};
@@ -2575,36 +2575,32 @@
 s.useMongo) %7B%25%3E%0A
-    
     await user.s
@@ -2644,36 +2644,32 @@
 eSequelize) %7B%25%3E%0A
-    
     await sequel
@@ -2689,36 +2689,32 @@
 on(async t =%3E %7B%0A
-    
             // c
@@ -2776,28 +2776,24 @@
             
-    
 await user.s
@@ -2807,36 +2807,32 @@
 ansaction: t%7D);%0A
-    
         %7D%0A      
@@ -2817,36 +2817,32 @@
  t%7D);%0A        %7D%0A
-    
     );%0A    %3C%25%7D%25%3E
@@ -3026,28 +3026,24 @@
 eMongo) %7B%25%3E%0A
-    
     await mo
@@ -3132,20 +3132,16 @@
 ze) %7B%25%3E%0A
-    
     awai
@@ -3169,36 +3169,32 @@
 on(async t =%3E %7B%0A
-    
             // c
@@ -3256,28 +3256,24 @@
             
-    
 await models
@@ -3288,20 +3288,16 @@
 stroy(%7B%0A
-    
         
@@ -3329,28 +3329,24 @@
             
-    
 id: req.para
@@ -3343,36 +3343,32 @@
 : req.params.id%0A
-    
                 
@@ -3378,36 +3378,32 @@
                 
-    
 transaction: t%0A 
@@ -3393,36 +3393,32 @@
  transaction: t%0A
-    
             %7D);%0A
@@ -3421,34 +3421,26 @@
 %7D);%0A        
-    %7D%0A    
+%7D%0A
     );%0A    %3C

reformat code