2016-05-03 22:50:21 +00:00
|
|
|
// Copyright IBM Corp. 2014,2016. All Rights Reserved.
|
|
|
|
// Node module: loopback
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2016-11-15 21:46:23 +00:00
|
|
|
'use strict';
|
2014-02-19 19:44:16 +00:00
|
|
|
var loopback = require('../../');
|
|
|
|
var server = module.exports = loopback();
|
|
|
|
var CartItem = require('./models').CartItem;
|
|
|
|
var memory = loopback.createDataSource({
|
2016-04-01 09:14:26 +00:00
|
|
|
connector: loopback.Memory,
|
2014-02-19 19:44:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
server.use(loopback.rest());
|
|
|
|
server.model(CartItem);
|
|
|
|
|
|
|
|
CartItem.attachTo(memory);
|
|
|
|
|
|
|
|
// test data
|
2014-02-20 01:09:36 +00:00
|
|
|
CartItem.create([
|
2016-11-15 21:46:23 +00:00
|
|
|
{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},
|
2014-02-20 01:09:36 +00:00
|
|
|
]);
|
2014-02-19 19:44:16 +00:00
|
|
|
|
2014-02-20 01:09:36 +00:00
|
|
|
CartItem.sum(1, function(err, total) {
|
|
|
|
console.log(total);
|
|
|
|
});
|
2014-02-19 19:44:16 +00:00
|
|
|
|
|
|
|
server.listen(3000);
|