Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `use strict`
- var server = require('diet')
- var mysql = require('mysql')
- var connection = mysql.createConnection({
- host: 'localhost',
- user: 'root',
- password: 'pass'
- });
- var app = server()
- app.listen('95.213.203.209:5683/')
- //clients
- app.get('/clients.get', function($) {
- connection.query("SELECT * FROM `get`.`clients` WHERE 1", function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/clients.getarr', function($) {
- connection.query("SELECT * FROM `get`.`clients` WHERE 1", function(err, rows, fields) {
- var arr = rows.map(function(row) {
- return [row.name + "," + row.email + "," + row.type + "," + row.added]
- })
- $.end(arr)
- })
- })
- app.get('/clients.getsum', function($) {
- connection.query("SELECT * FROM `get`.`clients` WHERE 1", function(err, rows, fields) {
- $.json({
- "rows": [{
- 'clients': rows.length
- }]
- })
- })
- })
- app.get('/client.getbyid', function($) {
- connection.query("SELECT * FROM `get`.`clients` WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/clients.getbyid', function($) {
- connection.query("SELECT * FROM `get`.`clients` WHERE `manager_id` =" + connection.escape($.query.id), function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/clients.new', function($) {
- connection.query("INSERT INTO `get`.`clients`(`name`, `email`, `phone`, `manager_id`, `type`, `added`) VALUES (" + connection.escape($.query.name) + "," + connection.escape($.query.email) + "," + connection.escape($.query.phone) + "," + connection.escape($.query.manager_id) + "," + connection.escape($.query.type) + ", CURRENT_DATE())", function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- app.get('/clients.delete', function($) {
- connection.query("DELETE FROM `get`.`clients` WHERE `id` =" + connection.escape($.query.id), function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- //comments
- app.get('/comment.add', function($) {
- connection.query("INSERT INTO `get`.`comments`(`task_id`, `user_id`, `comment`, `date`) VALUES (" + connection.escape($.query.task_id) + "," + connection.escape($.query.user_id) + "," + connection.escape($.query.comment) + ", NOW())", function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- app.get('/comments.get', function($) {
- connection.query("SELECT * FROM `get`.`comments` WHERE `task_id` =" + connection.escape($.query.id) + " ORDER BY `comments`.`id` DESC", function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/comments.getbyuser', function($) {
- connection.query("SELECT * FROM `get`.`tasks` WHERE `manager_id` =" + connection.escape($.query.id), function(err, rows, fields) {
- var tasks = rows.map(function(row) {
- return row.id
- })
- connection.query("SELECT * FROM `get`.`comments` WHERE `task_id` IN ("+tasks+") ORDER BY `comments`.`id` DESC", function(err, rows, fields) {
- if(!err) {
- $.json({
- rows
- })
- } else {
- $.end(err)
- }
- })
- })
- })
- //developers
- app.get('/developers.get', function($) {
- connection.query("SELECT * FROM `get`.`tbl_users` WHERE `group` = 'developer'", function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- //history
- app.get('/history.get', function($) {
- connection.query("SELECT * FROM `get`.`history` WHERE `task_id` =" + connection.escape($.query.id), function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/history.getbyuser', function($) {
- connection.query("SELECT * FROM `get`.`tasks` WHERE `manager_id` =" + connection.escape($.query.id), function(err, rows, fields) {
- var tasks = rows.map(function(row) {
- return row.id
- })
- connection.query("SELECT * FROM `get`.`history` WHERE `task_id` IN ("+tasks+") ORDER BY `history`.`id` DESC", function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- })
- //price
- app.get('/price.get', function($) {
- connection.query("SELECT * FROM `get`.`price_head` WHERE 1", function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/price.getbyid', function($) {
- connection.query("SELECT * FROM `get`.`price_head` WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/price.delete', function($) {
- connection.query("DELETE FROM `get`.`price_head` WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- app.get('/price.update', function($) {
- connection.query("UPDATE `get`.`price_head` SET `name`=" + connection.escape($.query.name) + ",`cost`=" + connection.escape($.query.cost) + " WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- app.get('/price.add', function($) {
- connection.query("INSERT INTO `get`.`price_head`(`name`, `cost`) VALUES (" + connection.escape($.query.name) + "," + connection.escape($.query.cost) + ")", function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- //statuses
- app.get('/status.get', function($) {
- connection.query("SELECT * FROM `get`.`statuses` WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/statuses', function($) {
- connection.query("SELECT * FROM `get`.`statuses` WHERE 1", function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/status.update', function($) {
- connection.query("UPDATE `get`.`tasks` SET `status`=" + connection.escape($.query.status) + " WHERE `id`=" + connection.escape($.query.task_id), function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- connection.query("INSERT INTO `get`.`history`(`task_id`, `user_id`, `info`, `date`) VALUES (" + connection.escape($.query.task_id) + "," + connection.escape($.query.user_id) + "," + connection.escape($.query.info) + ", NOW())", function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- //subprice
- app.get('/subprice.delete', function($) {
- connection.query("DELETE FROM `get`.`price_sub` WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- app.get('/subprice.update', function($) {
- connection.query("UPDATE `get`.`price_sub` SET `name`=" + connection.escape($.query.name) + ",`cost`=" + connection.escape($.query.cost) + " WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- app.get('/subprice.add', function($) {
- connection.query("INSERT INTO `get`.`price_sub`(`name`, `cost`) VALUES (" + connection.escape($.query.name) + "," + connection.escape($.query.cost) + ")", function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- app.get('/subprice.get', function($) {
- connection.query("SELECT * FROM `get`.`price_sub` WHERE 1", function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/sub.get', function($) {
- connection.query("SELECT * FROM `get`.`price_sub` WHERE `id`in (" + $.query.id + ")", function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- //tasks
- app.get('/tasks.get', function($) {
- connection.query("SELECT * FROM `get`.`tasks` WHERE 1", function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/tasks.getbyid', function($) {
- connection.query("SELECT * FROM `get`.`tasks` WHERE `manager_id`=" + connection.escape($.query.id), function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/tasks.getbyclient', function($) {
- connection.query("SELECT * FROM `get`.`tasks` WHERE `client_id`=" + connection.escape($.query.id), function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/tasks.oneid', function($) {
- connection.query("SELECT * FROM `get`.`tasks` WHERE `id`=" + connection.escape($.query.id), function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/tasks.getsumbyid', function($) {
- connection.query("SELECT * FROM `get`.`tasks` WHERE `manager_id` =" + connection.escape($.query.id), function(err, rows, fields) {
- var not_payed = rows.map(function(row) {
- if (row.status == '1') {
- return row.status
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var payed = rows.map(function(row) {
- if (row.status == '2') {
- return row.status
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var in_development = rows.map(function(row) {
- if (row.status == '3') {
- return row.status
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var done = rows.map(function(row) {
- if (row.status == '4') {
- return row.status
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var ended = rows.map(function(row) {
- if (row.status == '5') {
- return row.status
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var re_edit = rows.map(function(row) {
- if (row.status == '6') {
- return row.status
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var actual_inc = rows.map(function(row) {
- if (row.status == '5') {
- return row.sum
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var actual_income = 0;
- for (var i = 0; i < actual_inc.length; i++) {
- actual_income = actual_income + parseInt(actual_inc[i]);
- }
- var real_inc = rows.map(function(row) {
- if (row.status == '5') {
- return row.salesum
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var real_income = 0;
- for (var i = 0; i < real_inc.length; i++) {
- real_income = real_income + parseInt(real_inc[i]);
- }
- var perspective_act = rows.map(function(row) {
- if (row.status == '1' || row.status == '2' || row.status == '3' || row.status == '4' || row.status == '6') {
- return row.sum
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var perspective_actual = 0;
- for (var i = 0; i < perspective_act.length; i++) {
- perspective_actual = perspective_actual + parseInt(perspective_act[i]);
- }
- var perspective_rea = rows.map(function(row) {
- if (row.status == '1' || row.status == '2' || row.status == '3' || row.status == '4' || row.status == '6') {
- return row.salesum
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var perspective_real = 0;
- for (var i = 0; i < perspective_rea.length; i++) {
- perspective_real = perspective_real + parseInt(perspective_rea[i]);
- }
- var manager_salary = real_income * 0.2
- var developer_salary = actual_income * 0.05
- $.json({
- "rows": [{
- 'tasks': rows.length,
- 'not_payed': not_payed.length,
- 'payed': payed.length,
- 'in_development': in_development.length,
- 'done': done.length,
- 'ended': ended.length,
- 're_edit': re_edit.length,
- 'actual_income': actual_income,
- 'real_income': real_income,
- 'perspective_actual': perspective_actual,
- 'perspective_real': perspective_real,
- 'manager_salary': manager_salary,
- 'developer_salry': developer_salary
- }]
- })
- })
- })
- app.get('/tasks.getsum', function($) {
- connection.query("SELECT * FROM `get`.`tasks` WHERE 1", function(err, rows, fields) {
- var not_payed = rows.map(function(row) {
- if (row.status == '1') {
- return row.status
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var payed = rows.map(function(row) {
- if (row.status == '2') {
- return row.status
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var in_development = rows.map(function(row) {
- if (row.status == '3') {
- return row.status
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var done = rows.map(function(row) {
- if (row.status == '4') {
- return row.status
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var ended = rows.map(function(row) {
- if (row.status == '5') {
- return row.status
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var re_edit = rows.map(function(row) {
- if (row.status == '6') {
- return row.status
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var actual_inc = rows.map(function(row) {
- if (row.status == '5') {
- return row.sum
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var actual_income = 0;
- for (var i = 0; i < actual_inc.length; i++) {
- actual_income = actual_income + parseInt(actual_inc[i]);
- }
- var real_inc = rows.map(function(row) {
- if (row.status == '5') {
- return row.salesum
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var real_income = 0;
- for (var i = 0; i < real_inc.length; i++) {
- real_income = real_income + parseInt(real_inc[i]);
- }
- var perspective_act = rows.map(function(row) {
- if (row.status == '1' || row.status == '2' || row.status == '3' || row.status == '4' || row.status == '6') {
- return row.sum
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var perspective_actual = 0;
- for (var i = 0; i < perspective_act.length; i++) {
- perspective_actual = perspective_actual + parseInt(perspective_act[i]);
- }
- var perspective_rea = rows.map(function(row) {
- if (row.status == '1' || row.status == '2' || row.status == '3' || row.status == '4' || row.status == '6') {
- return row.salesum
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var perspective_real = 0;
- for (var i = 0; i < perspective_rea.length; i++) {
- perspective_real = perspective_real + parseInt(perspective_rea[i]);
- }
- var manager_salary = real_income * 0.2
- var developer_salary = actual_income * 0.05
- $.json({
- "rows": [{
- 'tasks': rows.length,
- 'not_payed': not_payed.length,
- 'payed': payed.length,
- 'in_development': in_development.length,
- 'done': done.length,
- 'ended': ended.length,
- 're_edit': re_edit.length,
- 'actual_income': actual_income,
- 'real_income': real_income,
- 'perspective_actual': perspective_actual,
- 'perspective_real': perspective_real,
- 'manager_salary': manager_salary,
- 'developer_salry': developer_salary
- }]
- })
- })
- })
- app.get('/task.new', function($) {
- connection.query("INSERT INTO `get`.`tasks`(`name`, `about`, `manager_id`, `client_id`, `developer_id`, `category`, `sub`, `status`, `sum`, `salesum`, `date`) VALUES (" + connection.escape($.query.name) + ", " + connection.escape($.query.about) + ", " + connection.escape($.query.man_id) + ", " + connection.escape($.query.client_id) + ", " + connection.escape($.query.dev_id) + ", " + connection.escape($.query.cat) + ", " + connection.escape($.query.dops) + ", " + connection.escape($.query.status) + ", " + connection.escape($.query.pay_price) + ", " + connection.escape($.query.sale_sum) + ", CURRENT_DATE())", function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err + "<br>" + rows)
- }
- })
- })
- //users
- app.get('/user.add', function($) {
- connection.query("INSERT INTO `get`.`tbl_users`(`userName`, `userEmail`, `userPass`, `userStatus`, `group`, `tokenCode`) VALUES (" + connection.escape($.query.name) + "," + connection.escape($.query.mail) + "," + connection.escape($.query.pass) + ", 'Y', " + connection.escape($.query.group) + "," + connection.escape($.query.token) + ")", function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- app.get('/users.get', function($) {
- connection.query("SELECT * FROM `get`.`tbl_users` WHERE `userStatus` = 'Y'", function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/users.getbyid', function($) {
- connection.query("SELECT * FROM `get`.`tbl_users` WHERE `userID` =" + connection.escape($.query.id), function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/users.getsum', function($) {
- connection.query("SELECT * FROM `get`.`tbl_users` WHERE 1", function(err, rows, fields) {
- var developers = rows.map(function(row) {
- if (row.group == 'developer') {
- return row.group
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var managers = rows.map(function(row) {
- if (row.group == 'manager') {
- return row.group
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- var admins = rows.map(function(row) {
- if (row.group == 'admin') {
- return row.group
- }
- }).filter(function(x) {
- return typeof x !== 'undefined';
- })
- $.json({
- "rows": [{
- 'users': rows.length,
- 'developers': developers.length,
- 'managerts': managers.length,
- 'admins': admins.length
- }]
- })
- })
- })
- app.get('/users.getin', function($) {
- connection.query("SELECT * FROM `get`.`tbl_users` WHERE `userStatus` = 'N'", function(err, rows, fields) {
- $.json({
- rows
- })
- })
- })
- app.get('/user.update', function($) {
- connection.query("UPDATE `get`.`tbl_users` SET `userName`=" + connection.escape($.query.name) + ",`userEmail`=" + connection.escape($.query.email) + ",`group`=" + connection.escape($.query.group) + " WHERE `userID`=" + connection.escape($.query.id), function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- app.get('/user.inactive', function($) {
- connection.query("UPDATE `get`.`tbl_users` SET `userStatus`= 'N' WHERE `userID`=" + connection.escape($.query.id), function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- app.get('/user.active', function($) {
- connection.query("UPDATE `get`.`tbl_users` SET `userStatus`= 'Y' WHERE `userID`=" + connection.escape($.query.id), function(err, rows, fields) {
- if (!err) {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end('Success')
- } else {
- $.header('Access-Control-Allow-Origin', 'http://get.tepolis.ru')
- $.end(err)
- }
- })
- })
- function conn() {
- connection.query("SELECT * FROM `get`.`history` WHERE 1", function(err, rows, fields) {
- console.log(rows)
- })
- }
- setInterval(conn, 24000000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement