query and build fix
This commit is contained in:
parent
e30a3bf3c1
commit
2dac417cb3
|
|
@ -1,6 +1,6 @@
|
||||||
export default {
|
export default {
|
||||||
environment: 'production',
|
environment: 'production',
|
||||||
port: 3005,
|
port: 3000,
|
||||||
bodyLimit: '300kb',
|
bodyLimit: '300kb',
|
||||||
db: {
|
db: {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,11 @@ import config from './config/index.js'
|
||||||
import routes from './routes/index.js'
|
import routes from './routes/index.js'
|
||||||
import { error404, errorHandler } from './utils/errors.js'
|
import { error404, errorHandler } from './utils/errors.js'
|
||||||
import { getRoutes } from './utils/links.js'
|
import { getRoutes } from './utils/links.js'
|
||||||
|
/*import { fileURLToPath } from 'node:url'
|
||||||
|
import { dirname } from 'node:path'
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url)
|
||||||
|
const __dirname = dirname(__filename)*/
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ const _endpointsQuery = (_pagination = '') => ({ count }) => ({ uuid, route, met
|
||||||
SELECT
|
SELECT
|
||||||
${count || `*`}
|
${count || `*`}
|
||||||
FROM
|
FROM
|
||||||
mydb.endpoints as e
|
acloc.endpoints as e
|
||||||
WHERE
|
WHERE
|
||||||
e.created <= :now
|
e.created <= :now
|
||||||
AND
|
AND
|
||||||
|
|
@ -29,7 +29,7 @@ const countEndpointsQuery = rest =>
|
||||||
|
|
||||||
const insertEndpointsQuery = () => {
|
const insertEndpointsQuery = () => {
|
||||||
return `
|
return `
|
||||||
INSERT INTO mydb.endpoints (
|
INSERT INTO acloc.endpoints (
|
||||||
uuid,
|
uuid,
|
||||||
route,
|
route,
|
||||||
created,
|
created,
|
||||||
|
|
@ -41,26 +41,26 @@ const insertEndpointsQuery = () => {
|
||||||
:now,
|
:now,
|
||||||
:createdBy
|
:createdBy
|
||||||
);
|
);
|
||||||
SELECT * FROM mydb.endpoints WHERE uuid = :uuid;
|
SELECT * FROM acloc.endpoints WHERE uuid = :uuid;
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateEndpointsQuery = (route) => {
|
const updateEndpointsQuery = (route) => {
|
||||||
const routeCondition = route ? 'route = :route,' : '';
|
const routeCondition = route ? 'route = :route,' : '';
|
||||||
return `
|
return `
|
||||||
UPDATE mydb.endpoints
|
UPDATE acloc.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 acloc.endpoints WHERE uuid = :uuid;
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
const softDeleteEndpointsQuery = () => {
|
const softDeleteEndpointsQuery = () => {
|
||||||
return `
|
return `
|
||||||
UPDATE mydb.endpoints
|
UPDATE acloc.endpoints
|
||||||
SET deleted = :deleted, deletedBy = :deletedBy
|
SET deleted = :deleted, deletedBy = :deletedBy
|
||||||
WHERE uuid = :uuid
|
WHERE uuid = :uuid
|
||||||
AND deleted IS NULL
|
AND deleted IS NULL
|
||||||
|
|
@ -69,9 +69,9 @@ const softDeleteEndpointsQuery = () => {
|
||||||
|
|
||||||
const deleteEndpointsQuery = () => {
|
const deleteEndpointsQuery = () => {
|
||||||
return `
|
return `
|
||||||
DELETE FROM mydb.endpoints
|
DELETE FROM acloc.endpoints
|
||||||
WHERE uuid = :uuid;
|
WHERE uuid = :uuid;
|
||||||
SELECT * FROM mydb.endpoints WHERE uuid = :uuid;
|
SELECT * FROM acloc.endpoints WHERE uuid = :uuid;
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,15 @@ import { pagination } from '../../utils/pagination.js'
|
||||||
const _permissionsQuery = (_pagination = '') => ({count}) => ({uuid, action, endpoint}) => {
|
const _permissionsQuery = (_pagination = '') => ({count}) => ({uuid, action, endpoint}) => {
|
||||||
const uuidCondition = uuid ? 'AND uuid = :uuid ' : '';
|
const uuidCondition = uuid ? 'AND uuid = :uuid ' : '';
|
||||||
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 acloc.endpoints WHERE route = :endpoint)' : '';
|
||||||
return `
|
return `
|
||||||
SELECT
|
SELECT
|
||||||
${count ||
|
${count ||
|
||||||
`*`}
|
`*`}
|
||||||
FROM
|
FROM
|
||||||
mydb.permissions as p
|
acloc.permissions as p
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
mydb.endpoints as e ON p.fk_endpoint = e.id
|
acloc.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)
|
||||||
p.created <= :now
|
p.created <= :now
|
||||||
|
|
@ -33,7 +33,7 @@ const countPermissionsQuery = rest =>
|
||||||
|
|
||||||
const insertPermissionsQuery = () => {
|
const insertPermissionsQuery = () => {
|
||||||
return `
|
return `
|
||||||
INSERT INTO mydb.permissions (
|
INSERT INTO acloc.permissions (
|
||||||
uuid,
|
uuid,
|
||||||
name,
|
name,
|
||||||
action,
|
action,
|
||||||
|
|
@ -45,19 +45,19 @@ const insertPermissionsQuery = () => {
|
||||||
:uuid,
|
:uuid,
|
||||||
:name,
|
:name,
|
||||||
:action,
|
:action,
|
||||||
(SELECT id FROM mydb.endpoints WHERE route = :endpoint),
|
(SELECT id FROM acloc.endpoints WHERE route = :endpoint),
|
||||||
:now,
|
:now,
|
||||||
:createdBy
|
:createdBy
|
||||||
);
|
);
|
||||||
SELECT * FROM mydb.permissions WHERE uuid = :uuid;
|
SELECT * FROM acloc.permissions WHERE uuid = :uuid;
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
const modifyPermissionsQuery = (action, endpoint) => {
|
const modifyPermissionsQuery = (action, endpoint) => {
|
||||||
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 acloc.endpoints WHERE route = :endpoint),' : '';
|
||||||
return `
|
return `
|
||||||
UPDATE mydb.permissions
|
UPDATE acloc.permissions
|
||||||
SET
|
SET
|
||||||
${actionCondition}
|
${actionCondition}
|
||||||
${endpointCondition}
|
${endpointCondition}
|
||||||
|
|
@ -66,21 +66,21 @@ const modifyPermissionsQuery = (action, endpoint) => {
|
||||||
permissions.uuid = :uuid
|
permissions.uuid = :uuid
|
||||||
AND
|
AND
|
||||||
permissions.deleted IS NULL;
|
permissions.deleted IS NULL;
|
||||||
SELECT * FROM mydb.permissions WHERE uuid = :uuid;
|
SELECT * FROM acloc.permissions WHERE uuid = :uuid;
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
const softDeletePermissionsQuery = () => {
|
const softDeletePermissionsQuery = () => {
|
||||||
return `
|
return `
|
||||||
UPDATE
|
UPDATE
|
||||||
mydb.permissions
|
acloc.permissions
|
||||||
SET
|
SET
|
||||||
deleted = :now, deletedBy = :deletedBy
|
deleted = :now, deletedBy = :deletedBy
|
||||||
WHERE
|
WHERE
|
||||||
permissions.uuid = :uuid
|
permissions.uuid = :uuid
|
||||||
AND
|
AND
|
||||||
permissions.deleted IS NULL
|
permissions.deleted IS NULL
|
||||||
SELECT * FROM mydb.permissions WHERE uuid = :uuid;
|
SELECT * FROM acloc.permissions WHERE uuid = :uuid;
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ const _roleSelectQuery = (_pagination = '') =>
|
||||||
SELECT
|
SELECT
|
||||||
${count || `*`}
|
${count || `*`}
|
||||||
FROM
|
FROM
|
||||||
mydb.roles as r
|
acloc.roles as r
|
||||||
WHERE
|
WHERE
|
||||||
r.created <= :now
|
r.created <= :now
|
||||||
AND
|
AND
|
||||||
|
|
@ -49,7 +49,7 @@ const countRoleQuery = rest =>
|
||||||
*/
|
*/
|
||||||
const insertRoleQuery = () => {
|
const insertRoleQuery = () => {
|
||||||
return `
|
return `
|
||||||
INSERT INTO mydb.roles (
|
INSERT INTO acloc.roles (
|
||||||
uuid,
|
uuid,
|
||||||
name,
|
name,
|
||||||
created,
|
created,
|
||||||
|
|
@ -61,7 +61,7 @@ const insertRoleQuery = () => {
|
||||||
:now,
|
:now,
|
||||||
:createdBy
|
:createdBy
|
||||||
);
|
);
|
||||||
SELECT * FROM mydb.roles WHERE uuid = :uuid;
|
SELECT * FROM acloc.roles WHERE uuid = :uuid;
|
||||||
`
|
`
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -74,7 +74,7 @@ const modifyRoleQuery = ({ name }) => {
|
||||||
|
|
||||||
return `
|
return `
|
||||||
UPDATE
|
UPDATE
|
||||||
mydb.roles
|
acloc.roles
|
||||||
SET
|
SET
|
||||||
${nameCondition}
|
${nameCondition}
|
||||||
uuid = :uuid
|
uuid = :uuid
|
||||||
|
|
@ -82,8 +82,8 @@ const modifyRoleQuery = ({ name }) => {
|
||||||
roles.uuid = :uuid
|
roles.uuid = :uuid
|
||||||
AND
|
AND
|
||||||
roles.deleted IS NULL;
|
roles.deleted IS NULL;
|
||||||
SELECT mydb.roles.*
|
SELECT acloc.roles.*
|
||||||
FROM mydb.roles
|
FROM acloc.roles
|
||||||
WHERE roles.uuid = :uuid
|
WHERE roles.uuid = :uuid
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
@ -93,7 +93,7 @@ const modifyRoleQuery = ({ name }) => {
|
||||||
*/
|
*/
|
||||||
const deleteRoleQuery = () => {
|
const deleteRoleQuery = () => {
|
||||||
return `
|
return `
|
||||||
DELETE FROM mydb.roles
|
DELETE FROM acloc.roles
|
||||||
WHERE roles.uuid = :uuid
|
WHERE roles.uuid = :uuid
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
@ -105,7 +105,7 @@ const deleteRoleQuery = () => {
|
||||||
const softDeleteRoleQuery = () => {
|
const softDeleteRoleQuery = () => {
|
||||||
return `
|
return `
|
||||||
UPDATE
|
UPDATE
|
||||||
mydb.roles
|
acloc.roles
|
||||||
SET
|
SET
|
||||||
deleted = :deleted, deletedby = :deletedBy
|
deleted = :deleted, deletedby = :deletedBy
|
||||||
WHERE
|
WHERE
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ import { pagination } from '../../utils/pagination.js'
|
||||||
|
|
||||||
const _rolesHasPermissionsQuery = (_pagination = '') => ({count}) => ({uuid, fk_permission, fk_role, roleName}) => {
|
const _rolesHasPermissionsQuery = (_pagination = '') => ({count}) => ({uuid, fk_permission, fk_role, roleName}) => {
|
||||||
const uuidCondition = uuid ? 'AND r.uuid = :uuid' : '';
|
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 acloc.roles WHERE name = :roleName)' : '';
|
||||||
const roleUuidCondition = fk_role ? 'AND fk_role = (SELECT id from mydb.roles WHERE uuid = :fk_role)' : '';
|
const roleUuidCondition = fk_role ? 'AND fk_role = (SELECT id from acloc.roles WHERE uuid = :fk_role)' : '';
|
||||||
const permissionsUuidCondition = fk_permission ? 'AND fk_permission = (SELECT id from mydb.permissions WHERE uuid = :fk_permission)' : '';
|
const permissionsUuidCondition = fk_permission ? 'AND fk_permission = (SELECT id from acloc.permissions WHERE uuid = :fk_permission)' : '';
|
||||||
return `
|
return `
|
||||||
SELECT
|
SELECT
|
||||||
${count ||
|
${count ||
|
||||||
|
|
@ -15,13 +15,13 @@ const _rolesHasPermissionsQuery = (_pagination = '') => ({count}) => ({uuid, fk_
|
||||||
p.uuid as permission_uuid,
|
p.uuid as permission_uuid,
|
||||||
p.fk_endpoint as permission_endpoint`}
|
p.fk_endpoint as permission_endpoint`}
|
||||||
FROM
|
FROM
|
||||||
mydb.roles_has_permissions as r
|
acloc.roles_has_permissions as r
|
||||||
JOIN
|
JOIN
|
||||||
mydb.roles as r2 ON r.fk_role = r2.id
|
acloc.roles as r2 ON r.fk_role = r2.id
|
||||||
AND r2.created <= :now
|
AND r2.created <= :now
|
||||||
AND (r2.deleted > :now OR r2.deleted IS NULL)
|
AND (r2.deleted > :now OR r2.deleted IS NULL)
|
||||||
JOIN
|
JOIN
|
||||||
mydb.permissions as p ON r.fk_permission = p.id
|
acloc.permissions as p ON r.fk_permission = p.id
|
||||||
AND p.created <= :now
|
AND p.created <= :now
|
||||||
AND (p.deleted > :now OR p.deleted IS NULL)
|
AND (p.deleted > :now OR p.deleted IS NULL)
|
||||||
WHERE
|
WHERE
|
||||||
|
|
@ -45,7 +45,7 @@ const countRolesHasPermissionsQuery = rest =>
|
||||||
|
|
||||||
const insertRolesHasPermissionsQuery = () => {
|
const insertRolesHasPermissionsQuery = () => {
|
||||||
return `
|
return `
|
||||||
INSERT INTO mydb.roles_has_permissions (
|
INSERT INTO acloc.roles_has_permissions (
|
||||||
uuid,
|
uuid,
|
||||||
fk_role,
|
fk_role,
|
||||||
fk_permission,
|
fk_permission,
|
||||||
|
|
@ -54,28 +54,28 @@ const insertRolesHasPermissionsQuery = () => {
|
||||||
)
|
)
|
||||||
VALUES (
|
VALUES (
|
||||||
:uuid,
|
:uuid,
|
||||||
(SELECT id FROM mydb.roles WHERE uuid = :fk_role),
|
(SELECT id FROM acloc.roles WHERE uuid = :fk_role),
|
||||||
(SELECT id FROM mydb.permissions WHERE uuid = :fk_permission),
|
(SELECT id FROM acloc.permissions WHERE uuid = :fk_permission),
|
||||||
:now,
|
:now,
|
||||||
:createdBy
|
:createdBy
|
||||||
);
|
);
|
||||||
SELECT permissions.*,
|
SELECT acloc.permissions.*,
|
||||||
permissions.uuid as permission_uuid,
|
permissions.uuid as permission_uuid,
|
||||||
roles.uuid as role_uuid,
|
roles.uuid as role_uuid,
|
||||||
roles.name as role_name
|
roles.name as role_name
|
||||||
FROM mydb.roles_has_permissions as rp
|
FROM acloc.roles_has_permissions as rp
|
||||||
LEFT JOIN mydb.permissions as permissions ON rp.fk_permission = permissions.id
|
LEFT JOIN acloc.permissions as permissions ON rp.fk_permission = permissions.id
|
||||||
LEFT JOIN mydb.roles as roles ON rp.fk_role = roles.id
|
LEFT JOIN acloc.roles as roles ON rp.fk_role = roles.id
|
||||||
WHERE rp.uuid = :uuid;
|
WHERE rp.uuid = :uuid;
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
const modifyRolesHasPermissionsQuery = (roleUuid, permissionUuid) => {
|
const modifyRolesHasPermissionsQuery = (roleUuid, permissionUuid) => {
|
||||||
const roleUuidCondition = roleUuid ? 'fk_role = (SELECT id from mydb.roles WHERE uuid = :fk_role),' : '';
|
const roleUuidCondition = roleUuid ? 'fk_role = (SELECT id from acloc.roles WHERE uuid = :fk_role),' : '';
|
||||||
const permissionUuidCondition = permissionUuid ? 'fk_permission = (SELECT id from mydb.permissions WHERE uuid = :fk_permission),' : '';
|
const permissionUuidCondition = permissionUuid ? 'fk_permission = (SELECT id from acloc.permissions WHERE uuid = :fk_permission),' : '';
|
||||||
return `
|
return `
|
||||||
UPDATE
|
UPDATE
|
||||||
mydb.roles_has_permissions as roles_has_permissions
|
acloc.roles_has_permissions as roles_has_permissions
|
||||||
SET
|
SET
|
||||||
${roleUuidCondition}
|
${roleUuidCondition}
|
||||||
${permissionUuidCondition}
|
${permissionUuidCondition}
|
||||||
|
|
@ -84,14 +84,14 @@ const modifyRolesHasPermissionsQuery = (roleUuid, permissionUuid) => {
|
||||||
roles_has_permissions.uuid = :uuid
|
roles_has_permissions.uuid = :uuid
|
||||||
AND
|
AND
|
||||||
roles_has_permissions.deleted IS NULL;
|
roles_has_permissions.deleted IS NULL;
|
||||||
SELECT * FROM mydb.roles_has_permissions WHERE uuid = :uuid;
|
SELECT * FROM acloc.roles_has_permissions WHERE uuid = :uuid;
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
const softDeleteRolesHasPermissionsQuery = () => {
|
const softDeleteRolesHasPermissionsQuery = () => {
|
||||||
return `
|
return `
|
||||||
UPDATE
|
UPDATE
|
||||||
mydb.roles_has_permissions as roles_has_permissions
|
acloc.roles_has_permissions as roles_has_permissions
|
||||||
SET
|
SET
|
||||||
deleted = :deleted, deletedBy = :deletedBy
|
deleted = :deleted, deletedBy = :deletedBy
|
||||||
WHERE
|
WHERE
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,13 @@ 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)' : '';
|
const roleNameCondition = roleName ? 'AND users.fk_role = (SELECT id FROM acloc.roles WHERE name = :roleName)' : '';
|
||||||
return `
|
return `
|
||||||
SELECT
|
SELECT
|
||||||
${count || `users.*, r.name AS role`}
|
${count || `users.*, r.name AS role`}
|
||||||
FROM
|
FROM
|
||||||
mydb.users as users
|
acloc.users as users
|
||||||
LEFT JOIN mydb.roles as r ON users.fk_role = r.id
|
LEFT JOIN acloc.roles as r ON acloc.fk_role = r.id
|
||||||
WHERE
|
WHERE
|
||||||
users.created <= :now
|
users.created <= :now
|
||||||
AND
|
AND
|
||||||
|
|
@ -62,10 +62,10 @@ const countUserListQuery = rest =>
|
||||||
*/
|
*/
|
||||||
const insertUserQuery = ({email, fk_role, createdBy}) => {
|
const insertUserQuery = ({email, fk_role, createdBy}) => {
|
||||||
const emailCondition = email ? ':email' : null;
|
const emailCondition = email ? ':email' : null;
|
||||||
const roleCondition = fk_role ? '(SELECT id FROM mydb.roles WHERE name = :fk_role)' : `(SELECT id FROM mydb.roles WHERE name = 'viewer')`;
|
const roleCondition = fk_role ? '(SELECT id FROM acloc.roles WHERE name = :fk_role)' : `(SELECT id FROM acloc.roles WHERE name = 'viewer')`;
|
||||||
const createdByCondition = createdBy ? 'createdBy = :createdBy' : null;
|
const createdByCondition = createdBy ? 'createdBy = :createdBy' : null;
|
||||||
return `
|
return `
|
||||||
INSERT INTO mydb.users (
|
INSERT INTO acloc.users (
|
||||||
uuid,
|
uuid,
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
|
|
@ -83,7 +83,7 @@ const insertUserQuery = ({email, fk_role, createdBy}) => {
|
||||||
:now,
|
:now,
|
||||||
${createdByCondition}
|
${createdByCondition}
|
||||||
);
|
);
|
||||||
SELECT * FROM mydb.users WHERE uuid = :uuid;
|
SELECT * FROM acloc.users WHERE uuid = :uuid;
|
||||||
`
|
`
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -95,11 +95,11 @@ const modifyUserQuery = ({ username, password, email, role }) => {
|
||||||
const usernameCondition = username ? `username = :username, ` : ``;
|
const usernameCondition = username ? `username = :username, ` : ``;
|
||||||
const passwordCondition = password ? `password = :password, ` : ``;
|
const passwordCondition = password ? `password = :password, ` : ``;
|
||||||
const emailCondition = email ? `email = :email, ` : ``;
|
const emailCondition = email ? `email = :email, ` : ``;
|
||||||
const roleCondition = role ? `fk_role = (SELECT id FROM mydb.roles WHERE name = :role) ` : ``;
|
const roleCondition = role ? `fk_role = (SELECT id FROM acloc.roles WHERE name = :role) ` : ``;
|
||||||
|
|
||||||
return `
|
return `
|
||||||
UPDATE
|
UPDATE
|
||||||
mydb.users
|
acloc.users
|
||||||
SET
|
SET
|
||||||
${usernameCondition}
|
${usernameCondition}
|
||||||
${passwordCondition}
|
${passwordCondition}
|
||||||
|
|
@ -110,8 +110,8 @@ const modifyUserQuery = ({ username, password, email, role }) => {
|
||||||
users.uuid = :uuid
|
users.uuid = :uuid
|
||||||
AND
|
AND
|
||||||
users.deleted IS NULL;
|
users.deleted IS NULL;
|
||||||
SELECT mydb.users.*
|
SELECT acloc.users.*
|
||||||
FROM mydb.users
|
FROM acloc.users
|
||||||
WHERE users.uuid = :uuid
|
WHERE users.uuid = :uuid
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
@ -121,7 +121,7 @@ const modifyUserQuery = ({ username, password, email, role }) => {
|
||||||
*/
|
*/
|
||||||
const deleteUserQuery = () => {
|
const deleteUserQuery = () => {
|
||||||
return `
|
return `
|
||||||
DELETE FROM mydb.users
|
DELETE FROM acloc.users
|
||||||
WHERE users.uuid = :uuid
|
WHERE users.uuid = :uuid
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
@ -133,7 +133,7 @@ const deleteUserQuery = () => {
|
||||||
const softDeleteUserQuery = () => {
|
const softDeleteUserQuery = () => {
|
||||||
return `
|
return `
|
||||||
UPDATE
|
UPDATE
|
||||||
mydb.users
|
acloc.users
|
||||||
SET
|
SET
|
||||||
deleted = :deleted, deletedby = :deletedBy
|
deleted = :deleted, deletedby = :deletedBy
|
||||||
WHERE
|
WHERE
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,12 @@ const _placeSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, name, de
|
||||||
p.name,
|
p.name,
|
||||||
p.description,
|
p.description,
|
||||||
p.address,
|
p.address,
|
||||||
p.latitude,
|
c.latitude,
|
||||||
p.longitude,
|
c.longitude,
|
||||||
p.created,
|
p.created,
|
||||||
p.createdby
|
p.createdby
|
||||||
|
FROM acloc.places AS p
|
||||||
|
JOIN acloc.coordinates AS c ON p.fk_coordinates = c.id
|
||||||
WHERE p.deleted IS NULL
|
WHERE p.deleted IS NULL
|
||||||
AND p.created <= :now
|
AND p.created <= :now
|
||||||
AND (p.deleted > :now OR p.deleted IS NULL)
|
AND (p.deleted > :now OR p.deleted IS NULL)
|
||||||
|
|
@ -45,7 +47,7 @@ const insertPlaceQuery = ({ name, description, address, latitude, longitude, cre
|
||||||
const longitudeCondition = longitude ? ':longitude' : null;
|
const longitudeCondition = longitude ? ':longitude' : null;
|
||||||
const createdByCondition = createdBy ? 'createdBy = :createdBy' : null;
|
const createdByCondition = createdBy ? 'createdBy = :createdBy' : null;
|
||||||
return `
|
return `
|
||||||
INSERT INTO mydb.places (
|
INSERT INTO acloc.places (
|
||||||
uuid,
|
uuid,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
|
|
@ -77,7 +79,7 @@ const updatePlaceQuery = ({ uuid, name, description, address, latitude, longitud
|
||||||
const longitudeCondition = longitude ? ':longitude' : null;
|
const longitudeCondition = longitude ? ':longitude' : null;
|
||||||
const updatedByCondition = updatedBy ? 'updatedBy = :updatedBy' : null;
|
const updatedByCondition = updatedBy ? 'updatedBy = :updatedBy' : null;
|
||||||
return `
|
return `
|
||||||
UPDATE mydb.places AS p
|
UPDATE acloc.places AS p
|
||||||
SET
|
SET
|
||||||
name = ${nameCondition},
|
name = ${nameCondition},
|
||||||
description = ${descriptionCondition},
|
description = ${descriptionCondition},
|
||||||
|
|
@ -97,11 +99,13 @@ const deletePlaceQuery = ({ uuid, deletedBy }) => {
|
||||||
const uuidCondition = uuid ? 'AND p.uuid = :uuid ' : '';
|
const uuidCondition = uuid ? 'AND p.uuid = :uuid ' : '';
|
||||||
const deletedByCondition = deletedBy ? 'deletedBy = :deletedBy' : null;
|
const deletedByCondition = deletedBy ? 'deletedBy = :deletedBy' : null;
|
||||||
return `
|
return `
|
||||||
UPDATE mydb.places AS p
|
UPDATE acloc.places AS p
|
||||||
SET
|
SET
|
||||||
deleted = NOW(),
|
deleted = NOW(),
|
||||||
${deletedByCondition}
|
${deletedByCondition}
|
||||||
WHERE p.deleted IS NULL
|
WHERE
|
||||||
|
p.uuid = :uuid
|
||||||
|
AND p.deleted IS NULL
|
||||||
AND p.created <= NOW()
|
AND p.created <= NOW()
|
||||||
AND (p.deleted > NOW() OR p.deleted IS NULL)
|
AND (p.deleted > NOW() OR p.deleted IS NULL)
|
||||||
${uuidCondition}
|
${uuidCondition}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ const softDeleteUserHasPlacesQuery = () => {
|
||||||
UPDATE
|
UPDATE
|
||||||
mydb.users_has_places
|
mydb.users_has_places
|
||||||
SET
|
SET
|
||||||
deleted = :now, deletedBy = :deletedBy
|
deleted = :deleted, deletedBy = :deletedBy
|
||||||
WHERE
|
WHERE
|
||||||
users_has_places.uuid = :uuid
|
users_has_places.uuid = :uuid
|
||||||
AND
|
AND
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue