changed db name
This commit is contained in:
parent
adebf1f0ae
commit
36776f9083
|
|
@ -8,7 +8,7 @@ const _endpointsQuery = (_pagination = '') => ({ count }) => ({ uuid, route, met
|
|||
SELECT
|
||||
${count || `*`}
|
||||
FROM
|
||||
acloc.endpoints as e
|
||||
dbmaster.endpoints as e
|
||||
WHERE
|
||||
e.created <= :now
|
||||
AND
|
||||
|
|
@ -29,7 +29,7 @@ const countEndpointsQuery = rest =>
|
|||
|
||||
const insertEndpointsQuery = () => {
|
||||
return `
|
||||
INSERT INTO acloc.endpoints (
|
||||
INSERT INTO dbmaster.endpoints (
|
||||
uuid,
|
||||
route,
|
||||
created,
|
||||
|
|
@ -41,26 +41,26 @@ const insertEndpointsQuery = () => {
|
|||
:now,
|
||||
:createdBy
|
||||
);
|
||||
SELECT * FROM acloc.endpoints WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.endpoints WHERE uuid = :uuid;
|
||||
`
|
||||
}
|
||||
|
||||
const updateEndpointsQuery = (route) => {
|
||||
const routeCondition = route ? 'route = :route,' : '';
|
||||
return `
|
||||
UPDATE acloc.endpoints
|
||||
UPDATE dbmaster.endpoints
|
||||
SET
|
||||
${routeCondition}
|
||||
uuid = :uuid
|
||||
WHERE uuid = :uuid
|
||||
AND deleted IS NULL;
|
||||
SELECT * FROM acloc.endpoints WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.endpoints WHERE uuid = :uuid;
|
||||
`
|
||||
}
|
||||
|
||||
const softDeleteEndpointsQuery = () => {
|
||||
return `
|
||||
UPDATE acloc.endpoints
|
||||
UPDATE dbmaster.endpoints
|
||||
SET deleted = :deleted, deletedBy = :deletedBy
|
||||
WHERE uuid = :uuid
|
||||
AND deleted IS NULL
|
||||
|
|
@ -69,9 +69,9 @@ const softDeleteEndpointsQuery = () => {
|
|||
|
||||
const deleteEndpointsQuery = () => {
|
||||
return `
|
||||
DELETE FROM acloc.endpoints
|
||||
DELETE FROM dbmaster.endpoints
|
||||
WHERE uuid = :uuid;
|
||||
SELECT * FROM acloc.endpoints WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.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 acloc.endpoints WHERE route = :endpoint)' : '';
|
||||
const endpointCondition = endpoint ? 'AND fk_endpoint = (SELECT id from dbmaster.endpoints WHERE route = :endpoint)' : '';
|
||||
return `
|
||||
SELECT
|
||||
${count ||
|
||||
`*`}
|
||||
FROM
|
||||
acloc.permissions as p
|
||||
dbmaster.permissions as p
|
||||
LEFT JOIN
|
||||
acloc.endpoints as e ON p.fk_endpoint = e.id
|
||||
dbmaster.endpoints as e ON p.fk_endpoint = e.id
|
||||
WHERE
|
||||
e.created <= :now
|
||||
AND (e.deleted > :now OR e.deleted IS NULL)
|
||||
|
|
@ -36,7 +36,7 @@ const countPermissionsQuery = rest =>
|
|||
const insertPermissionsQuery = (createdBy) => {
|
||||
const createdByCondition = createdBy ? ':createdBy' : null;
|
||||
return `
|
||||
INSERT INTO acloc.permissions (
|
||||
INSERT INTO dbmaster.permissions (
|
||||
uuid,
|
||||
action,
|
||||
fk_endpoint,
|
||||
|
|
@ -46,19 +46,19 @@ const insertPermissionsQuery = (createdBy) => {
|
|||
VALUES (
|
||||
:uuid,
|
||||
:action,
|
||||
(SELECT id FROM acloc.endpoints WHERE route = :endpoint),
|
||||
(SELECT id FROM dbmaster.endpoints WHERE route = :endpoint),
|
||||
:now,
|
||||
${createdByCondition}
|
||||
);
|
||||
SELECT * FROM acloc.permissions WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.permissions WHERE uuid = :uuid;
|
||||
`
|
||||
}
|
||||
|
||||
const modifyPermissionsQuery = (action, endpoint) => {
|
||||
const actionCondition = action ? 'action = :action ,' : '';
|
||||
const endpointCondition = endpoint ? 'fk_endpoint = (SELECT id from acloc.endpoints WHERE route = :endpoint),' : '';
|
||||
const endpointCondition = endpoint ? 'fk_endpoint = (SELECT id from dbmaster.endpoints WHERE route = :endpoint),' : '';
|
||||
return `
|
||||
UPDATE acloc.permissions AS permissions
|
||||
UPDATE dbmaster.permissions AS permissions
|
||||
SET
|
||||
${actionCondition}
|
||||
${endpointCondition}
|
||||
|
|
@ -67,21 +67,21 @@ const modifyPermissionsQuery = (action, endpoint) => {
|
|||
permissions.uuid = :uuid
|
||||
AND
|
||||
permissions.deleted IS NULL;
|
||||
SELECT * FROM acloc.permissions WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.permissions WHERE uuid = :uuid;
|
||||
`
|
||||
}
|
||||
|
||||
const softDeletePermissionsQuery = () => {
|
||||
return `
|
||||
UPDATE
|
||||
acloc.permissions AS permissions
|
||||
dbmaster.permissions AS permissions
|
||||
SET
|
||||
deleted = :now, deletedBy = :deletedBy
|
||||
WHERE
|
||||
permissions.uuid = :uuid
|
||||
AND
|
||||
permissions.deleted IS NULL;
|
||||
SELECT * FROM acloc.permissions WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.permissions WHERE uuid = :uuid;
|
||||
`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ const _roleSelectQuery = (_pagination = '') =>
|
|||
SELECT
|
||||
${count || `*`}
|
||||
FROM
|
||||
acloc.roles as r
|
||||
dbmaster.roles as r
|
||||
WHERE
|
||||
r.created <= :now
|
||||
AND
|
||||
|
|
@ -49,7 +49,7 @@ const countRoleQuery = rest =>
|
|||
*/
|
||||
const insertRoleQuery = () => {
|
||||
return `
|
||||
INSERT INTO acloc.roles (
|
||||
INSERT INTO dbmaster.roles (
|
||||
uuid,
|
||||
name,
|
||||
created,
|
||||
|
|
@ -61,7 +61,7 @@ const insertRoleQuery = () => {
|
|||
:now,
|
||||
:createdBy
|
||||
);
|
||||
SELECT * FROM acloc.roles WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.roles WHERE uuid = :uuid;
|
||||
`
|
||||
};
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ const modifyRoleQuery = ({ name }) => {
|
|||
|
||||
return `
|
||||
UPDATE
|
||||
acloc.roles
|
||||
dbmaster.roles
|
||||
SET
|
||||
${nameCondition}
|
||||
uuid = :uuid
|
||||
|
|
@ -82,8 +82,8 @@ const modifyRoleQuery = ({ name }) => {
|
|||
roles.uuid = :uuid
|
||||
AND
|
||||
roles.deleted IS NULL;
|
||||
SELECT acloc.roles.*
|
||||
FROM acloc.roles
|
||||
SELECT dbmaster.roles.*
|
||||
FROM dbmaster.roles
|
||||
WHERE roles.uuid = :uuid
|
||||
`;
|
||||
};
|
||||
|
|
@ -93,7 +93,7 @@ const modifyRoleQuery = ({ name }) => {
|
|||
*/
|
||||
const deleteRoleQuery = () => {
|
||||
return `
|
||||
DELETE FROM acloc.roles
|
||||
DELETE FROM dbmaster.roles
|
||||
WHERE roles.uuid = :uuid
|
||||
`;
|
||||
};
|
||||
|
|
@ -105,7 +105,7 @@ const deleteRoleQuery = () => {
|
|||
const softDeleteRoleQuery = () => {
|
||||
return `
|
||||
UPDATE
|
||||
acloc.roles
|
||||
dbmaster.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 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)' : '';
|
||||
const roleNameCondition = roleName ? 'AND fk_role = (SELECT id from dbmaster.roles WHERE name = :roleName)' : '';
|
||||
const roleUuidCondition = fk_role ? 'AND fk_role = (SELECT id from dbmaster.roles WHERE uuid = :fk_role)' : '';
|
||||
const permissionsUuidCondition = fk_permission ? 'AND fk_permission = (SELECT id from dbmaster.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
|
||||
acloc.roles_has_permissions as r
|
||||
dbmaster.roles_has_permissions as r
|
||||
JOIN
|
||||
acloc.roles as r2 ON r.fk_role = r2.id
|
||||
dbmaster.roles as r2 ON r.fk_role = r2.id
|
||||
AND r2.created <= :now
|
||||
AND (r2.deleted > :now OR r2.deleted IS NULL)
|
||||
JOIN
|
||||
acloc.permissions as p ON r.fk_permission = p.id
|
||||
dbmaster.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 acloc.roles_has_permissions (
|
||||
INSERT INTO dbmaster.roles_has_permissions (
|
||||
uuid,
|
||||
fk_role,
|
||||
fk_permission,
|
||||
|
|
@ -54,28 +54,28 @@ const insertRolesHasPermissionsQuery = () => {
|
|||
)
|
||||
VALUES (
|
||||
:uuid,
|
||||
(SELECT id FROM acloc.roles WHERE uuid = :fk_role),
|
||||
(SELECT id FROM acloc.permissions WHERE uuid = :fk_permission),
|
||||
(SELECT id FROM dbmaster.roles WHERE uuid = :fk_role),
|
||||
(SELECT id FROM dbmaster.permissions WHERE uuid = :fk_permission),
|
||||
:now,
|
||||
:createdBy
|
||||
);
|
||||
SELECT acloc.permissions.*,
|
||||
SELECT dbmaster.permissions.*,
|
||||
permissions.uuid as permission_uuid,
|
||||
roles.uuid as role_uuid,
|
||||
roles.name as role_name
|
||||
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
|
||||
FROM dbmaster.roles_has_permissions as rp
|
||||
LEFT JOIN dbmaster.permissions as permissions ON rp.fk_permission = permissions.id
|
||||
LEFT JOIN dbmaster.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 acloc.roles WHERE uuid = :fk_role),' : '';
|
||||
const permissionUuidCondition = permissionUuid ? 'fk_permission = (SELECT id from acloc.permissions WHERE uuid = :fk_permission),' : '';
|
||||
const roleUuidCondition = roleUuid ? 'fk_role = (SELECT id from dbmaster.roles WHERE uuid = :fk_role),' : '';
|
||||
const permissionUuidCondition = permissionUuid ? 'fk_permission = (SELECT id from dbmaster.permissions WHERE uuid = :fk_permission),' : '';
|
||||
return `
|
||||
UPDATE
|
||||
acloc.roles_has_permissions as roles_has_permissions
|
||||
dbmaster.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 acloc.roles_has_permissions WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.roles_has_permissions WHERE uuid = :uuid;
|
||||
`
|
||||
}
|
||||
|
||||
const softDeleteRolesHasPermissionsQuery = () => {
|
||||
return `
|
||||
UPDATE
|
||||
acloc.roles_has_permissions as roles_has_permissions
|
||||
dbmaster.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 acloc.roles WHERE name = :roleName)' : '';
|
||||
const roleNameCondition = roleName ? 'AND users.fk_role = (SELECT id FROM dbmaster.roles WHERE name = :roleName)' : '';
|
||||
return `
|
||||
SELECT
|
||||
${count || `users.*, r.name AS role`}
|
||||
FROM
|
||||
acloc.users as users
|
||||
LEFT JOIN acloc.roles as r ON users.fk_role = r.id
|
||||
dbmaster.users as users
|
||||
LEFT JOIN dbmaster.roles as r ON users.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 acloc.roles WHERE name = :fk_role)' : `(SELECT id FROM acloc.roles WHERE name = 'viewer')`;
|
||||
const roleCondition = fk_role ? '(SELECT id FROM dbmaster.roles WHERE name = :fk_role)' : `(SELECT id FROM dbmaster.roles WHERE name = 'viewer')`;
|
||||
const createdByCondition = createdBy ? ':createdBy' : null;
|
||||
return `
|
||||
INSERT INTO acloc.users (
|
||||
INSERT INTO dbmaster.users (
|
||||
uuid,
|
||||
username,
|
||||
password,
|
||||
|
|
@ -83,7 +83,7 @@ const insertUserQuery = ({email, fk_role, createdBy}) => {
|
|||
:now,
|
||||
${createdByCondition}
|
||||
);
|
||||
SELECT * FROM acloc.users WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.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 acloc.roles WHERE name = :role) ` : ``;
|
||||
const roleCondition = role ? `fk_role = (SELECT id FROM dbmaster.roles WHERE name = :role) ` : ``;
|
||||
|
||||
return `
|
||||
UPDATE
|
||||
acloc.users
|
||||
dbmaster.users
|
||||
SET
|
||||
${usernameCondition}
|
||||
${passwordCondition}
|
||||
|
|
@ -110,8 +110,8 @@ const modifyUserQuery = ({ username, password, email, role }) => {
|
|||
users.uuid = :uuid
|
||||
AND
|
||||
users.deleted IS NULL;
|
||||
SELECT acloc.users.*
|
||||
FROM acloc.users
|
||||
SELECT dbmaster.users.*
|
||||
FROM dbmaster.users
|
||||
WHERE users.uuid = :uuid
|
||||
`;
|
||||
};
|
||||
|
|
@ -121,7 +121,7 @@ const modifyUserQuery = ({ username, password, email, role }) => {
|
|||
*/
|
||||
const deleteUserQuery = () => {
|
||||
return `
|
||||
DELETE FROM acloc.users
|
||||
DELETE FROM dbmaster.users
|
||||
WHERE users.uuid = :uuid
|
||||
`;
|
||||
};
|
||||
|
|
@ -133,7 +133,7 @@ const deleteUserQuery = () => {
|
|||
const softDeleteUserQuery = () => {
|
||||
return `
|
||||
UPDATE
|
||||
acloc.users
|
||||
dbmaster.users
|
||||
SET
|
||||
deleted = :deleted, deletedby = :deletedBy
|
||||
WHERE
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ const _coordinatesSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, la
|
|||
c.createdby,
|
||||
c.latitude,
|
||||
c.longitude`}
|
||||
FROM acloc.coordinates AS c
|
||||
FROM dbmaster.coordinates AS c
|
||||
WHERE c.created <= :now
|
||||
AND (c.deleted > :now OR c.deleted IS NULL)
|
||||
AND true
|
||||
|
|
@ -31,7 +31,7 @@ const countCoordinatesListQuery = rest =>
|
|||
|
||||
const insertCoordinatesQuery = () => {
|
||||
return `
|
||||
INSERT INTO acloc.coordinates (
|
||||
INSERT INTO dbmaster.coordinates (
|
||||
uuid,
|
||||
latitude,
|
||||
longitude,
|
||||
|
|
@ -45,7 +45,7 @@ const insertCoordinatesQuery = () => {
|
|||
:now,
|
||||
:createdBy
|
||||
);
|
||||
SELECT * FROM acloc.coordinates WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.coordinates WHERE uuid = :uuid;
|
||||
`
|
||||
}
|
||||
|
||||
|
|
@ -53,21 +53,21 @@ const updateCoordinatesQuery = (latitude, longitude) => {
|
|||
const latitudeCondition = latitude ? 'latitude = :latitude,' : '';
|
||||
const longitudeCondition = longitude ? 'longitude = :longitude,' : '';
|
||||
return `
|
||||
UPDATE acloc.coordinates
|
||||
UPDATE dbmaster.coordinates
|
||||
SET
|
||||
${latitudeCondition}
|
||||
${longitudeCondition}
|
||||
uuid = :uuid
|
||||
WHERE uuid = :uuid
|
||||
AND deleted IS NULL;
|
||||
SELECT * FROM acloc.coordinates WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.coordinates WHERE uuid = :uuid;
|
||||
`
|
||||
}
|
||||
|
||||
const softDeleteCoordinatesQuery = () => {
|
||||
return `
|
||||
UPDATE
|
||||
acloc.coordinates
|
||||
dbmaster.coordinates
|
||||
SET
|
||||
deleted = :deleted, deletedby = :deletedBy
|
||||
WHERE uuid = :uuid
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const _placeSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, name, de
|
|||
const nameCondition = name ? `AND p.name LIKE CONCAT('%',:name,'%')` : '';
|
||||
const descriptionCondition = description ? `AND p.description LIKE CONCAT('%',:description,'%')` : '';
|
||||
const addressCondition = address ? `AND p.address LIKE CONCAT('%',:address,'%')` : '';
|
||||
const fk_coordinateCondition = latitude && longitude ? 'AND fk_coordinate = (SELECT id FROM acloc.coordinates WHERE latitude = :latitude AND longitude = :longitude)' : '';
|
||||
const fk_coordinateCondition = latitude && longitude ? 'AND fk_coordinate = (SELECT id FROM dbmaster.coordinates WHERE latitude = :latitude AND longitude = :longitude)' : '';
|
||||
return `
|
||||
SELECT ${count ||
|
||||
`p.uuid,
|
||||
|
|
@ -15,8 +15,8 @@ const _placeSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, name, de
|
|||
c.latitude,
|
||||
c.longitude,
|
||||
p.created`}
|
||||
FROM acloc.places AS p
|
||||
JOIN acloc.coordinates AS c ON p.fk_coordinate = c.id
|
||||
FROM dbmaster.places AS p
|
||||
JOIN dbmaster.coordinates AS c ON p.fk_coordinate = c.id
|
||||
WHERE p.deleted IS NULL
|
||||
AND p.created <= :now
|
||||
AND (p.deleted > :now OR p.deleted IS NULL)
|
||||
|
|
@ -41,7 +41,7 @@ const insertPlaceQuery = ({ description, address, createdBy }) => {
|
|||
const addressCondition = address ? ':address' : null;
|
||||
const createdByCondition = createdBy ? 'createdBy = :createdBy' : null;
|
||||
return `
|
||||
INSERT INTO acloc.places (
|
||||
INSERT INTO dbmaster.places (
|
||||
uuid,
|
||||
name,
|
||||
description,
|
||||
|
|
@ -55,7 +55,7 @@ const insertPlaceQuery = ({ description, address, createdBy }) => {
|
|||
:name,
|
||||
${descriptionCondition},
|
||||
${addressCondition},
|
||||
(SELECT id FROM acloc.coordinates WHERE latitude = :latitude AND longitude = :longitude),
|
||||
(SELECT id FROM dbmaster.coordinates WHERE latitude = :latitude AND longitude = :longitude),
|
||||
:now,
|
||||
${createdByCondition}
|
||||
)
|
||||
|
|
@ -66,10 +66,10 @@ const updatePlaceQuery = ({ name, description, address, latitude, longitude }) =
|
|||
const nameCondition = name ? 'name = :name,' : '';
|
||||
const descriptionCondition = description ? 'description = :description,' : '';
|
||||
const addressCondition = address ? 'address = :address' : '';
|
||||
const fk_coordinateCondition = latitude && longitude ? 'fk_coordinate = (SELECT id FROM acloc.coordinates WHERE latitude = :latitude AND longitude = :longitude),' : '';
|
||||
const fk_coordinateCondition = latitude && longitude ? 'fk_coordinate = (SELECT id FROM dbmaster.coordinates WHERE latitude = :latitude AND longitude = :longitude),' : '';
|
||||
|
||||
return `
|
||||
UPDATE acloc.places AS p
|
||||
UPDATE dbmaster.places AS p
|
||||
SET
|
||||
${nameCondition}
|
||||
${descriptionCondition}
|
||||
|
|
@ -85,7 +85,7 @@ const updatePlaceQuery = ({ name, description, address, latitude, longitude }) =
|
|||
|
||||
const deletePlaceQuery = () => {
|
||||
return `
|
||||
UPDATE acloc.places AS p
|
||||
UPDATE dbmaster.places AS p
|
||||
SET
|
||||
deleted = :deleted, deletedby = :deletedBy
|
||||
WHERE
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const _coordinatesSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, na
|
|||
return `
|
||||
SELECT ${count ||
|
||||
`*`}
|
||||
FROM acloc.report_types AS rt
|
||||
FROM dbmaster.report_types AS rt
|
||||
WHERE rt.created <= :now
|
||||
AND (rt.deleted > :now OR rt.deleted IS NULL)
|
||||
AND true
|
||||
|
|
@ -24,7 +24,7 @@ const countReportTypesListQuery = rest =>
|
|||
|
||||
const insertReportTypesQuery = () => {
|
||||
return `
|
||||
INSERT INTO acloc.report_types (
|
||||
INSERT INTO dbmaster.report_types (
|
||||
uuid,
|
||||
name,
|
||||
created,
|
||||
|
|
@ -36,33 +36,33 @@ const insertReportTypesQuery = () => {
|
|||
:now,
|
||||
:createdBy
|
||||
);
|
||||
SELECT * FROM acloc.report_types WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.report_types WHERE uuid = :uuid;
|
||||
`
|
||||
}
|
||||
|
||||
const updateReportTypesQuery = (name) => {
|
||||
const nameCondition = name ? 'name = :name,' : '';
|
||||
return `
|
||||
UPDATE acloc.report_types
|
||||
UPDATE dbmaster.report_types
|
||||
SET
|
||||
${nameCondition}
|
||||
uuid = :uuid
|
||||
WHERE uuid = :uuid
|
||||
AND deleted IS NULL;
|
||||
SELECT * FROM acloc.report_types WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.report_types WHERE uuid = :uuid;
|
||||
`
|
||||
}
|
||||
|
||||
const softDeleteReportTypesQuery = () => {
|
||||
return `
|
||||
UPDATE
|
||||
acloc.report_types
|
||||
dbmaster.report_types
|
||||
SET
|
||||
deleted = :deleted,
|
||||
deletedBy = :deletedBy
|
||||
WHERE uuid = :uuid
|
||||
AND deleted IS NULL;
|
||||
SELECT * FROM acloc.report_types WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.report_types WHERE uuid = :uuid;
|
||||
`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ import { pagination } from "../../utils/pagination.js";
|
|||
//reports repository
|
||||
const _userHasPlacesSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, uuidUser, uuidPlace, uuidReportType, rating }) => {
|
||||
const uuidCondition = uuid ? 'AND up.uuid = :uuid ' : '';
|
||||
const uuidUserCondition = uuidUser ? 'AND up.fk_user = (SELECT id FROM acloc.users WHERE uuid = :uuidUser)' : '';
|
||||
const uuidPlaceCondition = uuidPlace ? 'AND up.fk_place = (SELECT id FROM acloc.places WHERE uuid = :uuidPlace)' : '';
|
||||
const uuidReportTypeCondition = uuidReportType ? 'AND up.fk_report_type = (SELECT id FROM acloc.report_types WHERE uuid = :uuidReportType)' : '';
|
||||
const uuidUserCondition = uuidUser ? 'AND up.fk_user = (SELECT id FROM dbmaster.users WHERE uuid = :uuidUser)' : '';
|
||||
const uuidPlaceCondition = uuidPlace ? 'AND up.fk_place = (SELECT id FROM dbmaster.places WHERE uuid = :uuidPlace)' : '';
|
||||
const uuidReportTypeCondition = uuidReportType ? 'AND up.fk_report_type = (SELECT id FROM dbmaster.report_types WHERE uuid = :uuidReportType)' : '';
|
||||
const ratingCondition = rating ? 'AND up.rating = :rating' : '';
|
||||
return `
|
||||
SELECT ${count ||
|
||||
|
|
@ -15,10 +15,10 @@ const _userHasPlacesSelectQuery = (_pagination = '') => ({ count }) => ({ uuid,
|
|||
p.uuid AS place_uuid,
|
||||
rt.name AS report_type_name,
|
||||
rt.uuid AS report_type_uuid`}
|
||||
FROM acloc.users_has_places AS up
|
||||
JOIN acloc.users AS u ON up.fk_user = u.id
|
||||
JOIN acloc.places AS p ON up.fk_place = p.id
|
||||
JOIN acloc.report_types AS rt ON up.fk_report_type = rt.id
|
||||
FROM dbmaster.users_has_places AS up
|
||||
JOIN dbmaster.users AS u ON up.fk_user = u.id
|
||||
JOIN dbmaster.places AS p ON up.fk_place = p.id
|
||||
JOIN dbmaster.report_types AS rt ON up.fk_report_type = rt.id
|
||||
WHERE up.created <= :now
|
||||
AND (up.deleted > :now OR up.deleted IS NULL)
|
||||
AND u.deleted IS NULL
|
||||
|
|
@ -41,13 +41,13 @@ const countUserHasPlacesListQuery = rest =>
|
|||
_userHasPlacesSelectQuery()({ count: 'COUNT(DISTINCT(up.uuid)) AS count' })(rest);
|
||||
|
||||
const insertUserHasPlacesQuery = ({ uuidUser, uuidPlace, createdBy, uuidReportType }) => {
|
||||
const uuidUserCondition = uuidUser ? '(SELECT id FROM acloc.users WHERE uuid = :uuidUser),' : null;
|
||||
const uuidPlaceCondition = uuidPlace ? '(SELECT id FROM acloc.places WHERE uuid = :uuidPlace),' : null;
|
||||
const uuidUserCondition = uuidUser ? '(SELECT id FROM dbmaster.users WHERE uuid = :uuidUser),' : null;
|
||||
const uuidPlaceCondition = uuidPlace ? '(SELECT id FROM dbmaster.places WHERE uuid = :uuidPlace),' : null;
|
||||
const createdByCondition = createdBy ? 'createdBy = :createdBy' : null;
|
||||
const reportTypeCondition = uuidReportType ? '(SELECT id FROM acloc.report_types WHERE uuid = :reportType),' : null;
|
||||
const reportTypeCondition = uuidReportType ? '(SELECT id FROM dbmaster.report_types WHERE uuid = :reportType),' : null;
|
||||
|
||||
return `
|
||||
INSERT INTO acloc.users_has_places (
|
||||
INSERT INTO dbmaster.users_has_places (
|
||||
uuid,
|
||||
fk_user,
|
||||
fk_place,
|
||||
|
|
@ -65,17 +65,17 @@ const insertUserHasPlacesQuery = ({ uuidUser, uuidPlace, createdBy, uuidReportTy
|
|||
:now,
|
||||
${createdByCondition}
|
||||
);
|
||||
SELECT * FROM acloc.users_has_places WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.users_has_places WHERE uuid = :uuid;
|
||||
`
|
||||
}
|
||||
|
||||
const modifyUserHasPlacesQuery = (uuidUser, uuidPlace, uuidReportType, rating) => {
|
||||
const uuidUserCondition = uuidUser ? 'fk_user = (SELECT id FROM acloc.users WHERE uuid = :uuidUser)' : ``;
|
||||
const uuidPlaceCondition = uuidPlace ? 'fk_place = (SELECT id FROM acloc.places WHERE uuid = :uuidPlace)' : ``;
|
||||
const uuidReportTypeCondition = uuidReportType ? 'fk_report_type = (SELECT id FROM acloc.report_types WHERE uuid = :uuidReportType)' : ``;
|
||||
const uuidUserCondition = uuidUser ? 'fk_user = (SELECT id FROM dbmaster.users WHERE uuid = :uuidUser)' : ``;
|
||||
const uuidPlaceCondition = uuidPlace ? 'fk_place = (SELECT id FROM dbmaster.places WHERE uuid = :uuidPlace)' : ``;
|
||||
const uuidReportTypeCondition = uuidReportType ? 'fk_report_type = (SELECT id FROM dbmaster.report_types WHERE uuid = :uuidReportType)' : ``;
|
||||
const ratingCondition = rating ? 'rating = :rating' : ``;
|
||||
return `
|
||||
UPDATE acloc.users_has_places
|
||||
UPDATE dbmaster.users_has_places
|
||||
SET
|
||||
${uuidUserCondition}
|
||||
${uuidPlaceCondition}
|
||||
|
|
@ -86,14 +86,14 @@ const modifyUserHasPlacesQuery = (uuidUser, uuidPlace, uuidReportType, rating) =
|
|||
users_has_places.uuid = :uuid
|
||||
AND
|
||||
users_has_places.deleted IS NULL;
|
||||
SELECT * FROM acloc.users_has_places WHERE uuid = :uuid;
|
||||
SELECT * FROM dbmaster.users_has_places WHERE uuid = :uuid;
|
||||
`
|
||||
}
|
||||
|
||||
const softDeleteUserHasPlacesQuery = () => {
|
||||
return `
|
||||
UPDATE
|
||||
acloc.users_has_places
|
||||
dbmaster.users_has_places
|
||||
SET
|
||||
deleted = :deleted, deletedBy = :deletedBy
|
||||
WHERE
|
||||
|
|
|
|||
Loading…
Reference in New Issue