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 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),' : ''; const endpointCondition = endpoint ? 'fk_endpoint = (SELECT id from dbmaster.endpoints WHERE route = :endpoint),' : '';
return ` return `
UPDATE dbmaster.permissions AS permissions UPDATE dbmaster.permissions AS permissions

View File

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

View File

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

View File

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