// Copyright IBM Corp. 2014,2019. All Rights Reserved.
// Node module: loopback
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

'use strict';
const loopback = require('../../');
const server = module.exports = loopback();
const CartItem = require('./models').CartItem;
const memory = loopback.createDataSource({
  connector: loopback.Memory,
});

server.use(loopback.rest());
server.model(CartItem);

CartItem.attachTo(memory);

// test data
CartItem.create([
  {item: 'red hat', qty: 6, price: 19.99, cartId: 1},
  {item: 'green shirt', qty: 1, price: 14.99, cartId: 1},
  {item: 'orange pants', qty: 58, price: 9.99, cartId: 1},
]);

CartItem.sum(1, function(err, total) {
  console.log(total);
});

server.listen(3000);
