changed db name

This commit is contained in:
Pau 2025-04-14 02:22:18 +02:00
parent adebf1f0ae
commit 36776f9083
9 changed files with 96 additions and 96 deletions

View File

@ -8,7 +8,7 @@ const _endpointsQuery = (_pagination = '') => ({ count }) => ({ uuid, route, met
SELECT SELECT
${count || `*`} ${count || `*`}
FROM FROM
acloc.endpoints as e dbmaster.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 acloc.endpoints ( INSERT INTO dbmaster.endpoints (
uuid, uuid,
route, route,
created, created,
@ -41,26 +41,26 @@ const insertEndpointsQuery = () => {
:now, :now,
:createdBy :createdBy
); );
SELECT * FROM acloc.endpoints WHERE uuid = :uuid; SELECT * FROM dbmaster.endpoints WHERE uuid = :uuid;
` `
} }
const updateEndpointsQuery = (route) => { const updateEndpointsQuery = (route) => {
const routeCondition = route ? 'route = :route,' : ''; const routeCondition = route ? 'route = :route,' : '';
return ` return `
UPDATE acloc.endpoints UPDATE dbmaster.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 acloc.endpoints WHERE uuid = :uuid; SELECT * FROM dbmaster.endpoints WHERE uuid = :uuid;
` `
} }
const softDeleteEndpointsQuery = () => { const softDeleteEndpointsQuery = () => {
return ` return `
UPDATE acloc.endpoints UPDATE dbmaster.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 acloc.endpoints DELETE FROM dbmaster.endpoints
WHERE uuid = :uuid; WHERE uuid = :uuid;
SELECT * FROM acloc.endpoints WHERE uuid = :uuid; SELECT * FROM dbmaster.endpoints WHERE uuid = :uuid;
` `
} }

View File

@ -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 acloc.endpoints WHERE route = :endpoint)' : ''; const endpointCondition = endpoint ? 'AND fk_endpoint = (SELECT id from dbmaster.endpoints WHERE route = :endpoint)' : '';
return ` return `
SELECT SELECT
${count || ${count ||
`*`} `*`}
FROM FROM
acloc.permissions as p dbmaster.permissions as p
LEFT JOIN LEFT JOIN
acloc.endpoints as e ON p.fk_endpoint = e.id dbmaster.endpoints as e ON p.fk_endpoint = e.id
WHERE WHERE
e.created <= :now e.created <= :now
AND (e.deleted > :now OR e.deleted IS NULL) AND (e.deleted > :now OR e.deleted IS NULL)
@ -36,7 +36,7 @@ const countPermissionsQuery = rest =>
const insertPermissionsQuery = (createdBy) => { const insertPermissionsQuery = (createdBy) => {
const createdByCondition = createdBy ? ':createdBy' : null; const createdByCondition = createdBy ? ':createdBy' : null;
return ` return `
INSERT INTO acloc.permissions ( INSERT INTO dbmaster.permissions (
uuid, uuid,
action, action,
fk_endpoint, fk_endpoint,
@ -46,19 +46,19 @@ const insertPermissionsQuery = (createdBy) => {
VALUES ( VALUES (
:uuid, :uuid,
:action, :action,
(SELECT id FROM acloc.endpoints WHERE route = :endpoint), (SELECT id FROM dbmaster.endpoints WHERE route = :endpoint),
:now, :now,
${createdByCondition} ${createdByCondition}
); );
SELECT * FROM acloc.permissions WHERE uuid = :uuid; SELECT * FROM dbmaster.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 acloc.endpoints WHERE route = :endpoint),' : ''; const endpointCondition = endpoint ? 'fk_endpoint = (SELECT id from dbmaster.endpoints WHERE route = :endpoint),' : '';
return ` return `
UPDATE acloc.permissions AS permissions UPDATE dbmaster.permissions AS permissions
SET SET
${actionCondition} ${actionCondition}
${endpointCondition} ${endpointCondition}
@ -67,21 +67,21 @@ const modifyPermissionsQuery = (action, endpoint) => {
permissions.uuid = :uuid permissions.uuid = :uuid
AND AND
permissions.deleted IS NULL; permissions.deleted IS NULL;
SELECT * FROM acloc.permissions WHERE uuid = :uuid; SELECT * FROM dbmaster.permissions WHERE uuid = :uuid;
` `
} }
const softDeletePermissionsQuery = () => { const softDeletePermissionsQuery = () => {
return ` return `
UPDATE UPDATE
acloc.permissions AS permissions dbmaster.permissions AS 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 acloc.permissions WHERE uuid = :uuid; SELECT * FROM dbmaster.permissions WHERE uuid = :uuid;
` `
} }

View File

@ -16,7 +16,7 @@ const _roleSelectQuery = (_pagination = '') =>
SELECT SELECT
${count || `*`} ${count || `*`}
FROM FROM
acloc.roles as r dbmaster.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 acloc.roles ( INSERT INTO dbmaster.roles (
uuid, uuid,
name, name,
created, created,
@ -61,7 +61,7 @@ const insertRoleQuery = () => {
:now, :now,
:createdBy :createdBy
); );
SELECT * FROM acloc.roles WHERE uuid = :uuid; SELECT * FROM dbmaster.roles WHERE uuid = :uuid;
` `
}; };
@ -74,7 +74,7 @@ const modifyRoleQuery = ({ name }) => {
return ` return `
UPDATE UPDATE
acloc.roles dbmaster.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 acloc.roles.* SELECT dbmaster.roles.*
FROM acloc.roles FROM dbmaster.roles
WHERE roles.uuid = :uuid WHERE roles.uuid = :uuid
`; `;
}; };
@ -93,7 +93,7 @@ const modifyRoleQuery = ({ name }) => {
*/ */
const deleteRoleQuery = () => { const deleteRoleQuery = () => {
return ` return `
DELETE FROM acloc.roles DELETE FROM dbmaster.roles
WHERE roles.uuid = :uuid WHERE roles.uuid = :uuid
`; `;
}; };
@ -105,7 +105,7 @@ const deleteRoleQuery = () => {
const softDeleteRoleQuery = () => { const softDeleteRoleQuery = () => {
return ` return `
UPDATE UPDATE
acloc.roles dbmaster.roles
SET SET
deleted = :deleted, deletedby = :deletedBy deleted = :deleted, deletedby = :deletedBy
WHERE WHERE

View File

@ -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 acloc.roles WHERE name = :roleName)' : ''; const roleNameCondition = roleName ? 'AND fk_role = (SELECT id from dbmaster.roles WHERE name = :roleName)' : '';
const roleUuidCondition = fk_role ? 'AND fk_role = (SELECT id from acloc.roles WHERE uuid = :fk_role)' : ''; 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 acloc.permissions WHERE uuid = :fk_permission)' : ''; const permissionsUuidCondition = fk_permission ? 'AND fk_permission = (SELECT id from dbmaster.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
acloc.roles_has_permissions as r dbmaster.roles_has_permissions as r
JOIN 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.created <= :now
AND (r2.deleted > :now OR r2.deleted IS NULL) AND (r2.deleted > :now OR r2.deleted IS NULL)
JOIN 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.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 acloc.roles_has_permissions ( INSERT INTO dbmaster.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 acloc.roles WHERE uuid = :fk_role), (SELECT id FROM dbmaster.roles WHERE uuid = :fk_role),
(SELECT id FROM acloc.permissions WHERE uuid = :fk_permission), (SELECT id FROM dbmaster.permissions WHERE uuid = :fk_permission),
:now, :now,
:createdBy :createdBy
); );
SELECT acloc.permissions.*, SELECT dbmaster.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 acloc.roles_has_permissions as rp FROM dbmaster.roles_has_permissions as rp
LEFT JOIN acloc.permissions as permissions ON rp.fk_permission = permissions.id LEFT JOIN dbmaster.permissions as permissions ON rp.fk_permission = permissions.id
LEFT JOIN acloc.roles as roles ON rp.fk_role = roles.id LEFT JOIN dbmaster.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 acloc.roles WHERE uuid = :fk_role),' : ''; const roleUuidCondition = roleUuid ? 'fk_role = (SELECT id from dbmaster.roles WHERE uuid = :fk_role),' : '';
const permissionUuidCondition = permissionUuid ? 'fk_permission = (SELECT id from acloc.permissions WHERE uuid = :fk_permission),' : ''; const permissionUuidCondition = permissionUuid ? 'fk_permission = (SELECT id from dbmaster.permissions WHERE uuid = :fk_permission),' : '';
return ` return `
UPDATE UPDATE
acloc.roles_has_permissions as roles_has_permissions dbmaster.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 acloc.roles_has_permissions WHERE uuid = :uuid; SELECT * FROM dbmaster.roles_has_permissions WHERE uuid = :uuid;
` `
} }
const softDeleteRolesHasPermissionsQuery = () => { const softDeleteRolesHasPermissionsQuery = () => {
return ` return `
UPDATE UPDATE
acloc.roles_has_permissions as roles_has_permissions dbmaster.roles_has_permissions as roles_has_permissions
SET SET
deleted = :deleted, deletedBy = :deletedBy deleted = :deleted, deletedBy = :deletedBy
WHERE WHERE

View File

@ -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 acloc.roles WHERE name = :roleName)' : ''; const roleNameCondition = roleName ? 'AND users.fk_role = (SELECT id FROM dbmaster.roles WHERE name = :roleName)' : '';
return ` return `
SELECT SELECT
${count || `users.*, r.name AS role`} ${count || `users.*, r.name AS role`}
FROM FROM
acloc.users as users dbmaster.users as users
LEFT JOIN acloc.roles as r ON users.fk_role = r.id LEFT JOIN dbmaster.roles as r ON users.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 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; const createdByCondition = createdBy ? ':createdBy' : null;
return ` return `
INSERT INTO acloc.users ( INSERT INTO dbmaster.users (
uuid, uuid,
username, username,
password, password,
@ -83,7 +83,7 @@ const insertUserQuery = ({email, fk_role, createdBy}) => {
:now, :now,
${createdByCondition} ${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 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 acloc.roles WHERE name = :role) ` : ``; const roleCondition = role ? `fk_role = (SELECT id FROM dbmaster.roles WHERE name = :role) ` : ``;
return ` return `
UPDATE UPDATE
acloc.users dbmaster.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 acloc.users.* SELECT dbmaster.users.*
FROM acloc.users FROM dbmaster.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 acloc.users DELETE FROM dbmaster.users
WHERE users.uuid = :uuid WHERE users.uuid = :uuid
`; `;
}; };
@ -133,7 +133,7 @@ const deleteUserQuery = () => {
const softDeleteUserQuery = () => { const softDeleteUserQuery = () => {
return ` return `
UPDATE UPDATE
acloc.users dbmaster.users
SET SET
deleted = :deleted, deletedby = :deletedBy deleted = :deleted, deletedby = :deletedBy
WHERE WHERE

View File

@ -12,7 +12,7 @@ const _coordinatesSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, la
c.createdby, c.createdby,
c.latitude, c.latitude,
c.longitude`} c.longitude`}
FROM acloc.coordinates AS c FROM dbmaster.coordinates AS c
WHERE c.created <= :now WHERE c.created <= :now
AND (c.deleted > :now OR c.deleted IS NULL) AND (c.deleted > :now OR c.deleted IS NULL)
AND true AND true
@ -31,7 +31,7 @@ const countCoordinatesListQuery = rest =>
const insertCoordinatesQuery = () => { const insertCoordinatesQuery = () => {
return ` return `
INSERT INTO acloc.coordinates ( INSERT INTO dbmaster.coordinates (
uuid, uuid,
latitude, latitude,
longitude, longitude,
@ -45,7 +45,7 @@ const insertCoordinatesQuery = () => {
:now, :now,
:createdBy :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 latitudeCondition = latitude ? 'latitude = :latitude,' : '';
const longitudeCondition = longitude ? 'longitude = :longitude,' : ''; const longitudeCondition = longitude ? 'longitude = :longitude,' : '';
return ` return `
UPDATE acloc.coordinates UPDATE dbmaster.coordinates
SET SET
${latitudeCondition} ${latitudeCondition}
${longitudeCondition} ${longitudeCondition}
uuid = :uuid uuid = :uuid
WHERE uuid = :uuid WHERE uuid = :uuid
AND deleted IS NULL; AND deleted IS NULL;
SELECT * FROM acloc.coordinates WHERE uuid = :uuid; SELECT * FROM dbmaster.coordinates WHERE uuid = :uuid;
` `
} }
const softDeleteCoordinatesQuery = () => { const softDeleteCoordinatesQuery = () => {
return ` return `
UPDATE UPDATE
acloc.coordinates dbmaster.coordinates
SET SET
deleted = :deleted, deletedby = :deletedBy deleted = :deleted, deletedby = :deletedBy
WHERE uuid = :uuid WHERE uuid = :uuid

View File

@ -5,7 +5,7 @@ const _placeSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, name, de
const nameCondition = name ? `AND p.name LIKE CONCAT('%',:name,'%')` : ''; const nameCondition = name ? `AND p.name LIKE CONCAT('%',:name,'%')` : '';
const descriptionCondition = description ? `AND p.description LIKE CONCAT('%',:description,'%')` : ''; const descriptionCondition = description ? `AND p.description LIKE CONCAT('%',:description,'%')` : '';
const addressCondition = address ? `AND p.address LIKE CONCAT('%',:address,'%')` : ''; 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 ` return `
SELECT ${count || SELECT ${count ||
`p.uuid, `p.uuid,
@ -15,8 +15,8 @@ const _placeSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, name, de
c.latitude, c.latitude,
c.longitude, c.longitude,
p.created`} p.created`}
FROM acloc.places AS p FROM dbmaster.places AS p
JOIN acloc.coordinates AS c ON p.fk_coordinate = c.id JOIN dbmaster.coordinates AS c ON p.fk_coordinate = 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)
@ -41,7 +41,7 @@ const insertPlaceQuery = ({ description, address, createdBy }) => {
const addressCondition = address ? ':address' : null; const addressCondition = address ? ':address' : null;
const createdByCondition = createdBy ? 'createdBy = :createdBy' : null; const createdByCondition = createdBy ? 'createdBy = :createdBy' : null;
return ` return `
INSERT INTO acloc.places ( INSERT INTO dbmaster.places (
uuid, uuid,
name, name,
description, description,
@ -55,7 +55,7 @@ const insertPlaceQuery = ({ description, address, createdBy }) => {
:name, :name,
${descriptionCondition}, ${descriptionCondition},
${addressCondition}, ${addressCondition},
(SELECT id FROM acloc.coordinates WHERE latitude = :latitude AND longitude = :longitude), (SELECT id FROM dbmaster.coordinates WHERE latitude = :latitude AND longitude = :longitude),
:now, :now,
${createdByCondition} ${createdByCondition}
) )
@ -66,10 +66,10 @@ const updatePlaceQuery = ({ name, description, address, latitude, longitude }) =
const nameCondition = name ? 'name = :name,' : ''; const nameCondition = name ? 'name = :name,' : '';
const descriptionCondition = description ? 'description = :description,' : ''; const descriptionCondition = description ? 'description = :description,' : '';
const addressCondition = address ? 'address = :address' : ''; 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 ` return `
UPDATE acloc.places AS p UPDATE dbmaster.places AS p
SET SET
${nameCondition} ${nameCondition}
${descriptionCondition} ${descriptionCondition}
@ -85,7 +85,7 @@ const updatePlaceQuery = ({ name, description, address, latitude, longitude }) =
const deletePlaceQuery = () => { const deletePlaceQuery = () => {
return ` return `
UPDATE acloc.places AS p UPDATE dbmaster.places AS p
SET SET
deleted = :deleted, deletedby = :deletedBy deleted = :deleted, deletedby = :deletedBy
WHERE WHERE

View File

@ -6,7 +6,7 @@ const _coordinatesSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, na
return ` return `
SELECT ${count || SELECT ${count ||
`*`} `*`}
FROM acloc.report_types AS rt FROM dbmaster.report_types AS rt
WHERE rt.created <= :now WHERE rt.created <= :now
AND (rt.deleted > :now OR rt.deleted IS NULL) AND (rt.deleted > :now OR rt.deleted IS NULL)
AND true AND true
@ -24,7 +24,7 @@ const countReportTypesListQuery = rest =>
const insertReportTypesQuery = () => { const insertReportTypesQuery = () => {
return ` return `
INSERT INTO acloc.report_types ( INSERT INTO dbmaster.report_types (
uuid, uuid,
name, name,
created, created,
@ -36,33 +36,33 @@ const insertReportTypesQuery = () => {
:now, :now,
:createdBy :createdBy
); );
SELECT * FROM acloc.report_types WHERE uuid = :uuid; SELECT * FROM dbmaster.report_types WHERE uuid = :uuid;
` `
} }
const updateReportTypesQuery = (name) => { const updateReportTypesQuery = (name) => {
const nameCondition = name ? 'name = :name,' : ''; const nameCondition = name ? 'name = :name,' : '';
return ` return `
UPDATE acloc.report_types UPDATE dbmaster.report_types
SET SET
${nameCondition} ${nameCondition}
uuid = :uuid uuid = :uuid
WHERE uuid = :uuid WHERE uuid = :uuid
AND deleted IS NULL; AND deleted IS NULL;
SELECT * FROM acloc.report_types WHERE uuid = :uuid; SELECT * FROM dbmaster.report_types WHERE uuid = :uuid;
` `
} }
const softDeleteReportTypesQuery = () => { const softDeleteReportTypesQuery = () => {
return ` return `
UPDATE UPDATE
acloc.report_types dbmaster.report_types
SET SET
deleted = :deleted, deleted = :deleted,
deletedBy = :deletedBy deletedBy = :deletedBy
WHERE uuid = :uuid WHERE uuid = :uuid
AND deleted IS NULL; AND deleted IS NULL;
SELECT * FROM acloc.report_types WHERE uuid = :uuid; SELECT * FROM dbmaster.report_types WHERE uuid = :uuid;
` `
} }

View File

@ -2,9 +2,9 @@ import { pagination } from "../../utils/pagination.js";
//reports repository //reports repository
const _userHasPlacesSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, uuidUser, uuidPlace, uuidReportType, rating }) => { const _userHasPlacesSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, uuidUser, uuidPlace, uuidReportType, rating }) => {
const uuidCondition = uuid ? 'AND up.uuid = :uuid ' : ''; const uuidCondition = uuid ? 'AND up.uuid = :uuid ' : '';
const uuidUserCondition = uuidUser ? 'AND up.fk_user = (SELECT id FROM acloc.users WHERE uuid = :uuidUser)' : ''; 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 acloc.places WHERE uuid = :uuidPlace)' : ''; 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 acloc.report_types WHERE uuid = :uuidReportType)' : ''; const uuidReportTypeCondition = uuidReportType ? 'AND up.fk_report_type = (SELECT id FROM dbmaster.report_types WHERE uuid = :uuidReportType)' : '';
const ratingCondition = rating ? 'AND up.rating = :rating' : ''; const ratingCondition = rating ? 'AND up.rating = :rating' : '';
return ` return `
SELECT ${count || SELECT ${count ||
@ -15,10 +15,10 @@ const _userHasPlacesSelectQuery = (_pagination = '') => ({ count }) => ({ uuid,
p.uuid AS place_uuid, p.uuid AS place_uuid,
rt.name AS report_type_name, rt.name AS report_type_name,
rt.uuid AS report_type_uuid`} rt.uuid AS report_type_uuid`}
FROM acloc.users_has_places AS up FROM dbmaster.users_has_places AS up
JOIN acloc.users AS u ON up.fk_user = u.id JOIN dbmaster.users AS u ON up.fk_user = u.id
JOIN acloc.places AS p ON up.fk_place = p.id JOIN dbmaster.places AS p ON up.fk_place = p.id
JOIN acloc.report_types AS rt ON up.fk_report_type = rt.id JOIN dbmaster.report_types AS rt ON up.fk_report_type = rt.id
WHERE up.created <= :now WHERE up.created <= :now
AND (up.deleted > :now OR up.deleted IS NULL) AND (up.deleted > :now OR up.deleted IS NULL)
AND u.deleted IS NULL AND u.deleted IS NULL
@ -41,13 +41,13 @@ const countUserHasPlacesListQuery = rest =>
_userHasPlacesSelectQuery()({ count: 'COUNT(DISTINCT(up.uuid)) AS count' })(rest); _userHasPlacesSelectQuery()({ count: 'COUNT(DISTINCT(up.uuid)) AS count' })(rest);
const insertUserHasPlacesQuery = ({ uuidUser, uuidPlace, createdBy, uuidReportType }) => { const insertUserHasPlacesQuery = ({ uuidUser, uuidPlace, createdBy, uuidReportType }) => {
const uuidUserCondition = uuidUser ? '(SELECT id FROM acloc.users WHERE uuid = :uuidUser),' : null; const uuidUserCondition = uuidUser ? '(SELECT id FROM dbmaster.users WHERE uuid = :uuidUser),' : null;
const uuidPlaceCondition = uuidPlace ? '(SELECT id FROM acloc.places WHERE uuid = :uuidPlace),' : null; const uuidPlaceCondition = uuidPlace ? '(SELECT id FROM dbmaster.places WHERE uuid = :uuidPlace),' : null;
const createdByCondition = createdBy ? 'createdBy = :createdBy' : 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 ` return `
INSERT INTO acloc.users_has_places ( INSERT INTO dbmaster.users_has_places (
uuid, uuid,
fk_user, fk_user,
fk_place, fk_place,
@ -65,17 +65,17 @@ const insertUserHasPlacesQuery = ({ uuidUser, uuidPlace, createdBy, uuidReportTy
:now, :now,
${createdByCondition} ${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 modifyUserHasPlacesQuery = (uuidUser, uuidPlace, uuidReportType, rating) => {
const uuidUserCondition = uuidUser ? 'fk_user = (SELECT id FROM acloc.users WHERE uuid = :uuidUser)' : ``; const uuidUserCondition = uuidUser ? 'fk_user = (SELECT id FROM dbmaster.users WHERE uuid = :uuidUser)' : ``;
const uuidPlaceCondition = uuidPlace ? 'fk_place = (SELECT id FROM acloc.places WHERE uuid = :uuidPlace)' : ``; const uuidPlaceCondition = uuidPlace ? 'fk_place = (SELECT id FROM dbmaster.places WHERE uuid = :uuidPlace)' : ``;
const uuidReportTypeCondition = uuidReportType ? 'fk_report_type = (SELECT id FROM acloc.report_types WHERE uuid = :uuidReportType)' : ``; const uuidReportTypeCondition = uuidReportType ? 'fk_report_type = (SELECT id FROM dbmaster.report_types WHERE uuid = :uuidReportType)' : ``;
const ratingCondition = rating ? 'rating = :rating' : ``; const ratingCondition = rating ? 'rating = :rating' : ``;
return ` return `
UPDATE acloc.users_has_places UPDATE dbmaster.users_has_places
SET SET
${uuidUserCondition} ${uuidUserCondition}
${uuidPlaceCondition} ${uuidPlaceCondition}
@ -86,14 +86,14 @@ const modifyUserHasPlacesQuery = (uuidUser, uuidPlace, uuidReportType, rating) =
users_has_places.uuid = :uuid users_has_places.uuid = :uuid
AND AND
users_has_places.deleted IS NULL; 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 = () => { const softDeleteUserHasPlacesQuery = () => {
return ` return `
UPDATE UPDATE
acloc.users_has_places dbmaster.users_has_places
SET SET
deleted = :deleted, deletedBy = :deletedBy deleted = :deleted, deletedBy = :deletedBy
WHERE WHERE