minor fix regarding query sintaxis and cohesion
This commit is contained in:
parent
f06ef22eb5
commit
9f15b06632
|
|
@ -1,4 +1,4 @@
|
||||||
import { pagination } from "../../utils/pagination";
|
import { pagination } from "../../utils/pagination.js";
|
||||||
|
|
||||||
const _endpointsQuery = (_pagination) => ({ count }) => ({ uuid, route, method }) => {
|
const _endpointsQuery = (_pagination) => ({ count }) => ({ uuid, route, method }) => {
|
||||||
const uuidCondition = uuid ? "AND uuid = :uuid " : "";
|
const uuidCondition = uuid ? "AND uuid = :uuid " : "";
|
||||||
|
|
@ -12,7 +12,7 @@ const _endpointsQuery = (_pagination) => ({ count }) => ({ uuid, route, method }
|
||||||
WHERE
|
WHERE
|
||||||
e.created <= :now
|
e.created <= :now
|
||||||
AND
|
AND
|
||||||
(e.created > :now OR e.deleted IS NULL)
|
(e.deleted > :now OR e.deleted IS NULL)
|
||||||
AND
|
AND
|
||||||
true
|
true
|
||||||
${uuidCondition}
|
${uuidCondition}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import { pagination } from '../../utils/pagination.js'
|
import { pagination } from '../../utils/pagination.js'
|
||||||
|
|
||||||
const _permissionsQuery = (_pagination) => ({count}) => ({uuid, name, action, endpoint}) => {
|
const _permissionsQuery = (_pagination) => ({count}) => ({uuid, action, endpoint}) => {
|
||||||
const uuidCondition = uuid ? 'AND uuid = :uuid ' : '';
|
const uuidCondition = uuid ? 'AND uuid = :uuid ' : '';
|
||||||
const nameCondition = name ? 'AND name = :name ' : '';
|
|
||||||
const actionCondition = action ? 'AND action = :action ' : '';
|
const actionCondition = action ? 'AND action = :action ' : '';
|
||||||
const endpointCondition = endpoint ? 'AND fk_endpoint = (SELECT id from mydb.endpoints WHERE route = :endpoint)' : '';
|
const endpointCondition = endpoint ? 'AND fk_endpoint = (SELECT id from mydb.endpoints WHERE route = :endpoint)' : '';
|
||||||
return `
|
return `
|
||||||
|
|
@ -15,12 +14,9 @@ const _permissionsQuery = (_pagination) => ({count}) => ({uuid, name, action, en
|
||||||
mydb.endpoints as e ON p.fk_endpoint = e.id
|
mydb.endpoints as e ON p.fk_endpoint = e.id
|
||||||
AND e.created <= :now
|
AND e.created <= :now
|
||||||
AND (e.deleted > :now OR e.deleted IS NULL)
|
AND (e.deleted > :now OR e.deleted IS NULL)
|
||||||
WHERE
|
|
||||||
p.created <= :now
|
|
||||||
WHERE
|
|
||||||
p.created <= :now
|
p.created <= :now
|
||||||
AND
|
AND
|
||||||
(p.created > :now OR p.deleted IS NULL)
|
(p.deleted > :now OR p.deleted IS NULL)
|
||||||
AND
|
AND
|
||||||
true
|
true
|
||||||
${uuidCondition}
|
${uuidCondition}
|
||||||
|
|
@ -58,14 +54,12 @@ const insertPermissionsQuery = () => {
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
const modifyPermissionsQuery = () => {
|
const modifyPermissionsQuery = (action, endpoint) => {
|
||||||
const nameCondition = name ? 'name = :name ' : '';
|
|
||||||
const actionCondition = action ? 'action = :action ' : '';
|
const actionCondition = action ? 'action = :action ' : '';
|
||||||
const endpointCondition = endpoint ? 'fk_endpoint = (SELECT id from mydb.endpoints WHERE route = :endpoint)' : '';
|
const endpointCondition = endpoint ? 'fk_endpoint = (SELECT id from mydb.endpoints WHERE route = :endpoint)' : '';
|
||||||
return `
|
return `
|
||||||
UPDATE mydb.permissions
|
UPDATE mydb.permissions
|
||||||
SET
|
SET
|
||||||
${nameCondition}
|
|
||||||
${actionCondition}
|
${actionCondition}
|
||||||
${endpointCondition}
|
${endpointCondition}
|
||||||
WHERE
|
WHERE
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ const _roleSelectQuery = (_pagination = '') =>
|
||||||
WHERE
|
WHERE
|
||||||
r.created <= :now
|
r.created <= :now
|
||||||
AND
|
AND
|
||||||
(r.created > :now OR r.deleted IS NULL)
|
(r.deleted > :now OR r.deleted IS NULL)
|
||||||
AND
|
AND
|
||||||
true
|
true
|
||||||
${uuidCondition}
|
${uuidCondition}
|
||||||
|
|
@ -119,4 +119,4 @@ export {
|
||||||
modifyRoleQuery,
|
modifyRoleQuery,
|
||||||
deleteRoleQuery,
|
deleteRoleQuery,
|
||||||
softDeleteRoleQuery
|
softDeleteRoleQuery
|
||||||
};
|
};
|
||||||
|
|
@ -12,7 +12,7 @@ const _rolesHasPermissionsQuery = (_pagination) => ({count}) => ({uuid, permissi
|
||||||
r2.uuid as role_uuid,
|
r2.uuid as role_uuid,
|
||||||
p.action as permission_action,
|
p.action as permission_action,
|
||||||
p.uuid as permission_uuid,
|
p.uuid as permission_uuid,
|
||||||
p.resource_type as permission_resource_type`}
|
p.fk_endpoint as permission_endpoint`}
|
||||||
FROM
|
FROM
|
||||||
mydb.roles_has_permissions as r
|
mydb.roles_has_permissions as r
|
||||||
JOIN
|
JOIN
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import { pagination } from "../../utils/pagination.js";
|
||||||
*/
|
*/
|
||||||
const _userListSelectQuery = (_pagination = '') =>
|
const _userListSelectQuery = (_pagination = '') =>
|
||||||
({ count }) =>
|
({ count }) =>
|
||||||
({ uuid, username, loginUsername, uuidList, email, role }) => {
|
({ uuid, username, loginUsername, uuidList, email, role, roleName }) => {
|
||||||
const uuidCondition = uuid ? 'AND users.uuid = :uuid ' : '';
|
const uuidCondition = uuid ? 'AND users.uuid = :uuid ' : '';
|
||||||
//for uuidList, we use IN clause to check if the uuid is in the list of uuids passed
|
//for uuidList, we use IN clause to check if the uuid is in the list of uuids passed
|
||||||
const uuidListCondition = uuidList ? 'AND users.uuid in(:uuidList)' : ''
|
const uuidListCondition = uuidList ? 'AND users.uuid in(:uuidList)' : ''
|
||||||
|
|
@ -17,6 +17,7 @@ const _userListSelectQuery = (_pagination = '') =>
|
||||||
const usernameCondition = username ? `AND users.username LIKE CONCAT('%',:username,'%')` : '';
|
const usernameCondition = username ? `AND users.username LIKE CONCAT('%',:username,'%')` : '';
|
||||||
const emailCondition = email ? 'AND users.email = :email ' : '';
|
const emailCondition = email ? 'AND users.email = :email ' : '';
|
||||||
const roleCondition = role ? 'AND users.fk_role = :role ' : '';
|
const roleCondition = role ? 'AND users.fk_role = :role ' : '';
|
||||||
|
const roleNameCondition = roleName ? 'AND users.fk_role = (SELECT id FROM mydb.roles WHERE name = :roleName)' : '';
|
||||||
return `
|
return `
|
||||||
SELECT
|
SELECT
|
||||||
${count || `users.*, r.name AS role`}
|
${count || `users.*, r.name AS role`}
|
||||||
|
|
@ -26,7 +27,7 @@ const _userListSelectQuery = (_pagination = '') =>
|
||||||
WHERE
|
WHERE
|
||||||
users.created <= :now
|
users.created <= :now
|
||||||
AND
|
AND
|
||||||
(users.created > :now OR users.deleted IS NULL)
|
(users.deleted > :now OR users.deleted IS NULL)
|
||||||
AND
|
AND
|
||||||
true
|
true
|
||||||
${uuidCondition}
|
${uuidCondition}
|
||||||
|
|
@ -35,6 +36,7 @@ const _userListSelectQuery = (_pagination = '') =>
|
||||||
${emailCondition}
|
${emailCondition}
|
||||||
${roleCondition}
|
${roleCondition}
|
||||||
${loginUsernameCondition}
|
${loginUsernameCondition}
|
||||||
|
${roleNameCondition}
|
||||||
${_pagination}
|
${_pagination}
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
@ -88,12 +90,12 @@ const insertUserQuery = () => {
|
||||||
* @returns {String} UPDATE query
|
* @returns {String} UPDATE query
|
||||||
*/
|
*/
|
||||||
const modifyUserQuery = ({ username, email, role }) => {
|
const modifyUserQuery = ({ username, email, role }) => {
|
||||||
const usernameCondition = username ? 'username = :username, ' : '';
|
const usernameCondition = username ? ':username, ' : '';
|
||||||
const passwordCondition = password ? 'password = :password, ' : '';
|
const passwordCondition = password ? ':password, ' : '';
|
||||||
const emailCondition = email ? 'email = :email, ' : '';
|
const emailCondition = email ? ':email, ' : '';
|
||||||
const roleCondition = role ? 'fk_role = (SELECT id FROM mydb.roles WHERE name = :role) ' : '';
|
const roleCondition = role ? '(SELECT id FROM mydb.roles WHERE name = :role) ' : '';
|
||||||
const lastLoginDateCondition = lastLoginDate ? 'last_login_date = :lastLoginDate, ' : '';
|
const lastLoginDateCondition = lastLoginDate ? ':lastLoginDate, ' : '';
|
||||||
const userStatusCondition = userStatus ? 'user_status = :userStatus, ' : '';
|
const userStatusCondition = userStatus ? ':userStatus, ' : '';
|
||||||
|
|
||||||
return `
|
return `
|
||||||
UPDATE
|
UPDATE
|
||||||
|
|
@ -147,4 +149,4 @@ export {
|
||||||
modifyUserQuery,
|
modifyUserQuery,
|
||||||
deleteUserQuery,
|
deleteUserQuery,
|
||||||
softDeleteUserQuery
|
softDeleteUserQuery
|
||||||
};
|
};
|
||||||
Loading…
Reference in New Issue