fixed sql syntax and logic
This commit is contained in:
parent
fd2e54c845
commit
0c146c201e
|
|
@ -45,14 +45,14 @@ const insertEndpointsQuery = () => {
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateEndpointsQuery = () => {
|
const updateEndpointsQuery = (route) => {
|
||||||
const routeCondition = route ? 'route = :route,' : '';
|
const routeCondition = route ? 'route = :route,' : '';
|
||||||
return `
|
return `
|
||||||
UPDATE mydb.endpoints
|
UPDATE mydb.endpoints
|
||||||
SET
|
SET
|
||||||
${routeCondition}
|
${routeCondition}
|
||||||
uuid = :uuid
|
uuid = :uuid
|
||||||
WHERE uuid = :uuid;
|
WHERE uuid = :uuid
|
||||||
AND deleted IS NULL;
|
AND deleted IS NULL;
|
||||||
SELECT * FROM mydb.endpoints WHERE uuid = :uuid;
|
SELECT * FROM mydb.endpoints WHERE uuid = :uuid;
|
||||||
`
|
`
|
||||||
|
|
@ -61,10 +61,9 @@ const updateEndpointsQuery = () => {
|
||||||
const softDeleteEndpointsQuery = () => {
|
const softDeleteEndpointsQuery = () => {
|
||||||
return `
|
return `
|
||||||
UPDATE mydb.endpoints
|
UPDATE mydb.endpoints
|
||||||
SET deleted = :now, deletedBy = :deletedBy
|
SET deleted = :deleted, deletedBy = :deletedBy
|
||||||
WHERE uuid = :uuid;
|
WHERE uuid = :uuid
|
||||||
AND deleted IS NULL;
|
AND deleted IS NULL
|
||||||
SELECT * FROM mydb.endpoints WHERE uuid = :uuid;
|
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import { pagination } from '../../utils/pagination.js'
|
import { pagination } from '../../utils/pagination.js'
|
||||||
|
|
||||||
const _rolesHasPermissionsQuery = (_pagination = '') => ({count}) => ({uuid, permission_uuid, roleName}) => {
|
const _rolesHasPermissionsQuery = (_pagination = '') => ({count}) => ({uuid, fk_permission, fk_role, roleName}) => {
|
||||||
|
const uuidCondition = uuid ? 'AND r.uuid = :uuid' : '';
|
||||||
const roleNameCondition = roleName ? 'AND fk_role = (SELECT id from mydb.roles WHERE name = :roleName)' : '';
|
const roleNameCondition = roleName ? 'AND fk_role = (SELECT id from mydb.roles WHERE name = :roleName)' : '';
|
||||||
const uuidCondition = uuid ? 'AND fk_role = (SELECT id from mydb.roles WHERE uuid = :roleUuid)' : '';
|
const roleUuidCondition = fk_role ? 'AND fk_role = (SELECT id from mydb.roles WHERE uuid = :fk_role)' : '';
|
||||||
const permissionsUuidCondition = permission_uuid ? 'AND fk_permission = (SELECT id from mydb.permissions WHERE uuid = :permissionUuid)' : '';
|
const permissionsUuidCondition = fk_permission ? 'AND fk_permission = (SELECT id from mydb.permissions WHERE uuid = :fk_permission)' : '';
|
||||||
return `
|
return `
|
||||||
SELECT
|
SELECT
|
||||||
${count ||
|
${count ||
|
||||||
|
|
@ -32,6 +33,7 @@ const _rolesHasPermissionsQuery = (_pagination = '') => ({count}) => ({uuid, per
|
||||||
${uuidCondition}
|
${uuidCondition}
|
||||||
${permissionsUuidCondition}
|
${permissionsUuidCondition}
|
||||||
${roleNameCondition}
|
${roleNameCondition}
|
||||||
|
${roleUuidCondition}
|
||||||
${_pagination}
|
${_pagination}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
@ -52,8 +54,8 @@ const insertRolesHasPermissionsQuery = () => {
|
||||||
)
|
)
|
||||||
VALUES (
|
VALUES (
|
||||||
:uuid,
|
:uuid,
|
||||||
(SELECT id FROM mydb.roles WHERE uuid = :roleUuid),
|
(SELECT id FROM mydb.roles WHERE uuid = :fk_role),
|
||||||
(SELECT id FROM mydb.permissions WHERE uuid = :permissionUuid),
|
(SELECT id FROM mydb.permissions WHERE uuid = :fk_permission),
|
||||||
:now,
|
:now,
|
||||||
:createdBy
|
:createdBy
|
||||||
);
|
);
|
||||||
|
|
@ -69,8 +71,8 @@ const insertRolesHasPermissionsQuery = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const modifyRolesHasPermissionsQuery = (roleUuid, permissionUuid) => {
|
const modifyRolesHasPermissionsQuery = (roleUuid, permissionUuid) => {
|
||||||
const roleUuidCondition = roleUuid ? 'fk_role = (SELECT id from mydb.roles WHERE uuid = :roleUuid),' : '';
|
const roleUuidCondition = roleUuid ? 'fk_role = (SELECT id from mydb.roles WHERE uuid = :fk_role),' : '';
|
||||||
const permissionUuidCondition = permissionUuid ? 'fk_permission = (SELECT id from mydb.permissions WHERE uuid = :permissionUuid),' : '';
|
const permissionUuidCondition = permissionUuid ? 'fk_permission = (SELECT id from mydb.permissions WHERE uuid = :fk_permission),' : '';
|
||||||
return `
|
return `
|
||||||
UPDATE
|
UPDATE
|
||||||
mydb.roles_has_permissions as roles_has_permissions
|
mydb.roles_has_permissions as roles_has_permissions
|
||||||
|
|
@ -91,14 +93,11 @@ const softDeleteRolesHasPermissionsQuery = () => {
|
||||||
UPDATE
|
UPDATE
|
||||||
mydb.roles_has_permissions as roles_has_permissions
|
mydb.roles_has_permissions as roles_has_permissions
|
||||||
SET
|
SET
|
||||||
deleted = :now, deletedBy = :deletedBy
|
deleted = :deleted, deletedBy = :deletedBy
|
||||||
WHERE
|
WHERE
|
||||||
roles_has_permissions.fk_role = (SELECT id FROM mydb.roles WHERE uuid = :roleUuid)
|
roles_has_permissions.uuid = :uuid
|
||||||
AND
|
|
||||||
roles_has_permissions.fk_permission = (SELECT id FROM mydb.permissions WHERE uuid = :permissionUuid)
|
|
||||||
AND
|
AND
|
||||||
roles_has_permissions.deleted IS NULL
|
roles_has_permissions.deleted IS NULL
|
||||||
SELECT * FROM mydb.roles_has_permissions WHERE uuid = :uuid;
|
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue