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