fixed errors in mysql syntax

This commit is contained in:
Pau 2025-04-18 13:58:28 +02:00
parent d9444aad10
commit ede0d821af
4 changed files with 33 additions and 31 deletions

View File

@ -55,7 +55,7 @@ const insertPermissionsQuery = (createdBy) => {
}
const modifyPermissionsQuery = (action, endpoint) => {
const actionCondition = action ? 'action = :action ,' : '';
const actionCondition = action ? 'action = :action,' : '';
const endpointCondition = endpoint ? 'fk_endpoint = (SELECT id from dbmaster.endpoints WHERE route = :endpoint),' : '';
return `
UPDATE dbmaster.permissions AS permissions

View File

@ -61,9 +61,9 @@ const countUserListQuery = rest =>
* @returns {String} INSERT query
*/
const insertUserQuery = ({email, fk_role, createdBy}) => {
const emailCondition = email ? ':email' : null;
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 emailCondition = email ? ':email,' : null;
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 dbmaster.users (
uuid,
@ -71,17 +71,17 @@ const insertUserQuery = ({email, fk_role, createdBy}) => {
password,
email,
fk_role,
created,
createdBy
createdBy,
created
)
VALUES (
:uuid,
:username,
:password,
${emailCondition},
${roleCondition},
:now,
${emailCondition}
${roleCondition}
${createdByCondition}
:now
);
SELECT * FROM dbmaster.users WHERE uuid = :uuid;
`
@ -95,7 +95,7 @@ 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 dbmaster.roles WHERE name = :role) ` : ``;
const roleCondition = role ? `fk_role = (SELECT id FROM dbmaster.roles WHERE name = :role),` : ``;
return `
UPDATE

View File

@ -38,9 +38,9 @@ const countPlaceListQuery = rest =>
_placeSelectQuery()({ count: 'COUNT(DISTINCT(p.uuid)) AS count' })(rest);
const insertPlaceQuery = ({ description, address, createdBy }) => {
const descriptionCondition = description ? ':description' : null;
const addressCondition = address ? ':address' : null;
const createdByCondition = createdBy ? 'createdBy = :createdBy' : null;
const descriptionCondition = description ? ':description,' : null;
const addressCondition = address ? ':address,' : null;
const createdByCondition = createdBy ? 'createdBy = :createdBy,' : null;
return `
INSERT INTO dbmaster.places (
uuid,
@ -48,19 +48,20 @@ const insertPlaceQuery = ({ description, address, createdBy }) => {
description,
address,
longitude,
latitude
created,
createdBy
latitude,
createdBy,
created
)
VALUES (
:uuid,
:name,
${descriptionCondition},
${addressCondition},
:longitude
${descriptionCondition}
${addressCondition}
:longitude,
:latitude,
:now,
${createdByCondition}
:now
)
`;
}
@ -68,9 +69,9 @@ const insertPlaceQuery = ({ description, address, createdBy }) => {
const updatePlaceQuery = ({ name, description, address, latitude, longitude }) => {
const nameCondition = name ? 'name = :name,' : '';
const descriptionCondition = description ? 'description = :description,' : '';
const addressCondition = address ? 'address = :address' : '';
const longitudeCondition = longitude ? 'longitude = :longitude' : '';
const latitudeCondition = latitude ? 'latitude = :latitude' : '';
const addressCondition = address ? 'address = :address,' : '';
const longitudeCondition = longitude ? 'longitude = :longitude,' : '';
const latitudeCondition = latitude ? 'latitude = :latitude,' : '';
return `
UPDATE dbmaster.places AS p
@ -80,6 +81,7 @@ const updatePlaceQuery = ({ name, description, address, latitude, longitude }) =
${addressCondition}
${longitudeCondition}
${latitudeCondition}
dbmaster.places.created = dbmaster.places.created,
WHERE
p.uuid = :uuid
AND p.deleted IS NULL

View File

@ -43,7 +43,7 @@ const countUserHasPlacesListQuery = rest =>
const insertUserHasPlacesQuery = ({ uuidUser, uuidPlace, createdBy, uuidReportType }) => {
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 createdByCondition = createdBy ? 'createdBy = :createdBy,' : null;
const reportTypeCondition = uuidReportType ? '(SELECT id FROM dbmaster.report_types WHERE uuid = :reportType),' : null;
return `
@ -53,8 +53,8 @@ const insertUserHasPlacesQuery = ({ uuidUser, uuidPlace, createdBy, uuidReportTy
fk_place,
fk_report_type,
rating,
created,
createdBy
createdBy,
created
)
VALUES (
:uuid
@ -62,18 +62,18 @@ const insertUserHasPlacesQuery = ({ uuidUser, uuidPlace, createdBy, uuidReportTy
${uuidPlaceCondition}
${reportTypeCondition}
:rating,
:now,
${createdByCondition}
:now
);
SELECT * FROM dbmaster.users_has_places WHERE uuid = :uuid;
`
}
const modifyUserHasPlacesQuery = (uuidUser, uuidPlace, uuidReportType, rating) => {
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' : ``;
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 dbmaster.users_has_places
SET