cavecomm/src/databaseStatementConstColle...

357 lines
25 KiB
C++

#ifndef DATABASE_STATEMENT_CONST_COLLECTION_CPP
#define DATABASE_STATEMENT_CONST_COLLECTION_CPP
#include <string>
#include <map>
/*
* Database Statement Const Collection
*/
namespace DatabaseStatementConstCollection {
/*
* Name and Statement for prepared statement to insert an item into Requests
*/
const static std::string PREPARED_STATEMENT_INSERT_ITEM_IN_REQUESTS = "insertItemInRequests";
const static std::string SQL_STATEMENT_INSERT_ITEM_IN_REQUESTS = "INSERT INTO requests(id, customerEmailAddress, freelancerid , templateid , currencyPreference, priceUpFront, priceOnDeliver, requestDescription, accepted, upFrontInvoiceID, onDeliverInvoiceID, upFrontPaid, onDeliverPaid, completed, customerContactDetails, customerName) VALUES(DEFAULT, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);";
/*
* Name and Statement for prepared statement to create a new freelancer
*/
const static std::string PREPARED_STATEMENT_INSERT_NEW_FREELANCER = "insertNewFreelancer";
const static std::string SQL_STATEMENT_INSERT_NEW_FREELANCER = "INSERT INTO freelancers (emailaddress, name, salt, hash) values($1, $2, $3, $4);";
/*
* Name and Statement for prepared statement to select an item based on a given ID
* Case for boolean return values because the default return value is f/t instead of 0/1 or false/true
*/
const static std::string PREPARED_STATEMENT_SELECT_ITEM_BY_ID = "selectItemByID";
const static std::string SQL_STATEMENT_SELECT_ITEM_BY_ID = "SELECT requests.id , customerEmailAddress, freelancers.name, templates.name, currencyPreference, priceUpFront, priceOnDeliver, requestDescription, (CASE WHEN requests.accepted THEN 1 ELSE 0 END) AS accepted, upFrontInvoiceID, onDeliverInvoiceID, (CASE WHEN requests.upFrontPaid THEN 1 ELSE 0 END) AS upFrontPaid, (CASE WHEN requests.onDeliverPaid THEN 1 ELSE 0 END) AS onDeliverPaid FROM requests INNER JOIN freelancers ON freelancers.id=requests.freelancerID INNER JOIN templates ON templates.id=requests.templateID WHERE requests.id=$1;";
/*
* Name and Statement for prepared statement to select a freelancers commission state based on a given id
* 0 == commissions are open
* 1 == commissions are closed
*/
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_COMMISSION_STATE = "selectFreelancerCommissionState";
const static std::string SQL_STATEMENT_SELECT_FREELANCER_COMMISSION_STATE = "select (case when (commissionlimit <= (select count(*) as requestCount from requests where requests.accepted = true and requests.freelancerid = id group by freelancerid)) then 1 else 0 end) as commissionsclosed from freelancers where freelancers.id = $1;";
/*
* Name and Statement for prepared statement to select a freelancers emailaddress based on a given id
*/
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_EMAIL = "selectFreelancerEmailAddress";
const static std::string SQL_STATEMENT_SELECT_FREELANCER_EMAIL = "select emailaddress from freelancers where id = $1;";
/*
* Name and Statement for prepared statement to check if an email is already registered with a freelancer
*/
const static std::string PREPARED_STATEMENT_SELECT_CHECK_EMAIL_EXISTS = "selectCheckEmailExists";
const static std::string SQL_STATEMENT_SELECT_CHECK_EMAIL_EXISTS = "select count(*) from freelancers where emailaddress = $1;";
/*
* Name and Statement for prepared statement to validate if a freelancer is already logged in
*/
const static std::string PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_LOGIN_STATE = "selectCheckFreelancerLoginState";
const static std::string SQL_STATEMENT_SELECT_CHECK_FREELANCER_LOGIN_STATE = "select count(*) from freelancers where emailaddress = $1 AND loginvalidationkey = $2;";
/*
* Name and Statement for prepared statement to get salt using a given email
*/
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_SALT = "selectFreelancerSalt";
const static std::string SQL_STATEMENT_SELECT_FREELANCER_SALT = "select salt from freelancers where emailaddress = $1;";
/*
* Name and Statement for prepared statement to get id using a given email
*/
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_ID = "selectFreelancerID";
const static std::string SQL_STATEMENT_SELECT_FREELANCER_ID = "select id from freelancers where emailaddress = $1;";
/*
* Name and Statement for prepared statement to check if hash is valid
*/
const static std::string PREPARED_STATEMENT_SELECT_CHECK_HASH_VALID = "selectCheckHashValid";
const static std::string SQL_STATEMENT_SELECT_CHECK_HASH_VALID = "select count(*) from freelancers where emailaddress = $1 AND hash = $2;";
/*
* Name and Statement for prepared statement to select a freelancer based on a given id
*/
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER = "selectFreelancer";
const static std::string SQL_STATEMENT_SELECT_FREELANCER = "select id, name, generalinformation, basicinformation from freelancers WHERE id=$1;";
/*
* Name and Statement for prepared statement to select a freelancer based on a given id for presentation to the customer
*/
const static std::string PREPARED_STATEMENT_SELECT_TEMPLATE = "selectTemplate";
const static std::string SQL_STATEMENT_SELECT_TEMPLATE = "select templates.id as templateid, templates.name as templatename, freelancers.id as freelancerid, freelancers.name as freelancername, contactdata, contactinformation, currencypreference, (coalesce(priceupfront ,0) + coalesce(priceondeliver ,0)) as pricetotal, priceupfront, priceondeliver, content from templates inner join freelancers on freelancers.id=templates.freelancerid where templates.id = $1;";
/*
* Name and Statement for prepared statement to select a freelancer based on a given id for usage in a request
*/
const static std::string PREPARED_STATEMENT_SELECT_TEMPLATE_FLAT = "selectTemplateFlat";
const static std::string SQL_STATEMENT_SELECT_TEMPLATE_FLAT = "select freelancerid, currencypreference, priceupfront, priceondeliver from templates where id = $1;";
/*
* Name and Statement for prepared statement to select a freelancers templates based on a given freelancer id
*/
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_TEMPLATES = "selectFreelancerTemplates";
const static std::string SQL_STATEMENT_SELECT_FREELANCER_TEMPLATES = "select id, name, content from templates where freelancerid = $1 order by id;";
/*
* Name and Statement for prepared statement to select an alias and its route via the alias name
*/
const static std::string PREPARED_STATEMENT_SELECT_ALIAS = "selectAlias";
const static std::string SQL_STATEMENT_SELECT_ALIAS = "select aliasname, route, routeparameter, routevalue from aliasroutes where aliasname = $1;";
/*
* Name and Statement for prepared statement to select an alias and its route via the alias name
*/
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_ALIAS = "selectFreelancerAlias";
const static std::string SQL_STATEMENT_SELECT_FREELANCER_ALIAS = "select aliasname, route from aliasroutes where freelancerid = (select freelancers.id from freelancers where emailaddress = $1);";
/*
* Name and Statement for prepared statement to select an alias and its route via the alias name
*/
const static std::string PREPARED_STATEMENT_DELETE_FREELANCER_ALIAS = "deleteFreelancerAlias";
const static std::string SQL_STATEMENT_DELETE_FREELANCER_ALIAS = "delete from aliasroutes where aliasname = $1 and freelancerid = (select freelancers.id from freelancers where emailaddress = $2);";
/*
* Name and Statement for prepared statement to update the loginvalidationkey of a freelancer via the freelancerID
*/
const static std::string PREPARED_STATEMENT_UPDATE_LOGIN_VALIDATION_KEY = "updateLoginValidationKey";
const static std::string SQL_STATEMENT_UPDATE_LOGIN_VALIDATION_KEY = "update freelancers set loginvalidationkey = $1 where emailaddress = $2;";
/*
* Name and Statement for prepared statement to update the passwordhash of a freelancer via the freelancerEmail
*/
const static std::string PREPARED_STATEMENT_UPDATE_FREELANCER_PASSWORD_HASH = "updateFreelancerPasswordHash";
const static std::string SQL_STATEMENT_UPDATE_FREELANCER_PASSWORD_HASH = "update freelancers set hash = $1, salt = $2 where emailaddress = $3;";
/*
* Name and Statement for prepared statement to check if an email has a reset key
*/
const static std::string PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY = "checkFreelancerResetKey";
const static std::string SQL_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY = "select count(*) from passwordresetkeys where freelanceremail = $1;";
/*
* Name and Statement for prepared statement to select a freelancers emailaddress based on a given password reset key
*/
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY = "selectFreelancerEmailAddressFromPasswordResetKeys";
const static std::string SQL_STATEMENT_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY = "select freelanceremail from passwordresetkeys where passwordresetkey = $1;";
/*
* Name and Statement for prepared statement to check if a reset key is expired
* returns 0 if key not expired
*/
const static std::string PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY_EXPIRED = "checkFreelancerResetKeyExpired";
const static std::string SQL_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY_EXPIRED = "select count(*) from passwordresetkeys where passwordresetkey = $1 and expiration <= CURRENT_TIMESTAMP;";
/*
* Name and Statement for prepared statement to create new reset key
* $1 = email, $2 = resetkey
*/
const static std::string PREPARED_STATEMENT_INSERT_FREELANCER_RESET_KEY = "insertFreelancerResetKey";
const static std::string SQL_STATEMENT_INSERT_FREELANCER_RESET_KEY = "insert into passwordresetkeys values ($1, $2, CURRENT_TIMESTAMP);";
/*
* Name and Statement for prepared statement to delete specific reset key of a freelancer
*/
const static std::string PREPARED_STATEMENT_DELETE_FREELANCER_RESET_KEY = "deleteFreelancerResetKey";
const static std::string SQL_STATEMENT_DELETE_FREELANCER_RESET_KEY = "delete from passwordresetkeys where freelanceremail = $1;";
/*
* Name and Statement for prepared statement to delete specific reset key of a freelancer
*/
const static std::string PREPARED_STATEMENT_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE_LIMITED_AND_OFFSET = "selectFreelancersWithCommissionstateLimitedAndOffset";
const static std::string SQL_STATEMENT_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE_LIMITED_AND_OFFSET = "select id, name, basicInformation , (case when (commissionlimit <= (select count(*) as requestCount from requests where requests.accepted = true and requests.completed = false and requests.freelancerid = freelancers.id group by freelancers.id)) then 'Closed' else 'Open' end) as commissionsclosed from freelancers order by name limit $1 offset $2;";
/*
* Name and Statement for prepared statement to check the email login lock out
*/
const static std::string PREPARED_STATEMENT_SELECT_CHECK_LOGIN_LOCK_OUT = "selectCheckLoginLockOut";
const static std::string SQL_STATEMENT_SELECT_CHECK_LOGIN_LOCK_OUT = "select (COALESCE(expiration, CURRENT_TIMESTAMP) - CURRENT_TIMESTAMP) > INTERVAL '0 second' from loginlockout where email = $1;";
/*
* Name and Statement for prepared statement to get the minutes till expiration of an email login lock out
*/
const static std::string PREPARED_STATEMENT_SELECT_GET_LOGIN_LOCK_OUT_MINUTES = "selectGetLoginLockOutMinutes";
const static std::string SQL_STATEMENT_SELECT_GET_LOGIN_LOCK_OUT_MINUTES = "select to_char((COALESCE(expiration, CURRENT_TIMESTAMP) - CURRENT_TIMESTAMP), 'MI') from loginlockout where email = $1;";
/*
* Name and Statement for prepared statement to increment the login attempts for an email
*/
const static std::string PREPARED_STATEMENT_UPDATE_INCREMENT_LOGIN_LOCK_OUT_ATTEMPTS = "updateIncrementLoginLockOutAttempts";
const static std::string SQL_STATEMENT_UPDATE_INCREMENT_LOGIN_LOCK_OUT_ATTEMPTS = "update loginlockout set attempts = attempts + 1 where email = $1;";
/*
* Name and Statement for prepared statement to try to add a new entry into the login lockout
*/
const static std::string PREPARED_STATEMENT_INSERT_LOGIN_LOCK_OUT = "insertLoginLockOut";
const static std::string SQL_STATEMENT_INSERT_LOGIN_LOCK_OUT = "insert into loginlockout values ($1, 0, CURRENT_TIMESTAMP) on conflict do nothing;";
/*
* Name and Statement for prepared statement to try to check if a login lock out has exceeded the max attempts
*/
const static std::string PREPARED_STATEMENT_SELECT_CHECK_LOGIN_LOCK_OUT_ATTEMPTS = "selectCheckLoginLockOutAttempts";
const static std::string SQL_STATEMENT_SELECT_CHECK_LOGIN_LOCK_OUT_ATTEMPTS = "select count(*) = 1 from loginlockout where email = $1 and attempts >= $2;";
/*
* Name and Statement for prepared statement to update the expiration and reset the login attempts
*/
const static std::string PREPARED_STATEMENT_UPDATE_EXPIRATION_LOGIN_LOCK_OUT = "updateExpirationLoginLockOut";
const static std::string SQL_STATEMENT_UPDATE_EXPIRATION_LOGIN_LOCK_OUT = "update loginlockout set (attempts, expiration) = (0, CURRENT_TIMESTAMP + make_interval(secs => $2)) where email = $1;";
/*
* Name and Statement for prepared statement to try to add a new template to a freelancer
* $1-8 -> name, content, contactdata, contactinformation, currencypreference, priceupfront, priceondeliver, emailaddress
*/
const static std::string PREPARED_STATEMENT_INSERT_FREELANCER_TEMPLATE = "insertFreelancerTemplate";
const static std::string SQL_STATEMENT_INSERT_FREELANCER_TEMPLATE = "INSERT INTO templates(freelancerid, name, content, contactdata, contactinformation, currencypreference, priceupfront, priceondeliver) VALUES((select freelancers.id from freelancers where emailaddress = $8), $1, $2, $3, $4, $5, $6, $7);";
/*
* Name and Statement for prepared statement to update the template of a freelancer
*/
const static std::string PREPARED_STATEMENT_UPDATE_EDIT_FREELANCER_TEMPLATE = "updateEeditFreelancerTemplate";
const static std::string SQL_STATEMENT_UPDATE_EDIT_FREELANCER_TEMPLATE = "UPDATE templates SET (name, content, contactdata, contactinformation, currencypreference, priceupfront, priceondeliver) = ($1, $2, $3, $4, $5, $6, $7) WHERE id = $8 and freelancerid = (select freelancers.id from freelancers where emailaddress = $9);";
/*
* Name and Statement for prepared statement to delete a template with ownership validation
*/
const static std::string PREPARED_STATEMENT_DELETE_FREELANCER_TEMPLATE = "deleteFreelancerTemplate";
const static std::string SQL_STATEMENT_DELETE_FREELANCER_TEMPLATE = "delete from templates where id = $1 and freelancerid = (select freelancers.id from freelancers where emailaddress = $2);";
/*
* IDs of prepared statements
*/
const static int ID_INSERT_ITEM_IN_REQUESTS = 0;
const static int ID_INSERT_NEW_FREELANCER = 1;
const static int ID_SELECT_ITEM_BY_ID = 2;
const static int ID_SELECT_FREELANCER_COMMISSION_STATE = 3;
const static int ID_SELECT_FREELANCER_EMAIL = 4;
const static int ID_SELECT_CHECK_EMAIL_EXISTS = 5;
const static int ID_SELECT_CHECK_FREELANCER_LOGIN_STATE = 6;
const static int ID_SELECT_FREELANCER_SALT = 7;
const static int ID_SELECT_FREELANCER_ID = 8;
const static int ID_SELECT_CHECK_HASH_VALID = 9;
const static int ID_SELECT_FREELANCER = 10;
const static int ID_SELECT_TEMPLATE = 11;
const static int ID_SELECT_TEMPLATE_FLAT = 12;
const static int ID_SELECT_FREELANCER_TEMPLATES = 13;
const static int ID_SELECT_ALIAS = 14;
const static int ID_UPDATE_LOGIN_VALIDATION_KEY = 15;
const static int ID_UPDATE_FREELANCER_PASSWORD_HASH = 16;
const static int ID_SELECT_CHECK_FREELANCER_RESET_KEY = 17;
const static int ID_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY = 18;
const static int ID_SELECT_CHECK_FREELANCER_RESET_KEY_EXPIRED = 19;
const static int ID_INSERT_FREELANCER_RESET_KEY = 20;
const static int ID_DELETE_FREELANCER_RESET_KEY = 21;
const static int ID_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE_LIMITED_AND_OFFSET = 22;
const static int ID_SELECT_CHECK_LOGIN_LOCK_OUT = 23;
const static int ID_SELECT_GET_LOGIN_LOCK_OUT_MINUTES = 24;
const static int ID_UPDATE_INCREMENT_LOGIN_LOCK_OUT_ATTEMPTS = 25;
const static int ID_INSERT_LOGIN_LOCK_OUT = 26;
const static int ID_SELECT_CHECK_LOGIN_LOCK_OUT_ATTEMPTS = 27;
const static int ID_UPDATE_EXPIRATION_LOGIN_LOCK_OUT = 28;
const static int ID_INSERT_FREELANCER_TEMPLATE = 29;
const static int ID_DELETE_FREELANCER_TEMPLATE = 30;
const static int ID_UPDATE_EDIT_FREELANCER_TEMPLATE = 31;
const static int ID_SELECT_FREELANCER_ALIAS = 32;
const static int ID_DELETE_FREELANCER_ALIAS = 33;
/*
* Easy access to prepared statements via prepared statement name
*/
const static std::unordered_map<std::string, std::string> preparedStatementCollection = {
{PREPARED_STATEMENT_INSERT_ITEM_IN_REQUESTS, SQL_STATEMENT_INSERT_ITEM_IN_REQUESTS},
{PREPARED_STATEMENT_INSERT_NEW_FREELANCER, SQL_STATEMENT_INSERT_NEW_FREELANCER},
{PREPARED_STATEMENT_SELECT_ITEM_BY_ID, SQL_STATEMENT_SELECT_ITEM_BY_ID},
{PREPARED_STATEMENT_SELECT_FREELANCER_COMMISSION_STATE, SQL_STATEMENT_SELECT_FREELANCER_COMMISSION_STATE},
{PREPARED_STATEMENT_SELECT_FREELANCER_EMAIL, SQL_STATEMENT_SELECT_FREELANCER_EMAIL},
{PREPARED_STATEMENT_SELECT_CHECK_EMAIL_EXISTS, SQL_STATEMENT_SELECT_CHECK_EMAIL_EXISTS},
{PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_LOGIN_STATE, SQL_STATEMENT_SELECT_CHECK_FREELANCER_LOGIN_STATE},
{PREPARED_STATEMENT_SELECT_FREELANCER_SALT, SQL_STATEMENT_SELECT_FREELANCER_SALT},
{PREPARED_STATEMENT_SELECT_FREELANCER_ID, SQL_STATEMENT_SELECT_FREELANCER_ID},
{PREPARED_STATEMENT_SELECT_CHECK_HASH_VALID, SQL_STATEMENT_SELECT_CHECK_HASH_VALID},
{PREPARED_STATEMENT_SELECT_FREELANCER, SQL_STATEMENT_SELECT_FREELANCER},
{PREPARED_STATEMENT_SELECT_TEMPLATE, SQL_STATEMENT_SELECT_TEMPLATE},
{PREPARED_STATEMENT_SELECT_TEMPLATE_FLAT, SQL_STATEMENT_SELECT_TEMPLATE_FLAT},
{PREPARED_STATEMENT_SELECT_FREELANCER_TEMPLATES, SQL_STATEMENT_SELECT_FREELANCER_TEMPLATES},
{PREPARED_STATEMENT_SELECT_ALIAS, SQL_STATEMENT_SELECT_ALIAS},
{PREPARED_STATEMENT_UPDATE_LOGIN_VALIDATION_KEY, SQL_STATEMENT_UPDATE_LOGIN_VALIDATION_KEY},
{PREPARED_STATEMENT_UPDATE_FREELANCER_PASSWORD_HASH, SQL_STATEMENT_UPDATE_FREELANCER_PASSWORD_HASH},
{PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY, SQL_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY},
{PREPARED_STATEMENT_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY, SQL_STATEMENT_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY},
{PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY_EXPIRED, SQL_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY_EXPIRED},
{PREPARED_STATEMENT_INSERT_FREELANCER_RESET_KEY, SQL_STATEMENT_INSERT_FREELANCER_RESET_KEY},
{PREPARED_STATEMENT_DELETE_FREELANCER_RESET_KEY, SQL_STATEMENT_DELETE_FREELANCER_RESET_KEY},
{PREPARED_STATEMENT_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE_LIMITED_AND_OFFSET, SQL_STATEMENT_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE_LIMITED_AND_OFFSET},
{PREPARED_STATEMENT_SELECT_CHECK_LOGIN_LOCK_OUT, SQL_STATEMENT_SELECT_CHECK_LOGIN_LOCK_OUT},
{PREPARED_STATEMENT_SELECT_GET_LOGIN_LOCK_OUT_MINUTES, SQL_STATEMENT_SELECT_GET_LOGIN_LOCK_OUT_MINUTES},
{PREPARED_STATEMENT_UPDATE_INCREMENT_LOGIN_LOCK_OUT_ATTEMPTS, SQL_STATEMENT_UPDATE_INCREMENT_LOGIN_LOCK_OUT_ATTEMPTS},
{PREPARED_STATEMENT_INSERT_LOGIN_LOCK_OUT, SQL_STATEMENT_INSERT_LOGIN_LOCK_OUT},
{PREPARED_STATEMENT_SELECT_CHECK_LOGIN_LOCK_OUT_ATTEMPTS, SQL_STATEMENT_SELECT_CHECK_LOGIN_LOCK_OUT_ATTEMPTS},
{PREPARED_STATEMENT_UPDATE_EXPIRATION_LOGIN_LOCK_OUT, SQL_STATEMENT_UPDATE_EXPIRATION_LOGIN_LOCK_OUT},
{PREPARED_STATEMENT_INSERT_FREELANCER_TEMPLATE, SQL_STATEMENT_INSERT_FREELANCER_TEMPLATE},
{PREPARED_STATEMENT_DELETE_FREELANCER_TEMPLATE, SQL_STATEMENT_DELETE_FREELANCER_TEMPLATE},
{PREPARED_STATEMENT_UPDATE_EDIT_FREELANCER_TEMPLATE, SQL_STATEMENT_UPDATE_EDIT_FREELANCER_TEMPLATE},
{PREPARED_STATEMENT_SELECT_FREELANCER_ALIAS, SQL_STATEMENT_SELECT_FREELANCER_ALIAS},
{PREPARED_STATEMENT_DELETE_FREELANCER_ALIAS, SQL_STATEMENT_DELETE_FREELANCER_ALIAS},
};
/*
* Easy access to prepared statement name via int
*/
const static std::unordered_map<int, std::string> preparedStatementNameCollection = {
{ID_INSERT_ITEM_IN_REQUESTS, PREPARED_STATEMENT_INSERT_ITEM_IN_REQUESTS},
{ID_INSERT_NEW_FREELANCER, PREPARED_STATEMENT_INSERT_NEW_FREELANCER},
{ID_SELECT_ITEM_BY_ID, PREPARED_STATEMENT_SELECT_ITEM_BY_ID},
{ID_SELECT_FREELANCER_COMMISSION_STATE, PREPARED_STATEMENT_SELECT_FREELANCER_COMMISSION_STATE},
{ID_SELECT_FREELANCER_EMAIL, PREPARED_STATEMENT_SELECT_FREELANCER_EMAIL},
{ID_SELECT_CHECK_EMAIL_EXISTS, PREPARED_STATEMENT_SELECT_CHECK_EMAIL_EXISTS},
{ID_SELECT_CHECK_FREELANCER_LOGIN_STATE, PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_LOGIN_STATE},
{ID_SELECT_FREELANCER_SALT, PREPARED_STATEMENT_SELECT_FREELANCER_SALT},
{ID_SELECT_FREELANCER_ID, PREPARED_STATEMENT_SELECT_FREELANCER_ID},
{ID_SELECT_CHECK_HASH_VALID, PREPARED_STATEMENT_SELECT_CHECK_HASH_VALID},
{ID_SELECT_FREELANCER, PREPARED_STATEMENT_SELECT_FREELANCER},
{ID_SELECT_TEMPLATE, PREPARED_STATEMENT_SELECT_TEMPLATE},
{ID_SELECT_TEMPLATE_FLAT, PREPARED_STATEMENT_SELECT_TEMPLATE_FLAT},
{ID_SELECT_FREELANCER_TEMPLATES, PREPARED_STATEMENT_SELECT_FREELANCER_TEMPLATES},
{ID_SELECT_ALIAS, PREPARED_STATEMENT_SELECT_ALIAS},
{ID_UPDATE_LOGIN_VALIDATION_KEY, PREPARED_STATEMENT_UPDATE_LOGIN_VALIDATION_KEY},
{ID_UPDATE_FREELANCER_PASSWORD_HASH, PREPARED_STATEMENT_UPDATE_FREELANCER_PASSWORD_HASH},
{ID_SELECT_CHECK_FREELANCER_RESET_KEY, PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY},
{ID_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY, PREPARED_STATEMENT_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY},
{ID_SELECT_CHECK_FREELANCER_RESET_KEY_EXPIRED, PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY_EXPIRED},
{ID_INSERT_FREELANCER_RESET_KEY, PREPARED_STATEMENT_INSERT_FREELANCER_RESET_KEY},
{ID_DELETE_FREELANCER_RESET_KEY, PREPARED_STATEMENT_DELETE_FREELANCER_RESET_KEY},
{ID_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE_LIMITED_AND_OFFSET, PREPARED_STATEMENT_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE_LIMITED_AND_OFFSET},
{ID_SELECT_CHECK_LOGIN_LOCK_OUT, PREPARED_STATEMENT_SELECT_CHECK_LOGIN_LOCK_OUT},
{ID_SELECT_GET_LOGIN_LOCK_OUT_MINUTES, PREPARED_STATEMENT_SELECT_GET_LOGIN_LOCK_OUT_MINUTES},
{ID_UPDATE_INCREMENT_LOGIN_LOCK_OUT_ATTEMPTS, PREPARED_STATEMENT_UPDATE_INCREMENT_LOGIN_LOCK_OUT_ATTEMPTS},
{ID_INSERT_LOGIN_LOCK_OUT, PREPARED_STATEMENT_INSERT_LOGIN_LOCK_OUT},
{ID_SELECT_CHECK_LOGIN_LOCK_OUT_ATTEMPTS, PREPARED_STATEMENT_SELECT_CHECK_LOGIN_LOCK_OUT_ATTEMPTS},
{ID_UPDATE_EXPIRATION_LOGIN_LOCK_OUT, PREPARED_STATEMENT_UPDATE_EXPIRATION_LOGIN_LOCK_OUT},
{ID_INSERT_FREELANCER_TEMPLATE, PREPARED_STATEMENT_INSERT_FREELANCER_TEMPLATE},
{ID_DELETE_FREELANCER_TEMPLATE, PREPARED_STATEMENT_DELETE_FREELANCER_TEMPLATE},
{ID_UPDATE_EDIT_FREELANCER_TEMPLATE, PREPARED_STATEMENT_UPDATE_EDIT_FREELANCER_TEMPLATE},
{ID_SELECT_FREELANCER_ALIAS, PREPARED_STATEMENT_SELECT_FREELANCER_ALIAS},
{ID_DELETE_FREELANCER_ALIAS, PREPARED_STATEMENT_DELETE_FREELANCER_ALIAS},
};
/*
* Statement to remove expired reset keys
*/
const static std::string SQL_STATEMENT_PURGE_EXPIRED_FREELANCER_RESET_KEYS = "delete from passwordresetkeys where expiration <= CURRENT_TIMESTAMP;";
/*
* Statement to remove expired login lockouts
*/
const static std::string SQL_STATEMENT_PURGE_EXPIRED_LOGIN_LOCKOUTS = "delete from loginlockout where expiration <= CURRENT_TIMESTAMP;";
/*
* Selects freelancers, their basicInfo and if the commissions are closed/open ordered by name.
* Delivers if the commission limit has been reached and if the commissions are closed based on the accepted/completed state of the freelancers requests
*/
const static std::string SQL_Statement_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE = "select id, name, basicInformation , (case when (commissionlimit <= (select count(*) as requestCount from requests where requests.accepted = true and requests.completed = false and requests.freelancerid = freelancers.id group by freelancers.id)) then 'Closed' else 'Open' end) as commissionsclosed from freelancers order by name;";
/*
* Selects freelancer count
*/
const static std::string SQL_Statement_SELECT_FREELANCERS_COUNT = "select count(*) from freelancers;";
}
#endif