Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Last active August 29, 2015 14:21
Show Gist options
  • Save wmakeev/417518372fd10f5d0c64 to your computer and use it in GitHub Desktop.
Save wmakeev/417518372fd10f5d0c64 to your computer and use it in GitHub Desktop.
Расширение объектной модели МойСклад
var moysklad = require('moysklad-client');
var client = moysklad.createClient();
// Создаем пустой объект отгрузки
// использовать ключевое слово new не нужно
var demand = client.Demand({
name: '10005'
});
demand.TYPE_NAME // -> moysklad.demand
// сохраняем
demand.save();
// или так
client.save(demand);
// Можем добавить метод для всех объектов указанного типа
client.CustomerOrder.methods({
totalQuantity: function () {
return this.customerOrderPosition.reduce((total, pos) => {
return total + pos.quantity;
}, 0)
}
})
// Затем получить заказ
var order = client.load('customerOrder', uuid);
// Метод totalQuantity доступен у всех заказов
var totalGoods = order.totalQuantity() // -> 15
// Нельзя использовать instanceof ..
order instanceof client.Entity // -> false
order instanceof client.CustomerOrder // -> false
// .. вместо instanceof
order.instanceOf('entity'); // -> true
order.instanceOf('customerOrder'); // -> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment