/var/www/myprog.com.ua/server/node
Edit: /var/www/myprog.com.ua/server/node/test_db.js (4838B)
console.log('begin init');
require('./helpers/date');
require('./helpers/global');
let t1 = new Date().microtime(true);
const http = require('http');
let config = require('./config.json');
const Client = require('./objects/client');
const Order = require('./objects/order');
const Car = require('./objects/car');
const ClientAdres = require('./objects/client_adres');
const ClientRoute = require('./objects/client_route');
const DbContext = require('./db/db_context');
let db = new DbContext(config);
console.log(`end init ${new Date().microtime(true) - t1} ms`);
// update_client(1);
// create_order();
// get_client(1);
// get_client_by_key("e74024ba3f5d1d670d1a51fec1e86f66");
// get_client_by_phone('+380506565772');
// get_operator_by_key("e74024ba3f5d1d670d1a51fec1e86f66");
// get_driver_by_key("e74024ba3f5d1d670d1a51fec1e86f66");
// get_clients();
// get_order(2438);
// get_orders();
// get_car(21);
// update_car(21);
// create_car();
get_b_formuls();
function update_client() {
let client = null;
db.get_client(1).then(result => {
client = result;
client.set_name('Anton...');
db.update_client(client)
.then(result => {
console.debug(result);
console.debug(client)
})
.catch(e => console.error(e));
});
//db.query(sql).then(r=>console.debug(r)).catch(e=>console.debug(e));
}
function create_order() {
let order = new Order();
let client = new Client();
client.add_phone('+380995552224');
let adres = new ClientAdres({ adres: 'Советская *тест' });
let route = new ClientRoute({ la: 48.570000, lo: 39.400000 });
order.set_client(client);
order.set_adres(adres);
order.set_route(route);
ctx_orders.update_order(order);
console.debug(order);
}
function get_client(id) {
db.get_client(id)
.then(client => {
console.debug(client);
})
.catch(e => console.error(e));
}
function get_client_by_phone(phone) {
db.get_client_by_phone(phone)
.then(client => {
console.debug(client);
})
.catch(e => console.error(e));
}
function get_client_by_key(key) {
db.get_client_by_key(key)
.then(client => {
console.debug(client);
})
.catch(e => console.error(e));
}
function get_operator_by_key(key) {
db.get_operator_by_key(key)
.then(client => {
console.debug(client);
console.debug(`is_activated ? ${client.is_activated()}`);
console.debug(`is_operator ? ${client.is_operator()}`);
})
.catch(e => console.error(e));
}
function get_driver_by_key(key) {
db.get_driver_by_key(key)
.then(client => {
console.debug(`is_activated ? ${client.is_activated()}`);
console.debug(`is_driver ? ${client.is_driver()}`);
})
.catch(e => console.error(e));
}
function update_client(id) {
db.get_client(id)
.then(client => {
client.add_phone('+380726565772');
client.del_phone('+380666565772');
console.debug(client);
return db.update_client(client);
})
.then(client => {
console.debug(client);
})
.catch(e => console.error(e))
}
function get_clients() {
console.log('begin get_clients');
db.get_clients(0, 5)
.then(clients => {
console.debug(clients);
console.log(`end get_clients ${new Date().microtime(true) - t1} s`);
})
.catch(e => {
console.error(e);
console.log(`end get_clients ${new Date().microtime(true) - t1} s`);
});
};
function get_order(id) {
db.get_order(id)
.then(order => {
console.log(order.get_array().phone);
//console.log(order.get_json());
})
.catch(e => console.debug(e));
}
function get_orders() {
db.get_orders(0, 1000, 'desc').then(orders => {
orders.forEach(order => {
console.debug(order);
})
});
}
function get_car(id) {
db.get_car(id)
.then(car => {
console.debug(car);
})
.catch(e => console.error(e));
}
function update_car(id) {
db.get_car(id)
.then(car => {
console.debug(car);
car.set_park(0);
db.update_car(car)
.then(car => console.debug(car))
.catch(e => console.error(e));
})
.catch(e => console.error(e));
}
function create_car() {
let car = new Car();
db.update_car(car)
.then(car => console.debug(car))
.catch(e => console.error(e));
}
function get_b_formuls() {
db.get_b_formuls()
.then(result => console.debug(result))
.catch(e => console.error(e));
}