backend done

This commit is contained in:
Калышев Ян 2023-04-10 11:03:23 +04:00
parent ab4439a531
commit f889ccc84f
14 changed files with 907 additions and 2456 deletions

View File

@ -0,0 +1,222 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js");
class carController {
async update(req, res, next) {
const {changeColumn} = req.query;
const {changeValue} = req.query;
const {id} = req.query;
const {gosNumber} = req.query;
const {vin} = req.query;
const {Driverid} = req.query;
if (!((id || gosNumber || vin || Driverid) && changeColumn && changeValue)) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Car\" SET \"${changeColumn}\" = '${changeValue}' WHERE `;
var updateCond = []
if (id) {
updateCond.push(id)
updateQuery += `\"id\" = $${updateCond.length} `;
}
if (gosNumber){
updateCond.push(gosNumber);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"gosNumber\" = $${updateCond.length} `;
}
if (vin){
updateCond.push(vin);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"vin\" = $${updateCond.length} `;
i++
}
if (Driverid){
updateCond.push(Driverid);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"Driverid\" = $${updateCond.length} `;
i++
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {id} = req.query;
const {gosNumber} = req.query;
const {vin} = req.query;
const {Driverid} = req.query;
if (!(id || gosNumber || vin || Driverid))
var deleteQuery = "DELETE FROM public.\"Car\" WHERE "
var deleteCond = []
if (id) {
deleteCond.push(id);
deleteQuery += `\"id\" = $${deleteCond.length} `;
}
if (gosNumber) {
deleteCond.push(gosNumber);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"gosNumber\" = $${deleteCond.length} `;
}
if (vin) {
deleteCond.push(vin);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"vin\" = $${deleteCond.length} `;
}
if (Driverid) {
deleteCond.push(Driverid);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"Driverid\" = $${deleteCond.length} `;
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {gosNumber} = req.query;
const {vin} = req.query;
const {Driverid} = req.query;
if (!(gosNumber && vin && Driverid)) {
return next(ApiError.badRequest('need more args'))
}
var insertQuery = "INSERT INTO public.\"Car\" (\"gosNumber\", \"vin\", \"Driverid\") Values($1, $2, $3)"
var insertCond = [gosNumber, vin, Driverid]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('error'))
}
res.json(result.rows)
}
async getAll(req, res, next) {
var selectQuery = 'SELECT * FROM public."Car"'
try {
var result
result = await DB.query(selectQuery);
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {column} = req.query;
const {operatorid} = req.query;
const {id} = req.query;
const {gosNumber} = req.query;
const {vin} = req.query;
const {Driverid} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (column) {
selectQuery += `\"${column}\" FROM public.\"Car\" `;
} else {
selectQuery += "* FROM public.\"Car\" ";
}
if (!(id || gosNumber || vin || Driverid)) {
return next(ApiError.badRequest('need more args'))
}
if (id) {
selectCond.push(id);
if (!operatorid) {
selectQuery += `\"id\" = $${selectCond.length} `;
} else {
switch (operatorid) {
case ">":
selectQuery += `\"id\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"id\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"id\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"id\" != $${selectCond.length} `;
break;
default:
break;
}
}
}
if (gosNumber) {
selectCond.push(gosNumber);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"gosNumber\" = $${selectCond.length} `;
}
if (vin) {
selectCond.push(vin);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"vin\" = $${selectCond.length} `;
}
if (Driverid) {
selectCond.push(Driverid);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"Driverid\" = $${selectCond.length} `;
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new carController()

View File

@ -0,0 +1,230 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js")
class clientController {
async update(req, res, next) {
const {id} = req.query;
const {name} = req.query;
const {phone} = req.query;
const {email} = req.query;
const {changeColumn} = req.query;
const {changeValue} = req.query;
if (!((id || name || phone || email) && changeColumn && changeValue)) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Client\" SET \"${changeColumn}\" = '${changeValue}' WHERE `;
var updateCond = []
if (id) {
updateCond.push(id)
updateQuery += `\"id\" = $${updateCond.length} `;
}
if (name){
updateCond.push(name);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"name\" = $${updateCond.length} `;
}
if (phone){
updateCond.push(phone);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"phone\" = $${updateCond.length} `;
}
if (email){
updateCond.push(email);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"email\" = $${updateCond.length} `;
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {id} = req.query;
const {name} = req.query;
const {phone} = req.query;
const {email} = req.query;
if (!(id || name || phone || email)) {
return next(ApiError.badRequest('need more args'))
}
var deleteQuery = "DELETE FROM public.\"Client\" WHERE "
var deleteCond = []
if (id) {
deleteCond.push(id);
deleteQuery += `\"id\" = $${deleteCond.length} `;
}
if (name) {
deleteCond.push(name);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"name\" = $${deleteCond.length} `;
}
if (phone) {
deleteCond.push(phone);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"phone\" = $${deleteCond.length} `;
}
if (email) {
deleteCond.push(email);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"email\" = $${deleteCond.length} `;
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {name} = req.query;
const {phone} = req.query;
const {email} = req.query;
if (!((name && phone) || email)) {
return next(ApiError.badRequest('need more args'))
}
var insertQuery = "INSERT INTO public.\"Client\" (\"name\", \"phone\""
var insertCond = []
if (email) {
insertQuery += ", \"email\") Values($1, $2, $3)"
insertCond = [name, phone, email]
} else {
insertQuery += ") Values($1, $2)"
insertCond = [name, phone]
}
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('error'))
}
res.json(result.rows)
}
async getAll(req, res, next) {
var selectQuery = 'SELECT * FROM public."Client"'
try {
var result
result = await DB.query(selectQuery);
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {column} = req.query;
const {operatorid} = req.query;
const {id} = req.query;
const {name} = req.query;
const {phone} = req.query;
const {email} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (column) {
selectQuery += `\"${column}\" FROM public.\"Client\" WHERE `;
} else {
selectQuery += "* FROM public.\"Client\" WHERE ";
}
if (!(id || name || phone || email)) {
return next(ApiError.badRequest('need more args'))
}
if (id) {
selectCond.push(id);
if (!operatorid) {
selectQuery += `\"id\" = $${selectCond.length} `;
} else {
switch (operatorid) {
case ">":
selectQuery += `\"id\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"id\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"id\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"id\" != $${selectCond.length} `;
break;
default:
break;
}
}
}
if (name) {
selectCond.push(name);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"name\" = $${selectCond.length} `;
}
if (phone) {
selectCond.push(phone);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"phone\" = $${selectCond.length} `;
}
if (email) {
selectCond.push(email);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"email\" = $${selectCond.length} `;
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new clientController()

View File

@ -0,0 +1,277 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js");
class driverController {
async update(req, res, next) {
const {id} = req.query;
const {name} = req.query;
const {age} = req.query;
const {phone} = req.query;
const {email} = req.query;
const {changeColumn} = req.query;
const {changeValue} = req.query;
if (!((id || name || age || phone || email) && changeColumn && changeValue)) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Driver\" SET \"${changeColumn}\" = '${changeValue}' WHERE `;
var updateCond = []
if (id) {
updateCond.push(id)
updateQuery += `\"id\" = $${updateCond.length} `;
}
if (name){
updateCond.push(name);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"name\" = $${updateCond.length} `;
}
if (age){
updateCond.push(age);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"age\" = $${updateCond.length} `;
}
if (phone){
updateCond.push(phone);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"phone\" = $${updateCond.length} `;
}
if (email){
updateCond.push(email);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"email\" = $${updateCond.length} `;
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {id} = req.query;
const {name} = req.query;
const {age} = req.query;
const {phone} = req.query;
const {email} = req.query;
if (id || name || age || phone || email) {
return next(ApiError.badRequest('need more args'))
}
var deleteQuery = "DELETE FROM public.\"Driver\" WHERE "
var deleteCond = []
if (id) {
deleteCond.push(id);
deleteQuery += `\"id\" = $${deleteCond.length} `;
}
if (id) {
deleteCond.push(id);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"id\" = $${deleteCond.length} `;
}
if (name) {
deleteCond.push(name);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"name\" = $${deleteCond.length} `;
}
if (age) {
deleteCond.push(age);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"age\" = $${deleteCond.length} `;
}
if (phone) {
deleteCond.push(phone);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"phone\" = $${deleteCond.length} `;
}
if (email) {
deleteCond.push(email);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"email\" = $${deleteCond.length} `;
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {name} = req.query;
const {age} = req.query;
const {phone} = req.query;
const {email} = req.query;
if (!(name && age && phone && email)) {
return next(ApiError.badRequest('need more args'))
}
var insertQuery = "INSERT INTO public.\"Driver\" (\"name\", \"age\", \"phone\", \"email\") Values($1, $2, $3, $4)"
var insertCond = [name, age, phone, email]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('error'))
}
res.json(result.rows)
}
async getAll(req, res, next) {
var selectQuery = 'SELECT * FROM public."Driver"'
try {
var result
result = await DB.query(selectQuery);
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {column} = req.query;
const {id} = req.query;
const {operatorid} = req.query;
const {name} = req.query;
const {age} = req.query;
const {operatorage} = req.query;
const {phone} = req.query;
const {email} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (column) {
selectQuery += `\"${column}\" FROM public.\"Driver\" `;
} else {
selectQuery += "* FROM public.\"Driver\" ";
}
if (id || name || age || phone || email) {
selectQuery += "WHERE ";
} else {
return next(ApiError.badRequest('need more args'))
}
var i = 0
if (id) {
selectCond.push(id);
if (!operatorid) {
selectQuery += `\"id\" = $${selectCond.length} `;
} else {
switch (operatorid) {
case ">":
selectQuery += `\"id\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"id\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"id\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"id\" != $${selectCond.length} `;
break;
default:
break;
}
}
}
if (name) {
selectCond.push(name);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"name\" = $${selectCond.length} `;
}
if (age) {
selectCond.push(age);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
if (!operatorage) {
selectQuery += `\"age\" = $${selectCond.length} `;
} else {
switch (operatorage) {
case ">":
selectQuery += `\"age\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"age\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"age\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"age\" != $${selectCond.length} `;
break;
default:
break;
}
}
}
if (phone) {
selectCond.push(phone);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"phone\" = $${selectCond.length} `;
}
if (email) {
selectCond.push(email);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"email\" = $${selectCond.length} `;
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new driverController()

View File

@ -1,66 +1,58 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js")
const DB = require("../db.js");
class orderController {
async update(req, res, next) {
const {ID} = req.query;
const {Name} = req.query;
const {BeginDate} = req.query;
const {EndDate} = req.query;
const {TechAspectID} = req.query;
const {TechSpecificationID} = req.query;
if ((!ID && !Name && !BeginDate && !EndDate && !TechAspectID && !TechSpecificationID) || !ChangeColumn || !ChangeValue) {
const {id} = req.query;
const {value} = req.query;
const {Clientid} = req.query;
const {sourcePickUpPointid} = req.query;
const {destPickUpPointid} = req.query;
const {Carid} = req.query;
const {changeColumn} = req.query;
const {changeValue} = req.query;
if (!((id || value || Clientid || sourcePickUpPointid || destPickUpPointid || Carid) && changeColumn && changeValue)) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Role_Project\" SET \"${ChangeColumn}\" = '${ChangeValue}' `;
var updateQuery = `UPDATE \"Order\" SET \"${changeColumn}\" = '${changeValue}' WHERE `;
var updateCond = []
if (ID || Name || BeginDate || EndDate || TechAspectID || TechSpecificationID) {
updateQuery += "WHERE ";
if (id) {
updateCond.push(id)
updateQuery += `\"id\" = $${updateCond.length} `;
}
var i = 0;
if (ID) {
updateCond.push(ID)
updateQuery += `\"ID\" = $${updateCond.length} `;
i++
}
if (Name){
updateCond.push(Name);
if (i > 0) {
if (value){
updateCond.push(value);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"Name\" = $${updateCond.length} `;
i++
updateQuery += `\"value\" = $${updateCond.length} `;
}
if (BeginDate){
updateCond.push(BeginDate);
if (i > 0) {
if (Clientid){
updateCond.push(Clientid);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"BeginDate\" = $${updateCond.length} `;
i++
updateQuery += `\"Clientid\" = $${updateCond.length} `;
}
if (EndDate){
updateCond.push(EndDate);
if (i > 0) {
if (sourcePickUpPointid){
updateCond.push(sourcePickUpPointid);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"EndDate\" = $${updateCond.length} `;
i++
updateQuery += `\"sourcePickUpPointid\" = $${updateCond.length} `;
}
if (TechAspectID){
updateCond.push(TechAspectID);
if (i > 0) {
if (destPickUpPointid){
updateCond.push(destPickUpPointid);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"TechAspectID\" = $${updateCond.length} `;
i++
updateQuery += `\"destPickUpPointids\" = $${updateCond.length} `;
}
if (TechSpecificationID){
updateCond.push(TechSpecificationID);
if (i > 0) {
if (Carid){
updateCond.push(Carid);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"TechSpecificationID\" = $${updateCond.length} `;
i++
updateQuery += `\"Carid\" = $${updateCond.length} `;
}
try {
var result
@ -79,62 +71,62 @@ class orderController {
}
async delete(req, res, next) {
const {ID} = req.query;
const {Name} = req.query;
const {BeginDate} = req.query;
const {EndDate} = req.query;
const {TechAspectID} = req.query;
const {TechSpecificationID} = req.query;
if (!ID && !Name && !BeginDate && !EndDate && !TechAspectID && !TechSpecificationID) {
const {id} = req.query;
const {value} = req.query;
const {Clientid} = req.query;
const {sourcePickUpPointid} = req.query;
const {destPickUpPointid} = req.query;
const {Carid} = req.query;
if (id || value || Clientid || sourcePickUpPointid || destPickUpPointid || Carid) {
return next(ApiError.badRequest('need more args'))
}
var deleteQuery = "DELETE FROM public.\"Project\" WHERE "
var deleteQuery = "DELETE FROM public.\"Order\" WHERE "
var deleteCond = []
var i = 0
if (ID) {
deleteCond.push(ID);
deleteQuery += `\"ID\" = $${deleteCond.length} `;
i++
if (id) {
deleteCond.push(id);
deleteQuery += `\"id\" = $${deleteCond.length} `;
}
if (Name) {
deleteCond.push(Name);
if (i > 0) {
if (id) {
deleteCond.push(id);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"Name\" = $${deleteCond.length} `;
i++
deleteQuery += `\"id\" = $${deleteCond.length} `;
}
if (BeginDate) {
deleteCond.push(BeginDate);
if (i > 0) {
if (value) {
deleteCond.push(value);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"BeginDate\" = $${selectCond.length} `;
i++
deleteQuery += `\"value\" = $${deleteCond.length} `;
}
if (EndDate) {
deleteCond.push(EndDate);
if (i > 0) {
if (Clientid) {
deleteCond.push(Clientid);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"EndDate\" = $${selectCond.length} `;
i++
deleteQuery += `\"Clientid\" = $${deleteCond.length} `;
}
if (TechAspectID) {
deleteCond.push(TechAspectID);
if (i > 0) {
if (sourcePickUpPointid) {
deleteCond.push(sourcePickUpPointid);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"TechAspectID\" = $${selectCond.length} `;
i++
deleteQuery += `\"sourcePickUpPointid\" = $${deleteCond.length} `;
}
if (TechSpecificationID) {
deleteCond.push(TechSpecificationID);
if (i > 0) {
if (destPickUpPointid) {
deleteCond.push(destPickUpPointid);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"TechSpecificationID\" = $${selectCond.length} `;
i++
deleteQuery += `\"destPickUpPointid\" = $${deleteCond.length} `;
}
if (Carid) {
deleteCond.push(Carid);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"Carid\" = $${deleteCond.length} `;
}
deleteQuery += "RETURNING *"
try {
@ -159,18 +151,10 @@ class orderController {
const {sourcePickUpPointid} = req.query;
const {destPickUpPointid} = req.query;
const {Carid} = req.query;
if (!value || !Clientid || !sourcePickUpPointid || !destPickUpPointid || !Carid) {
if (!(value && Clientid && sourcePickUpPointid && destPickUpPointid && Carid)) {
return next(ApiError.badRequest('need more args'))
}
// var selectTechAspect = await DB.query("SELECT * FROM public.\"TechAspect\" WHERE \"ID\" = $1", [TechAspectID]);
// if (!selectTechAspect.rowCount) {
// return next(ApiError.badRequest('no TechAspectID in TechAspect'))
// }
// var selectTechSpecification = await DB.query("SELECT * FROM public.\"TechSpecification\" WHERE \"ID\" = $1", [TechSpecificationID]);
// if (!selectTechSpecification.rowCount) {
// return next(ApiError.badRequest('no TechSpecificationID in TechSpecification'))
// }
var insertQuery = "INSERT INTO public.\"Project\" (\"value\", \"Clientid\", \"sourcePickUpPointid\", \"destPickUpPointid\", \"Carid\") Values(), $1, $2, $3, $4, $5)"
var insertQuery = "INSERT INTO public.\"Order\" (\"value\", \"Clientid\", \"sourcePickUpPointid\", \"destPickUpPointid\", \"Carid\") Values($1, $2, $3, $4, $5)"
var insertCond = [value, Clientid, sourcePickUpPointid, destPickUpPointid, Carid]
try {
var result
@ -185,10 +169,26 @@ class orderController {
res.json(result.rows)
}
async getAll(req, res, next) {
var selectQuery = 'SELECT * FROM public."Order"'
try {
var result
result = await DB.query(selectQuery);
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {column} = req.query;
const {id} = req.query;
const {operatorid} = req.query;
const {value} = req.query;
const {operatorvalue} = req.query;
const {Clientid} = req.query;
const {sourcePickUpPointid} = req.query;
const {destPickUpPointid} = req.query;
@ -196,115 +196,91 @@ class orderController {
var selectQuery = "SELECT "
var selectCond = []
if (column) {
selectQuery += `\"${column}\" FROM public.\"Project\" `;
selectQuery += `\"${column}\" FROM public.\"Order\" `;
} else {
selectQuery += "* FROM public.\"Project\" ";
selectQuery += "* FROM public.\"Driver\" ";
}
if (id || value || Clientid || sourcePickUpPointid || destPickUpPointid || Carid) {
selectQuery += "WHERE ";
} else {
return next(ApiError.badRequest('need more args'))
}
var i = 0
if (id) {
selectCond.push(id);
if (!OperatorID) {
if (!operatorid) {
selectQuery += `\"id\" = $${selectCond.length} `;
} else {
switch (OperatorID) {
switch (operatorid) {
case ">":
selectQuery += `\"ID\" > $${selectCond.length} `;
selectQuery += `\"id\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"ID\" < $${selectCond.length} `;
selectQuery += `\"id\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"ID\" = $${selectCond.length} `;
selectQuery += `\"id\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"ID\" != $${selectCond.length} `;
selectQuery += `\"id\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (Name) {
selectCond.push(Name);
if (i > 0) {
if (value) {
selectCond.push(value);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"Name\" = $${selectCond.length} `;
i++
}
if (BeginDate) {
selectCond.push(BeginDate);
if (i > 0) {
selectQuery += "AND ";
}
if (!OperatorBeginDate) {
selectQuery += `\"BeginDate\" = $${selectCond.length} `;
if (!operatorvalue) {
selectQuery += `\"value\" = $${selectCond.length} `;
} else {
switch (OperatorBeginDate) {
switch (operatorvalue) {
case ">":
selectQuery += `\"BeginDate\" > $${selectCond.length} `;
selectQuery += `\"value\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"BeginDate\" < $${selectCond.length} `;
selectQuery += `\"value\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"BeginDate\" = $${selectCond.length} `;
selectQuery += `\"value\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"BeginDate\" != $${selectCond.length} `;
selectQuery += `\"value\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (EndDate) {
selectCond.push(EndDate);
if (i > 0) {
if (Clientid) {
selectCond.push(Clientid);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
if (!OperatorEndDate) {
selectQuery += `\"EndDate\" = $${selectCond.length} `;
} else {
switch (OperatorBeginDate) {
case ">":
selectQuery += `\"EndDate\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"EndDate\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"EndDate\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"EndDate\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
selectQuery += `\"Clientid\" = $${selectCond.length} `;
}
if (TechAspectID) {
selectCond.push(TechAspectID);
if (i > 0) {
if (sourcePickUpPointid) {
selectCond.push(sourcePickUpPointid);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"TechAspectID\" = $${selectCond.length} `;
i++
selectQuery += `\"sourcePickUpPointid\" = $${selectCond.length} `;
}
if (TechSpecificationID) {
selectCond.push(TechSpecificationID);
if (i > 0) {
if (destPickUpPointid) {
selectCond.push(destPickUpPointid);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"TechSpecificationID\" = $${selectCond.length} `;
i++
selectQuery += `\"destPickUpPointid\" = $${selectCond.length} `;
}
if (Carid) {
selectCond.push(Carid);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"Carid\" = $${selectCond.length} `;
}
try {
var result

View File

@ -6,7 +6,7 @@ class pickUpPointController {
const {changeValue} = req.query;
const {id} = req.query;
const {address} = req.query;
if (!id && !address && !changeColumn && !changeValue) {
if (!((id || address) && changeColumn && changeValue)) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"PickUpPoint\" SET \"${changeColumn}\" = '${changeValue}' `;
@ -14,67 +14,16 @@ class pickUpPointController {
if (id || address) {
updateQuery += "WHERE ";
}
var i = 0;
if (ID) {
updateCond.push(ID)
updateQuery += `\"ID\" = $${updateCond.length} `;
i++
if (id) {
updateCond.push(id)
updateQuery += `\"id\" = $${updateCond.length} `;
}
if (Name){
updateCond.push(Name);
if (i > 0) {
if (address){
updateCond.push(address);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"Name\" = $${updateCond.length} `;
i++
}
if (AllWorkExp){
updateCond.push(Email);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"Email\" = $${updateCond.length} `;
i++
}
if (Email){
updateCond.push(Password);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"Password\" = $${updateCond.length} `;
i++
}
if (MainTechID){
updateCond.push(MainTechID);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"MainTechID\" = $${updateCond.length} `;
i++
}
if (MainRoleID){
updateCond.push(MainRoleID);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"MainRoleID\" = $${updateCond.length} `;
i++
}
if (ProjectID){
updateCond.push(ProjectID);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"ProjectID\" = $${updateCond.length} `;
i++
}
if (RoleInProjectID){
updateCond.push(RoleInProjectID);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"RoleInProjectID\" = $${updateCond.length} `;
i++
updateQuery += `\"address\" = $${updateCond.length} `;
}
try {
var result
@ -93,80 +42,23 @@ class pickUpPointController {
}
async delete(req, res, next) {
const {ID} = req.query;
const {Name} = req.query;
const {AllWorkExp} = req.query;
const {Email} = req.query;
const {MainTechID} = req.query;
const {MainRoleID} = req.query;
const {ProjectID} = req.query;
const {RoleInProjectID} = req.query;
if (!ID && !Name && !AllWorkExp && !Email && !MainTechID && !MainRoleID && !ProjectID && !RoleInProjectID) {
const {id} = req.query;
const {address} = req.query;
if (!(id || address)) {
return next(ApiError.badRequest('need more args'))
}
var deleteQuery = "DELETE FROM public.\"Worker\" WHERE "
var deleteQuery = "DELETE FROM public.\"PickUpPoint\" WHERE "
var deleteCond = []
var i = 0
if (ID) {
deleteCond.push(ID);
if (id) {
deleteCond.push(id);
deleteQuery += `\"ID\" = $${deleteCond.length} `;
i++
}
if (Name) {
deleteCond.push(Name);
if (i > 0) {
if (address) {
deleteCond.push(address);
if (updateCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"Name\" = $${deleteCond.length} `;
i++
}
if (AllWorkExp) {
deleteCond.push(AllWorkExp);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"AllWorkExp\" = $${selectCond.length} `;
i++
}
if (Email) {
deleteCond.push(Email);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"Email\" = $${selectCond.length} `;
i++
}
if (MainTechID) {
deleteCond.push(MainTechID);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"MainTechID\" = $${selectCond.length} `;
i++
}
if (MainRoleID) {
deleteCond.push(MainRoleID);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"MainRoleID\" = $${selectCond.length} `;
i++
}
if (ProjectID) {
deleteCond.push(ProjectID);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"ProjectID\" = $${selectCond.length} `;
i++
}
if (RoleInProjectID) {
deleteCond.push(RoleInProjectID);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"RoleInProjectID\" = $${selectCond.length} `;
i++
deleteQuery += `\"address\" = $${deleteCond.length} `;
}
deleteQuery += "RETURNING *"
try {
@ -186,41 +78,13 @@ class pickUpPointController {
}
async add(req, res, next) {
const {Name} = req.query;
const {AllWorkExp} = req.query;
const {Email} = req.query;
const {MainTechID} = req.query;
const {MainRoleID} = req.query;
const {ProjectID} = req.query;
const {RoleInProjectID} = req.query;
if (!Name || !AllWorkExp || !Email || !MainTechID || !MainRoleID) {
const {address} = req.query;
if (!address) {
return next(ApiError.badRequest('need more args'))
}
var selectTechnology = await DB.query("SELECT * FROM public.\"Technology\" WHERE \"ID\" = $1", [MainTechID]);
if (!selectTechnology.rowCount) {
return next(ApiError.badRequest('no MainTechID in Technology'))
}
var selectRole = await DB.query("SELECT * FROM public.\"Role\" WHERE \"ID\" = $1", [MainRoleID]);
if (!selectRole.rowCount) {
return next(ApiError.badRequest('no MainRoleID in Role'))
}
var selectProject;
var selectRoleInProject;
if (ProjectID) {
selectProject = await DB.query("SELECT * FROM public.\"Project\" WHERE \"ID\" = $1", [ProjectID]);
if (!selectProject.rowCount) {
return next(ApiError.badRequest('no ProjectID in Project'))
}
}
if (RoleInProjectID) {
selectRoleInProject = await DB.query("SELECT * FROM public.\"Role\" WHERE \"ID\" = $1", [RoleInProjectID]);
if (!selectRoleInProject.rowCount) {
return next(ApiError.badRequest('no RoleInProjectID in Role'))
}
}
var insertQuery = "INSERT INTO public.\"Worker\" (\"ID\", \"Name\", \"AllWorkExp\", \"Email\", \"MainTechID\", \"MainRoleID\", \"ProjectID\", \"RoleInProjectID\") Values(nextval('\"ProjectID\"'), $1, $2, $3, $4, $5, $6, $7)"
var insertCond = [Name, AllWorkExp, Email, MainTechID, MainRoleID, ProjectID, RoleInProjectID]
var insertQuery = "INSERT INTO public.\"PickUpPoint\" (\"address\") Values($1)"
var insertCond = [address]
try {
var result
if (insertCond.length != 0) {
@ -234,17 +98,11 @@ class pickUpPointController {
res.json(result.rows)
}
async getRoles(req, res, next) {
const {Email} = req.query;
var selectQuery = 'SELECT "Role"."Name" FROM public."Worker", public."Role" WHERE "Worker"."Email" = $1 AND "Role"."ID" = "Worker"."MainRoleID"'
var selectCond = [Email]
async getAll(req, res, next) {
var selectQuery = 'SELECT * FROM public."PickUpPoint"'
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
result = await DB.query(selectQuery);
} catch (error) {
return next(ApiError.badRequest('not found'))
}
@ -255,244 +113,50 @@ class pickUpPointController {
}
async get(req, res, next) {
const {Column} = req.query;
const {OperatorID} = req.query;
const {OperatorAllWorkExp} = req.query;
const {OperatorMainTechID} = req.query;
const {OperatorMainRoleID} = req.query;
const {OperatorProjectID} = req.query;
const {OperatorRoleInProjectID} = req.query;
const {ID} = req.query;
const {Name} = req.query;
const {AllWorkExp} = req.query;
const {Email} = req.query;
const {MainTechID} = req.query;
const {MainRoleID} = req.query;
const {ProjectID} = req.query;
const {RoleInProjectID} = req.query;
const {column} = req.query;
const {operatorid} = req.query;
const {id} = req.query;
const {address} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (Column) {
selectQuery += `\"${Column}\" FROM public.\"Worker\" `;
if (column) {
selectQuery += `\"${column}\" FROM public.\"PickUpPoint\" `;
} else {
selectQuery += "* FROM public.\"Worker\" ";
selectQuery += "* FROM public.\"PickUpPoint\" ";
}
if (ID || Name || AllWorkExp || Email || MainTechID || MainRoleID || ProjectID || RoleInProjectID) {
selectQuery += "WHERE ";
if (!(id || address)) {
return next(ApiError.badRequest('need more args'))
}
var i = 0
if (ID) {
selectCond.push(ID);
if (!OperatorID) {
selectQuery += `\"ID\" = $${selectCond.length} `;
selectQuery += "WHERE ";
if (id) {
selectCond.push(id);
if (!OpeoperatoridratorID) {
selectQuery += `\"id\" = $${selectCond.length} `;
} else {
switch (OperatorID) {
switch (operatorid) {
case ">":
selectQuery += `\"ID\" > $${selectCond.length} `;
selectQuery += `\"id\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"ID\" < $${selectCond.length} `;
selectQuery += `\"id\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"ID\" = $${selectCond.length} `;
selectQuery += `\"id\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"ID\" != $${selectCond.length} `;
selectQuery += `\"id\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (Name) {
selectCond.push(Name);
if (i > 0) {
if (address) {
selectCond.push(address);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"Name\" = $${selectCond.length} `;
i++
}
if (AllWorkExp) {
selectCond.push(AllWorkExp);
if (i > 0) {
selectQuery += "AND ";
}
if (!OperatorAllWorkExp) {
selectQuery += `\"AllWorkExp\" = $${selectCond.length} `;
} else {
switch (OperatorAllWorkExp) {
case ">":
selectQuery += `\"AllWorkExp\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"AllWorkExp\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"AllWorkExp\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"AllWorkExp\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (Email) {
selectCond.push(Email);
if (i > 0) {
selectQuery += "AND ";
}
selectQuery += `\"Email\" = $${selectCond.length} `;
i++
}
if (MainTechID) {
selectCond.push(MainTechID);
if (i > 0) {
selectQuery += "AND ";
}
if (!OperatorMainTechID) {
selectQuery += `\"MainTechID\" = $${selectCond.length} `;
} else {
switch (OperatorMainTechID) {
case ">":
selectQuery += `\"MainTechID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"MainTechID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"MainTechID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"MainTechID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (MainRoleID) {
selectCond.push(MainRoleID);
if (i > 0) {
selectQuery += "AND ";
}
if (!OperatorMainRoleID) {
selectQuery += `\"MainRoleID\" = $${selectCond.length} `;
} else {
switch (OperatorMainRoleID) {
case ">":
selectQuery += `\"MainRoleID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"MainRoleID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"MainRoleID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"MainRoleID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (ProjectID) {
if (i > 0) {
selectQuery += "AND ";
}
if (ProjectID == "null") {
if (!OperatorProjectID) {
selectQuery += `\"ProjectID\" IS NULL `;
console.log(selectQuery)
console.log(selectCond)
} else {
switch (OperatorProjectID) {
case "=":
selectQuery += `\"ProjectID\" IS NULL `;
break;
case "!=":
selectQuery += `\"ProjectID\" IS NOT NULL `;
break;
default:
break;
}
}
} else {
selectCond.push(ProjectID);
if (!OperatorProjectID) {
selectQuery += `\"ProjectID\" = $${selectCond.length} `;
} else {
switch (OperatorProjectID) {
case ">":
selectQuery += `\"ProjectID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"ProjectID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"ProjectID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"ProjectID\" != $${selectCond.length} `;
break;
default:
break;
}
}
}
i++
}
if (RoleInProjectID) {
if (i > 0) {
selectQuery += "AND ";
}
if (RoleInProjectID == "null") {
if (!OperatorRoleInProjectID) {
selectQuery += `\"RoleInProjectID\" IS NULL `;
console.log(selectQuery)
console.log(selectCond)
} else {
switch (OperatorRoleInProjectID) {
case "=":
selectQuery += `\"RoleInProjectID\" IS NULL `;
break;
case "!=":
selectQuery += `\"RoleInProjectID\" IS NOT NULL `;
break;
default:
break;
}
}
} else {
selectCond.push(RoleInProjectID);
if (!OperatorRoleInProjectID) {
selectQuery += `\"RoleInProjectID\" = $${selectCond.length} `;
} else {
switch (OperatorRoleInProjectID) {
case ">":
selectQuery += `\"RoleInProjectID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"RoleInProjectID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"RoleInProjectID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"RoleInProjectID\" != $${selectCond.length} `;
break;
default:
break;
}
}
}
i++
selectQuery += `\"address\" = $${selectCond.length} `;
}
try {
var result
@ -510,4 +174,4 @@ class pickUpPointController {
res.json(result.rows)
}
}
module.exports = new workerController()
module.exports = new pickUpPointController()

View File

@ -1,328 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js")
class projectController {
async update(req, res, next) {
const {ID} = req.query;
const {Name} = req.query;
const {BeginDate} = req.query;
const {EndDate} = req.query;
const {TechAspectID} = req.query;
const {TechSpecificationID} = req.query;
if ((!ID && !Name && !BeginDate && !EndDate && !TechAspectID && !TechSpecificationID) || !ChangeColumn || !ChangeValue) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Role_Project\" SET \"${ChangeColumn}\" = '${ChangeValue}' `;
var updateCond = []
if (ID || Name || BeginDate || EndDate || TechAspectID || TechSpecificationID) {
updateQuery += "WHERE ";
}
var i = 0;
if (ID) {
updateCond.push(ID)
updateQuery += `\"ID\" = $${updateCond.length} `;
i++
}
if (Name){
updateCond.push(Name);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"Name\" = $${updateCond.length} `;
i++
}
if (BeginDate){
updateCond.push(BeginDate);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"BeginDate\" = $${updateCond.length} `;
i++
}
if (EndDate){
updateCond.push(EndDate);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"EndDate\" = $${updateCond.length} `;
i++
}
if (TechAspectID){
updateCond.push(TechAspectID);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"TechAspectID\" = $${updateCond.length} `;
i++
}
if (TechSpecificationID){
updateCond.push(TechSpecificationID);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"TechSpecificationID\" = $${updateCond.length} `;
i++
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {ID} = req.query;
const {Name} = req.query;
const {BeginDate} = req.query;
const {EndDate} = req.query;
const {TechAspectID} = req.query;
const {TechSpecificationID} = req.query;
if (!ID && !Name && !BeginDate && !EndDate && !TechAspectID && !TechSpecificationID) {
return next(ApiError.badRequest('need more args'))
}
var deleteQuery = "DELETE FROM public.\"Project\" WHERE "
var deleteCond = []
var i = 0
if (ID) {
deleteCond.push(ID);
deleteQuery += `\"ID\" = $${deleteCond.length} `;
i++
}
if (Name) {
deleteCond.push(Name);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"Name\" = $${deleteCond.length} `;
i++
}
if (BeginDate) {
deleteCond.push(BeginDate);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"BeginDate\" = $${selectCond.length} `;
i++
}
if (EndDate) {
deleteCond.push(EndDate);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"EndDate\" = $${selectCond.length} `;
i++
}
if (TechAspectID) {
deleteCond.push(TechAspectID);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"TechAspectID\" = $${selectCond.length} `;
i++
}
if (TechSpecificationID) {
deleteCond.push(TechSpecificationID);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"TechSpecificationID\" = $${selectCond.length} `;
i++
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {Name} = req.query;
const {BeginDate} = req.query;
const {EndDate} = req.query;
const {TechAspectID} = req.query;
const {TechSpecificationID} = req.query;
if (!Name || !BeginDate || !EndDate || !TechAspectID || !TechSpecificationID) {
return next(ApiError.badRequest('need more args'))
}
var selectTechAspect = await DB.query("SELECT * FROM public.\"TechAspect\" WHERE \"ID\" = $1", [TechAspectID]);
if (!selectTechAspect.rowCount) {
return next(ApiError.badRequest('no TechAspectID in TechAspect'))
}
var selectTechSpecification = await DB.query("SELECT * FROM public.\"TechSpecification\" WHERE \"ID\" = $1", [TechSpecificationID]);
if (!selectTechSpecification.rowCount) {
return next(ApiError.badRequest('no TechSpecificationID in TechSpecification'))
}
var insertQuery = "INSERT INTO public.\"Project\" (\"ID\", \"Name\", \"BeginDate\", \"EndDate\", \"TechAspectID\", \"TechSpecificationID\") Values(nextval('\"ProjectID\"'), $1, $2, $3, $4, $5)"
var insertCond = [Name, BeginDate, EndDate, TechAspectID, TechSpecificationID]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('error'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {Column} = req.query;
const {OperatorID} = req.query;
const {OperatorBeginDate} = req.query;
const {OperatorEndDate} = req.query;
const {ID} = req.query;
const {Name} = req.query;
const {BeginDate} = req.query;
const {EndDate} = req.query;
const {TechAspectID} = req.query;
const {TechSpecificationID} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (Column) {
selectQuery += `\"${Column}\" FROM public.\"Project\" `;
} else {
selectQuery += "* FROM public.\"Project\" ";
}
if (Name || BeginDate || EndDate || TechAspectID || TechSpecificationID || ID) {
selectQuery += "WHERE ";
}
var i = 0
if (ID) {
selectCond.push(ID);
if (!OperatorID) {
selectQuery += `\"ID\" = $${selectCond.length} `;
} else {
switch (OperatorID) {
case ">":
selectQuery += `\"ID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"ID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"ID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"ID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (Name) {
selectCond.push(Name);
if (i > 0) {
selectQuery += "AND ";
}
selectQuery += `\"Name\" = $${selectCond.length} `;
i++
}
if (BeginDate) {
selectCond.push(BeginDate);
if (i > 0) {
selectQuery += "AND ";
}
if (!OperatorBeginDate) {
selectQuery += `\"BeginDate\" = $${selectCond.length} `;
} else {
switch (OperatorBeginDate) {
case ">":
selectQuery += `\"BeginDate\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"BeginDate\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"BeginDate\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"BeginDate\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (EndDate) {
selectCond.push(EndDate);
if (i > 0) {
selectQuery += "AND ";
}
if (!OperatorEndDate) {
selectQuery += `\"EndDate\" = $${selectCond.length} `;
} else {
switch (OperatorBeginDate) {
case ">":
selectQuery += `\"EndDate\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"EndDate\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"EndDate\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"EndDate\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (TechAspectID) {
selectCond.push(TechAspectID);
if (i > 0) {
selectQuery += "AND ";
}
selectQuery += `\"TechAspectID\" = $${selectCond.length} `;
i++
}
if (TechSpecificationID) {
selectCond.push(TechSpecificationID);
if (i > 0) {
selectQuery += "AND ";
}
selectQuery += `\"TechSpecificationID\" = $${selectCond.length} `;
i++
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new projectController()

View File

@ -1,199 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js");
class roleController {
async update(req, res, next) {
const {ChangeColumn} = req.query;
const {ChangeValue} = req.query;
const {ProjectID} = req.query;
const {TechnologyID} = req.query;
if ((!TechnologyID && !ProjectID) || !ChangeColumn || !ChangeValue) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Role_Project\" SET \"${ChangeColumn}\" = '${ChangeValue}' `;
var updateCond = []
if (TechnologyID || ProjectID) {
updateQuery += "WHERE ";
}
var i = 0;
if (TechnologyID) {
updateCond.push(TechnologyID)
updateQuery += `\"TechnologyID\" = $${updateCond.length} `;
i++
}
if (ProjectID){
updateCond.push(ProjectID);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"ProjectID\" = $${updateCond.length} `;
i++
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {ProjectID} = req.query;
const {TechnologyID} = req.query;
if (!ProjectID && !TechnologyID) {
return next(ApiError.badRequest('need more args'))
}
var deleteQuery = "DELETE FROM public.\"Project_Technology\" WHERE "
var deleteCond = []
var i = 0
if (ProjectID) {
deleteCond.push(ProjectID);
deleteQuery += `\"ProjectID\" = $${deleteCond.length} `;
i++
}
if (TechnologyID) {
deleteCond.push(TechnologyID);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"TechnologyID\" = $${deleteCond.length} `;
i++
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {ProjectID} = req.query;
const {TechnologyID} = req.query;
if (!ProjectID || !TechnologyID) {
return next(ApiError.badRequest('need more args'))
}
var selectProject = await DB.query("SELECT * FROM public.\"Project\" WHERE \"ID\" = $1", [ProjectID]);
if (!selectProject.rowCount) {
return next(ApiError.badRequest('no ProjectID in Project'))
}
var selectTechnology = await DB.query("SELECT * FROM public.\"Technology\" WHERE \"ID\" = $1", [TechnologyID]);
if (!selectTechnology.rowCount) {
return next(ApiError.badRequest('no TechnologyID in Technology'))
}
var insertQuery = "INSERT INTO public.\"Project_Technology\" (\"ProjectID\", \"TechnologyID\") Values($1, $2)"
var insertCond = [ProjectID, TechnologyID]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('error'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {Column} = req.query;
const {OperatorProjectID} = req.query;
const {OperatorTechnologyID} = req.query;
const {ProjectID} = req.query;
const {TechnologyID} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (Column) {
selectQuery += `\"${Column}\" FROM public.\"Project_Technology\" `;
} else {
selectQuery += "* FROM public.\"Project_Technology\" ";
}
if (ProjectID || TechnologyID) {
selectQuery += "WHERE ";
}
var i = 0
if (ProjectID) {
selectCond.push(ProjectID);
if (!OperatorProjectID) {
selectQuery += `\"ProjectID\" = $${selectCond.length} `;
} else {
switch (OperatorProjectID) {
case ">":
selectQuery += `\"ProjectID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"ProjectID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"ProjectID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"ProjectID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (TechnologyID) {
selectCond.push(TechnologyID);
if (i > 0) {
selectQuery += "AND ";
}
if (!OperatorTechnologyID) {
selectQuery += `\"TechnologyID\" = $${selectCond.length} `;
} else {
switch (OperatorTechnologyID) {
case ">":
selectQuery += `\"TechnologyID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"TechnologyID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"TechnologyID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"TechnologyID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new roleController()

View File

@ -1,178 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js");
class roleController {
async update(req, res, next) {
const {ChangeColumn} = req.query;
const {ChangeValue} = req.query;
const {ID} = req.query;
const {Name} = req.query;
if ((!ID && !Name) || !ChangeColumn || !ChangeValue) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Role\" SET \"${ChangeColumn}\" = '${ChangeValue}' `;
var updateCond = []
if (ID || Name) {
updateQuery += "WHERE ";
}
var i = 0;
if (ID) {
updateCond.push(ID)
updateQuery += `\"ID\" = $${updateCond.length} `;
i++
}
if (Name){
updateCond.push(Name);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"Name\" = $${updateCond.length} `;
i++
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {ID} = req.query;
const {Name} = req.query;
if (!ID && !Name) {
return next(ApiError.badRequest('need more args'))
}
var selectRefs1 = await DB.query("SELECT * FROM \"Role_Project\" WHERE \"RoleID\" = $1", [ID])
var selectRefs2 = await DB.query("SELECT * FROM \"Worker\" WHERE \"MainRoleID\" = $1", [ID])
var selectRefs3 = await DB.query("SELECT * FROM \"Worker\" WHERE \"RoleInProjectID\" = $1", [ID])
if (selectRefs1.rowCount) {
return next(ApiError.badRequest('exist Role_Project refs for ID'))
} else if (selectRefs2.rowCount) {
return next(ApiError.badRequest('exist Worker.MainRoleID refs for ID'))
} else if (selectRefs3.rowCount) {
return next(ApiError.badRequest('exist Worker.RoleInProjectID refs for ID'))
}
var deleteQuery = "DELETE FROM public.\"Role\" WHERE "
var deleteCond = []
var i = 0
if (ID) {
deleteCond.push(ID);
deleteQuery += `\"ID\" = $${deleteCond.length} `;
i++
}
if (Name) {
deleteCond.push(Name);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"Name\" = $${deleteCond.length} `;
i++
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {Name} = req.query;
if (!Name) {
return next(ApiError.badRequest('need more args'))
}
var insertQuery = "INSERT INTO public.\"Role\" (\"ID\", \"Name\") Values(nextval('\"RoleID\"'), $1)"
var insertCond = [Name]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('not unique'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {Column} = req.query;
const {OperatorID} = req.query;
const {ID} = req.query;
const {Name} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (Column) {
selectQuery += `\"${Column}\" FROM public.\"Role\" `;
} else {
selectQuery += "* FROM public.\"Role\" ";
}
if (ID || Name) {
selectQuery += "WHERE ";
}
var i = 0
if (ID) {
selectCond.push(ID);
if (!OperatorID) {
selectQuery += `\"ID\" = $${selectCond.length} `;
} else {
switch (OperatorID) {
case ">":
selectQuery += `\"ID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"ID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"ID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"ID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (Name) {
selectCond.push(Name);
if (i > 0) {
selectQuery += "AND ";
}
selectQuery += `\"Name\" = $${selectCond.length} `;
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new roleController()

View File

@ -1,199 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js");
class roleController {
async update(req, res, next) {
const {ChangeColumn} = req.query;
const {ChangeValue} = req.query;
const {RoleID} = req.query;
const {ProjectID} = req.query;
if ((!RoleID && !ProjectID) || !ChangeColumn || !ChangeValue) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Role_Project\" SET \"${ChangeColumn}\" = '${ChangeValue}' `;
var updateCond = []
if (RoleID || ProjectID) {
updateQuery += "WHERE ";
}
var i = 0;
if (RoleID) {
updateCond.push(RoleID)
updateQuery += `\"RoleID\" = $${updateCond.length} `;
i++
}
if (ProjectID){
updateCond.push(ProjectID);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"ProjectID\" = $${updateCond.length} `;
i++
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {RoleID} = req.query;
const {ProjectID} = req.query;
if (!RoleID && !ProjectID) {
return next(ApiError.badRequest('need more args'))
}
var deleteQuery = "DELETE FROM public.\"Role_Project\" WHERE "
var deleteCond = []
var i = 0
if (ProjectID) {
deleteCond.push(ProjectID);
deleteQuery += `\"ProjectID\" = $${deleteCond.length} `;
i++
}
if (RoleID) {
deleteCond.push(RoleID);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"RoleID\" = $${deleteCond.length} `;
i++
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {RoleID} = req.query;
const {ProjectID} = req.query;
if (!ProjectID || !RoleID) {
return next(ApiError.badRequest('need more args'))
}
var selectRole = await DB.query("SELECT * FROM public.\"Role\" WHERE \"ID\" = $1", [RoleID]);
if (!selectRole.rowCount) {
return next(ApiError.badRequest('no RoleID in Role'))
}
var selectProject = await DB.query("SELECT * FROM public.\"Project\" WHERE \"ID\" = $1", [ProjectID]);
if (!selectProject.rowCount) {
return next(ApiError.badRequest('no ProjectID in Project'))
}
var insertQuery = "INSERT INTO public.\"Role_Project\" (\"RoleID\", \"ProjectID\") Values($1, $2)"
var insertCond = [RoleID, ProjectID]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('error'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {Column} = req.query;
const {OperatorProjectID} = req.query;
const {OperatorRoleID} = req.query;
const {RoleID} = req.query;
const {ProjectID} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (Column) {
selectQuery += `\"${Column}\" FROM public.\"Role_Project\" `;
} else {
selectQuery += "* FROM public.\"Role_Project\" ";
}
if (ProjectID || RoleID) {
selectQuery += "WHERE ";
}
var i = 0
if (ProjectID) {
selectCond.push(ProjectID);
if (!OperatorProjectID) {
selectQuery += `\"ProjectID\" = $${selectCond.length} `;
} else {
switch (OperatorProjectID) {
case ">":
selectQuery += `\"ProjectID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"ProjectID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"ProjectID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"ProjectID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (RoleID) {
selectCond.push(RoleID);
if (i > 0) {
selectQuery += "AND ";
}
if (!OperatorRoleID) {
selectQuery += `\"RoleID\" = $${selectCond.length} `;
} else {
switch (OperatorRoleID) {
case ">":
selectQuery += `\"RoleID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"RoleID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"RoleID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"RoleID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new roleController()

View File

@ -1,173 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js")
class techAspectController {
async update(req, res, next) {
const {ChangeColumn} = req.query;
const {ChangeValue} = req.query;
const {ID} = req.query;
const {Name} = req.query;
if ((!ID && !Name) || !ChangeColumn || !ChangeValue) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"TechAspect\" SET \"${ChangeColumn}\" = '${ChangeValue}' `;
var updateCond = []
if (ID || Name) {
updateQuery += "WHERE ";
}
var i = 0;
if (ID) {
updateCond.push(ID)
updateQuery += `\"ID\" = $${updateCond.length} `;
i++
}
if (Name){
updateCond.push(Name);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"Name\" = $${updateCond.length} `;
i++
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {ID} = req.query;
const {Name} = req.query;
if (!ID && !Name) {
return next(ApiError.badRequest('need more args'))
}
var selectRefs = await DB.query("SELECT * FROM \"Project\" WHERE \"TechAspectID\" = $1", [ID])
if (selectRefs.rowCount) {
return next(ApiError.badRequest('exist Project refs for ID'))
}
var deleteQuery = "DELETE FROM public.\"TechAspect\" WHERE "
var deleteCond = []
var i = 0
if (ID) {
deleteCond.push(ID);
deleteQuery += `\"ID\" = $${deleteCond.length} `;
i++
}
if (Name) {
deleteCond.push(Name);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"Name\" = $${deleteCond.length} `;
i++
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {Name} = req.query;
if (!Name) {
return next(ApiError.badRequest('need more args'))
}
var insertQuery = "INSERT INTO public.\"TechAspect\" (\"ID\", \"Name\") Values(nextval('\"TechAspectID\"'), $1)"
var insertCond = [Name]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('not unique'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {Column} = req.query;
const {OperatorID} = req.query;
const {ID} = req.query;
const {Name} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (Column) {
selectQuery += `\"${Column}\" FROM public.\"TechAspect\" `;
} else {
selectQuery += "* FROM public.\"TechAspect\" ";
}
if (ID || Name) {
selectQuery += "WHERE ";
}
var i = 0
if (ID) {
selectCond.push(ID);
if (!OperatorID) {
selectQuery += `\"ID\" = $${selectCond.length} `;
} else {
switch (OperatorID) {
case ">":
selectQuery += `\"ID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"ID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"ID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"ID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (Name) {
selectCond.push(Name);
if (i > 0) {
selectQuery += "AND ";
}
selectQuery += `\"Name\" = $${selectCond.length} `;
i++
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new techAspectController()

View File

@ -1,173 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js")
class techSpecificationController {
async update(req, res, next) {
const {ChangeColumn} = req.query;
const {ChangeValue} = req.query;
const {ID} = req.query;
const {Name} = req.query;
if ((!ID && !Name) || !ChangeColumn || !ChangeValue) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"TechSpecification\" SET \"${ChangeColumn}\" = '${ChangeValue}' `;
var updateCond = []
if (ID || Name) {
updateQuery += "WHERE ";
}
var i = 0;
if (ID) {
updateCond.push(ID)
updateQuery += `\"ID\" = $${updateCond.length} `;
i++
}
if (Name){
updateCond.push(Name);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"Name\" = $${updateCond.length} `;
i++
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {ID} = req.query;
const {Name} = req.query;
if (!ID && !Name) {
return next(ApiError.badRequest('need more args'))
}
var selectRefs = await DB.query("SELECT * FROM \"Project\" WHERE \"TechSpecificationID\" = $1", [ID])
if (selectRefs.rowCount) {
return next(ApiError.badRequest('exist Project refs for ID'))
}
var deleteQuery = "DELETE FROM public.\"TechSpecification\" WHERE "
var deleteCond = []
var i = 0
if (ID) {
deleteCond.push(ID);
deleteQuery += `\"ID\" = $${deleteCond.length} `;
i++
}
if (Name) {
deleteCond.push(Name);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"Name\" = $${deleteCond.length} `;
i++
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {Name} = req.query;
if (!Name) {
return next(ApiError.badRequest('need more args'))
}
var insertQuery = "INSERT INTO public.\"TechSpecification\" (\"ID\", \"Name\") Values(nextval('\"TechSpecificationID\"'), $1)"
var insertCond = [Name]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('not unique'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {Column} = req.query;
const {OperatorID} = req.query;
const {ID} = req.query;
const {Name} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (Column) {
selectQuery += `\"${Column}\" FROM public.\"TechSpecification\" `;
} else {
selectQuery += "* FROM public.\"TechSpecification\" ";
}
if (ID || Name) {
selectQuery += "WHERE ";
}
var i = 0
if (ID) {
selectCond.push(ID);
if (!OperatorID) {
selectQuery += `\"ID\" = $${selectCond.length} `;
} else {
switch (OperatorID) {
case ">":
selectQuery += `\"ID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"ID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"ID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"ID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (Name) {
selectCond.push(Name);
if (i > 0) {
selectQuery += "AND ";
}
selectQuery += `\"Name\" = $${selectCond.length} `;
i++
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new techSpecificationController()

View File

@ -1,180 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js")
class technologyController {
async update(req, res, next) {
const {ChangeColumn} = req.query;
const {ChangeValue} = req.query;
const {ID} = req.query;
const {Name} = req.query;
if ((!ID && !Name) || !ChangeColumn || !ChangeValue) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Technology\" SET \"${ChangeColumn}\" = '${ChangeValue}' `;
var updateCond = []
if (ID || Name) {
updateQuery += "WHERE ";
}
var i = 0;
if (ID) {
updateCond.push(ID)
updateQuery += `\"ID\" = $${updateCond.length} `;
i++
}
if (Name){
updateCond.push(Name);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"Name\" = $${updateCond.length} `;
i++
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {ID} = req.query;
const {Name} = req.query;
if (!ID && !Name) {
return next(ApiError.badRequest('need more args'))
}
var selectRefs1 = await DB.query("SELECT * FROM \"Project_Technology\" WHERE \"TechnologyID\" = $1", [ID])
var selectRefs2 = await DB.query("SELECT * FROM \"Worker\" WHERE \"MainTechID\" = $1", [ID])
var selectRefs3 = await DB.query("SELECT * FROM \"Worker_Technology\" WHERE \"TechnologyID\" = $1", [ID])
if (selectRefs1.rowCount) {
return next(ApiError.badRequest('exist Project_Technology refs for ID'))
} else if (selectRefs2.rowCount) {
return next(ApiError.badRequest('exist Worker refs for ID'))
} else if (selectRefs3.rowCount) {
return next(ApiError.badRequest('exist Worker_Technology refs for ID'))
}
var deleteQuery = "DELETE FROM public.\"Technology\" WHERE "
var deleteCond = []
var i = 0
if (ID) {
deleteCond.push(ID);
deleteQuery += `\"ID\" = $${deleteCond.length} `;
i++
}
if (Name) {
deleteCond.push(Name);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"Name\" = $${deleteCond.length} `;
i++
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {Name} = req.query;
if (!Name) {
return next(ApiError.badRequest('need more args'))
}
var insertQuery = "INSERT INTO public.\"Technology\" (\"ID\", \"Name\") Values(nextval('\"TechnologyID\"'), $1)"
var insertCond = [Name]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('not unique'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {Column} = req.query;
const {OperatorID} = req.query;
const {ID} = req.query;
const {Name} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (Column) {
selectQuery += `\"${Column}\" FROM public.\"Technology\" `;
} else {
selectQuery += "* FROM public.\"Technology\" ";
}
if (ID || Name) {
selectQuery += "WHERE ";
}
var i = 0
if (ID) {
selectCond.push(ID);
if (!OperatorID) {
selectQuery += `\"ID\" = $${selectCond.length} `;
} else {
switch (OperatorID) {
case ">":
selectQuery += `\"ID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"ID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"ID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"ID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (Name) {
selectCond.push(Name);
if (i > 0) {
selectQuery += "AND ";
}
selectQuery += `\"Name\" = $${selectCond.length} `;
i++
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new technologyController()

View File

@ -1,234 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js")
class usersController {
async update(req, res, next) {
const {ChangeColumn} = req.query;
const {ChangeValue} = req.query;
const {ID} = req.query;
const {Name} = req.query;
const {Email} = req.query;
const {Password} = req.query;
if ((!ID && !Name && !Email && !Password) || !ChangeColumn || !ChangeValue) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Users\" SET \"${ChangeColumn}\" = '${ChangeValue}' `;
var updateCond = []
if (ID || Name || Email || Password) {
updateQuery += "WHERE ";
}
var i = 0;
if (ID) {
updateCond.push(ID)
updateQuery += `\"ID\" = $${updateCond.length} `;
i++
}
if (Name){
updateCond.push(Name);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"Name\" = $${updateCond.length} `;
i++
}
if (Email){
updateCond.push(Email);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"Email\" = $${updateCond.length} `;
i++
}
if (Password){
updateCond.push(Password);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"Password\" = $${updateCond.length} `;
i++
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {ID} = req.query;
const {Name} = req.query;
const {Email} = req.query;
const {Password} = req.query;
if (!ID && !Name && !Email && !Password) {
return next(ApiError.badRequest('need more args'))
}
var deleteQuery = "DELETE FROM public.\"Users\" WHERE "
var deleteCond = []
var i = 0
if (ID) {
deleteCond.push(ID);
deleteQuery += `\"ID\" = $${deleteCond.length} `;
i++
}
if (Name) {
deleteCond.push(Name);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"Name\" = $${deleteCond.length} `;
i++
}
if (Email) {
deleteCond.push(Email);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"Email\" = $${deleteCond.length} `;
i++
}
if (Password) {
deleteCond.push(Password);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"Password\" = $${deleteCond.length} `;
i++
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {Name} = req.query;
const {Email} = req.query;
const {Password} = req.query;
if (!Name || !Email || !Password) {
return next(ApiError.badRequest('need more args'))
}
var selectName = await DB.query("SELECT * FROM public.\"Users\" WHERE \"Name\" = $1", [Name]);
var selectEmail = await DB.query("SELECT * FROM public.\"Users\" WHERE \"Email\" = $1", [Email]);
if (selectName.rowCount) {
return next(ApiError.badRequest('not unique Name'))
}
if (selectEmail.rowCount) {
return next(ApiError.badRequest('not unique Email'))
}
var insertQuery = "INSERT INTO public.\"Users\" (\"ID\", \"Name\", \"Email\", \"Password\") Values(nextval('\"UsersID\"'), $1, $2, $3)"
var insertCond = [Name, Email, Password]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('not unique'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {Column} = req.query;
const {OperatorID} = req.query;
const {ID} = req.query;
const {Name} = req.query;
const {Email} = req.query;
const {Password} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (Column) {
selectQuery += `\"${Column}\" FROM public.\"Users\" `;
} else {
selectQuery += "* FROM public.\"Users\" ";
}
if (ID || Name || Password || Email) {
selectQuery += "WHERE ";
}
var i = 0
if (ID) {
selectCond.push(ID);
if (!OperatorID) {
selectQuery += `\"ID\" = $${selectCond.length} `;
} else {
switch (OperatorID) {
case ">":
selectQuery += `\"ID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"ID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"ID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"ID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (Name) {
selectCond.push(Name);
if (i > 0) {
selectQuery += "AND ";
}
selectQuery += `\"Name\" = $${selectCond.length} `;
i++
}
if (Email) {
selectCond.push(Email);
if (i > 0) {
selectQuery += "AND ";
}
selectQuery += `\"Email\" = $${selectCond.length} `;
i++
}
if (Password) {
selectCond.push(Password);
if (i > 0) {
selectQuery += "AND ";
}
selectQuery += `\"Password\" = $${selectCond.length} `;
i++
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new usersController()

View File

@ -1,254 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js");
class roleController {
async update(req, res, next) {
const {ChangeColumn} = req.query;
const {ChangeValue} = req.query;
const {WorkerID} = req.query;
const {TechnologyID} = req.query;
const {TimeSpended} = req.query;
if ((!WorkerID && !TechnologyID && !TimeSpended) || !ChangeColumn || !ChangeValue) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Worker_Technology\" SET \"${ChangeColumn}\" = '${ChangeValue}' `;
var updateCond = []
if (WorkerID || TechnologyID || TimeSpended) {
updateQuery += "WHERE ";
}
var i = 0;
if (WorkerID) {
updateCond.push(WorkerID)
updateQuery += `\"WorkerID\" = $${updateCond.length} `;
i++
}
if (TechnologyID){
updateCond.push(TechnologyID);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"TechnologyID\" = $${updateCond.length} `;
i++
}
if (TimeSpended){
updateCond.push(TimeSpended);
if (i > 0) {
updateQuery += "AND ";
}
updateQuery += `\"TimeSpended\" = $${updateCond.length} `;
i++
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {WorkerID} = req.query;
const {TechnologyID} = req.query;
const {TimeSpended} = req.query;
if (!WorkerID && !TechnologyID && !TimeSpended) {
return next(ApiError.badRequest('need more args'))
}
var deleteQuery = "DELETE FROM public.\"Worker_Technology\" WHERE "
var deleteCond = []
var i = 0
if (WorkerID) {
deleteCond.push(WorkerID);
deleteQuery += `\"WorkerID\" = $${deleteCond.length} `;
i++
}
if (TechnologyID) {
deleteCond.push(TechnologyID);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"TechnologyID\" = $${deleteCond.length} `;
i++
}
if (TimeSpended) {
deleteCond.push(TimeSpended);
if (i > 0) {
deleteQuery += "AND ";
}
deleteQuery += `\"TimeSpended\" = $${deleteCond.length} `;
i++
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {WorkerID} = req.query;
const {TechnologyID} = req.query;
const {TimeSpended} = req.query;
if (!TechnologyID || !WorkerID) {
return next(ApiError.badRequest('need more args'))
}
var selectWorker = await DB.query("SELECT * FROM public.\"Worker\" WHERE \"ID\" = $1", [WorkerID]);
if (!selectWorker.rowCount) {
return next(ApiError.badRequest('no WorkerID in Worker'))
}
var selectTechnology = await DB.query("SELECT * FROM public.\"Technology\" WHERE \"ID\" = $1", [TechnologyID]);
if (!selectTechnology.rowCount) {
return next(ApiError.badRequest('no TechnologyID in Technology'))
}
var insertQuery = "INSERT INTO public.\"Worker_Technology\" "
var insertCond
if (!TimeSpended) {
insertQuery += "(\"WorkerID\", \"TechnologyID\") Values($1, $2)"
insertCond = [WorkerID, TechnologyID]
} else {
insertQuery += "(\"WorkerID\", \"TechnologyID\", \"TimeSpended\") Values($1, $2, $3)"
insertCond = [WorkerID, TechnologyID, TimeSpended]
}
//try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
//} catch (error) {
// return next(ApiError.badRequest('error'))
//}
res.json(result.rows)
}
async get(req, res, next) {
const {Column} = req.query;
const {OperatorWorkerID} = req.query;
const {OperatorTechnologyID} = req.query;
const {OperatorTimeSpended} = req.query;
const {WorkerID} = req.query;
const {TechnologyID} = req.query;
const {TimeSpended} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (Column) {
selectQuery += `\"${Column}\" FROM public.\"Worker_Technology\" `;
} else {
selectQuery += "* FROM public.\"Worker_Technology\" ";
}
if (WorkerID || TechnologyID) {
selectQuery += "WHERE ";
}
var i = 0
if (WorkerID) {
selectCond.push(WorkerID);
if (!OperatorWorkerID) {
selectQuery += `\"WorkerID\" = $${selectCond.length} `;
} else {
switch (OperatorWorkerID) {
case ">":
selectQuery += `\"WorkerID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"WorkerID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"WorkerID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"WorkerID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (TimeSpended) {
selectCond.push(TimeSpended);
if (i > 0) {
selectQuery += "AND ";
}
if (!OperatorTimeSpended) {
selectQuery += `\"TimeSpended\" = $${selectCond.length} `;
} else {
switch (OperatorTimeSpended) {
case ">":
selectQuery += `\"TimeSpended\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"TimeSpended\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"TimeSpended\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"TimeSpended\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
if (TechnologyID) {
selectCond.push(TechnologyID);
if (i > 0) {
selectQuery += "AND ";
}
if (!OperatorTechnologyID) {
selectQuery += `\"TechnologyID\" = $${selectCond.length} `;
} else {
switch (OperatorTechnologyID) {
case ">":
selectQuery += `\"TechnologyID\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"TechnologyID\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"TechnologyID\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"TechnologyID\" != $${selectCond.length} `;
break;
default:
break;
}
}
i++
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new roleController()