fixed problems regarding requests and sql syntax
This commit is contained in:
parent
cf7c3b9b60
commit
2f56e3f37d
|
|
@ -20,7 +20,7 @@ const getUserHasPlacesListController = (req, res, next, config) => {
|
||||||
])
|
])
|
||||||
.then(([getResults, countResults]) => {
|
.then(([getResults, countResults]) => {
|
||||||
next({
|
next({
|
||||||
_data: {usersHasPlaces: getResults},
|
_data: {reports: getResults},
|
||||||
_page: {
|
_page: {
|
||||||
totalElements: countResults,
|
totalElements: countResults,
|
||||||
limit: req.query.limit || 100,
|
limit: req.query.limit || 100,
|
||||||
|
|
@ -41,7 +41,7 @@ const getUserHasPlacesByUuidController = (req, res, next, config) => {
|
||||||
const uuid_user_has_places = req.params.uuid
|
const uuid_user_has_places = req.params.uuid
|
||||||
const conn = mysql.start(config)
|
const conn = mysql.start(config)
|
||||||
|
|
||||||
getUserHasPlacesListModel({ uuid_user_has_places, conn })
|
getUserHasPlacesListModel({ uuid: uuid_user_has_places, conn })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (noResults(response)) {
|
if (noResults(response)) {
|
||||||
const err = error404()
|
const err = error404()
|
||||||
|
|
@ -51,7 +51,7 @@ const getUserHasPlacesByUuidController = (req, res, next, config) => {
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
_data: {
|
_data: {
|
||||||
usersHasPlaces: response
|
reports: response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next(result)
|
next(result)
|
||||||
|
|
@ -69,7 +69,7 @@ const getUserHasPlacesByUserUuidController = (req, res, next, config) => {
|
||||||
const uuid_user = req.params.uuid
|
const uuid_user = req.params.uuid
|
||||||
const conn = mysql.start(config)
|
const conn = mysql.start(config)
|
||||||
|
|
||||||
getUserHasPlacesListModel({ uuid_user, conn })
|
getUserHasPlacesListModel({ user_uuid: uuid_user, conn })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (noResults(response)) {
|
if (noResults(response)) {
|
||||||
const err = error404()
|
const err = error404()
|
||||||
|
|
@ -79,7 +79,7 @@ const getUserHasPlacesByUserUuidController = (req, res, next, config) => {
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
_data: {
|
_data: {
|
||||||
usersHasPlaces: response
|
reports: response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next(result)
|
next(result)
|
||||||
|
|
@ -97,7 +97,7 @@ const getUserHasPlacesByPlaceUuidController = (req, res, next, config) => {
|
||||||
const uuid_place = req.params.uuid
|
const uuid_place = req.params.uuid
|
||||||
const conn = mysql.start(config)
|
const conn = mysql.start(config)
|
||||||
|
|
||||||
getUserHasPlacesListModel({ uuid_place, conn })
|
getUserHasPlacesListModel({ place_uuid: uuid_place, conn })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (noResults(response)) {
|
if (noResults(response)) {
|
||||||
const err = error404()
|
const err = error404()
|
||||||
|
|
@ -107,7 +107,7 @@ const getUserHasPlacesByPlaceUuidController = (req, res, next, config) => {
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
_data: {
|
_data: {
|
||||||
usersHasPlaces: response
|
reports: response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next(result)
|
next(result)
|
||||||
|
|
@ -128,7 +128,7 @@ const postUserHasPlacesController = (req, res, next, config) => {
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const result = {
|
const result = {
|
||||||
_data: {
|
_data: {
|
||||||
usersHasPlaces: response
|
reports: response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next(result)
|
next(result)
|
||||||
|
|
@ -149,7 +149,7 @@ const putUserHasPlacesController = (req, res, next, config) => {
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const result = {
|
const result = {
|
||||||
_data: {
|
_data: {
|
||||||
usersHasPlaces: response
|
reports: response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next(result)
|
next(result)
|
||||||
|
|
@ -168,7 +168,7 @@ const deleteUserHasPlacesController = (req, res, next, config) => {
|
||||||
const uuid_user_has_places = req.params.uuid
|
const uuid_user_has_places = req.params.uuid
|
||||||
const deleted_by = req.auth.user || null
|
const deleted_by = req.auth.user || null
|
||||||
|
|
||||||
softDeleteUserHasPlacesModel({uuid_user_has_places, deleted_by, conn})
|
softDeleteUserHasPlacesModel({uuid: uuid_user_has_places, deleted_by, conn})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
next({})
|
next({})
|
||||||
})
|
})
|
||||||
|
|
@ -186,7 +186,7 @@ const deleteUserHasPlacesByUserUuidController = (req, res, next, config) => {
|
||||||
const uuid_user = req.params.uuid
|
const uuid_user = req.params.uuid
|
||||||
const deleted_by = req.auth.user || null
|
const deleted_by = req.auth.user || null
|
||||||
|
|
||||||
softDeleteUserHasPlacesModel({uuid_user, deleted_by, conn})
|
softDeleteUserHasPlacesModel({user_uuid: uuid_user, deleted_by, conn})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
next({})
|
next({})
|
||||||
})
|
})
|
||||||
|
|
@ -204,7 +204,7 @@ const deleteUserHasPlacesByPlaceUuidController = (req, res, next, config) => {
|
||||||
const uuid_place = req.params.uuid
|
const uuid_place = req.params.uuid
|
||||||
const deleted_by = req.auth.user || null
|
const deleted_by = req.auth.user || null
|
||||||
|
|
||||||
softDeleteUserHasPlacesModel({uuid_place, deleted_by, conn})
|
softDeleteUserHasPlacesModel({place_uuid: uuid_place, deleted_by, conn})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
next({})
|
next({})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -78,9 +78,9 @@ const insertUserQuery = ({email, fk_role, createdBy}) => {
|
||||||
:uuid,
|
:uuid,
|
||||||
:username,
|
:username,
|
||||||
:password,
|
:password,
|
||||||
${emailCondition}
|
${emailCondition},
|
||||||
${roleCondition}
|
${roleCondition}
|
||||||
${createdByCondition}
|
${createdByCondition},
|
||||||
:now
|
:now
|
||||||
);
|
);
|
||||||
SELECT * FROM dbmaster.users WHERE uuid = :uuid;
|
SELECT * FROM dbmaster.users WHERE uuid = :uuid;
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
@ -55,11 +55,11 @@ const insertPlaceQuery = ({ description, address, createdBy }) => {
|
||||||
VALUES (
|
VALUES (
|
||||||
:uuid,
|
:uuid,
|
||||||
:name,
|
:name,
|
||||||
${descriptionCondition}
|
${descriptionCondition},
|
||||||
${addressCondition}
|
${addressCondition},
|
||||||
:longitude,
|
:longitude,
|
||||||
:latitude,
|
:latitude,
|
||||||
${createdByCondition}
|
${createdByCondition},
|
||||||
:now
|
:now
|
||||||
);
|
);
|
||||||
SELECT * FROM dbmaster.places WHERE uuid = :uuid;
|
SELECT * FROM dbmaster.places WHERE uuid = :uuid;
|
||||||
|
|
@ -81,7 +81,7 @@ const updatePlaceQuery = ({ name, description, address, latitude, longitude }) =
|
||||||
${addressCondition}
|
${addressCondition}
|
||||||
${longitudeCondition}
|
${longitudeCondition}
|
||||||
${latitudeCondition}
|
${latitudeCondition}
|
||||||
uuid = :uuid,
|
uuid = :uuid
|
||||||
WHERE
|
WHERE
|
||||||
p.uuid = :uuid
|
p.uuid = :uuid
|
||||||
AND p.deleted IS NULL
|
AND p.deleted IS NULL
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { pagination } from "../../utils/pagination.js";
|
import { pagination } from "../../utils/pagination.js";
|
||||||
//reports repository
|
//reports repository
|
||||||
const _userHasPlacesSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, uuidUser, uuidPlace, uuidReportType, rating }) => {
|
const _userHasPlacesSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, user_uuid, place_uuid, report_type_uuid, 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 dbmaster.users WHERE uuid = :uuidUser)' : '';
|
const user_uuidCondition = user_uuid ? 'AND up.fk_user = (SELECT id FROM dbmaster.users WHERE uuid = :user_uuid)' : '';
|
||||||
const uuidPlaceCondition = uuidPlace ? 'AND up.fk_place = (SELECT id FROM dbmaster.places WHERE uuid = :uuidPlace)' : '';
|
const place_uuidCondition = place_uuid ? 'AND up.fk_place = (SELECT id FROM dbmaster.places WHERE uuid = :place_uuid)' : '';
|
||||||
const uuidReportTypeCondition = uuidReportType ? 'AND up.fk_report_type = (SELECT id FROM dbmaster.report_types WHERE uuid = :uuidReportType)' : '';
|
const report_type_uuidCondition = report_type_uuid ? 'AND up.fk_report_type = (SELECT id FROM dbmaster.report_types WHERE uuid = :report_type_uuid)' : '';
|
||||||
const ratingCondition = rating ? 'AND up.rating = :rating' : '';
|
const ratingCondition = rating ? 'AND up.rating = :rating' : '';
|
||||||
return `
|
return `
|
||||||
SELECT ${count ||
|
SELECT ${count ||
|
||||||
|
|
@ -26,9 +26,9 @@ const _userHasPlacesSelectQuery = (_pagination = '') => ({ count }) => ({ uuid,
|
||||||
AND rt.deleted IS NULL
|
AND rt.deleted IS NULL
|
||||||
AND true
|
AND true
|
||||||
${uuidCondition}
|
${uuidCondition}
|
||||||
${uuidUserCondition}
|
${user_uuidCondition}
|
||||||
${uuidPlaceCondition}
|
${place_uuidCondition}
|
||||||
${uuidReportTypeCondition}
|
${report_type_uuidCondition}
|
||||||
${ratingCondition}
|
${ratingCondition}
|
||||||
${_pagination}
|
${_pagination}
|
||||||
`;
|
`;
|
||||||
|
|
@ -40,11 +40,11 @@ const getUserHasPlacesListQuery = ({ limit, page, ...rest }) =>
|
||||||
const countUserHasPlacesListQuery = rest =>
|
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 = ({ user_uuid, place_uuid, createdBy, report_type_uuid }) => {
|
||||||
const uuidUserCondition = uuidUser ? '(SELECT id FROM dbmaster.users WHERE uuid = :uuidUser),' : null;
|
const user_uuidCondition = user_uuid ? '(SELECT id FROM dbmaster.users WHERE uuid = :user_uuid)' : null;
|
||||||
const uuidPlaceCondition = uuidPlace ? '(SELECT id FROM dbmaster.places WHERE uuid = :uuidPlace),' : null;
|
const place_uuidCondition = place_uuid ? '(SELECT id FROM dbmaster.places WHERE uuid = :place_uuid)' : 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 = report_type_uuid ? '(SELECT id FROM dbmaster.report_types WHERE uuid = :reportType)' : null;
|
||||||
|
|
||||||
return `
|
return `
|
||||||
INSERT INTO dbmaster.users_has_places (
|
INSERT INTO dbmaster.users_has_places (
|
||||||
|
|
@ -57,29 +57,29 @@ const insertUserHasPlacesQuery = ({ uuidUser, uuidPlace, createdBy, uuidReportTy
|
||||||
created
|
created
|
||||||
)
|
)
|
||||||
VALUES (
|
VALUES (
|
||||||
:uuid
|
:uuid,
|
||||||
${uuidUserCondition}
|
${user_uuidCondition},
|
||||||
${uuidPlaceCondition}
|
${place_uuidCondition},
|
||||||
${reportTypeCondition}
|
${reportTypeCondition},
|
||||||
:rating,
|
:rating,
|
||||||
${createdByCondition}
|
${createdByCondition},
|
||||||
:now
|
: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 = (user_uuid, place_uuid, report_type_uuid, rating) => {
|
||||||
const uuidUserCondition = uuidUser ? 'fk_user = (SELECT id FROM dbmaster.users WHERE uuid = :uuidUser),' : ``;
|
const user_uuidCondition = user_uuid ? 'fk_user = (SELECT id FROM dbmaster.users WHERE uuid = :user_uuid),' : ``;
|
||||||
const uuidPlaceCondition = uuidPlace ? 'fk_place = (SELECT id FROM dbmaster.places WHERE uuid = :uuidPlace),' : ``;
|
const place_uuidCondition = place_uuid ? 'fk_place = (SELECT id FROM dbmaster.places WHERE uuid = :place_uuid),' : ``;
|
||||||
const uuidReportTypeCondition = uuidReportType ? 'fk_report_type = (SELECT id FROM dbmaster.report_types WHERE uuid = :uuidReportType),' : ``;
|
const report_type_uuidCondition = report_type_uuid ? 'fk_report_type = (SELECT id FROM dbmaster.report_types WHERE uuid = :report_type_uuid),' : ``;
|
||||||
const ratingCondition = rating ? 'rating = :rating,' : ``;
|
const ratingCondition = rating ? 'rating = :rating,' : ``;
|
||||||
return `
|
return `
|
||||||
UPDATE dbmaster.users_has_places
|
UPDATE dbmaster.users_has_places
|
||||||
SET
|
SET
|
||||||
${uuidUserCondition}
|
${user_uuidCondition}
|
||||||
${uuidPlaceCondition}
|
${place_uuidCondition}
|
||||||
${uuidReportTypeCondition}
|
${report_type_uuidCondition}
|
||||||
${ratingCondition}
|
${ratingCondition}
|
||||||
uuid = :uuid
|
uuid = :uuid
|
||||||
WHERE
|
WHERE
|
||||||
|
|
|
||||||
|
|
@ -1071,9 +1071,9 @@ export default(config) => {
|
||||||
(req, res, next) => authorizePermission('/reports')(req, res, next, config),
|
(req, res, next) => authorizePermission('/reports')(req, res, next, config),
|
||||||
[
|
[
|
||||||
uuid('uuid'),
|
uuid('uuid'),
|
||||||
uuid('uuidPlace').optional({ nullable: false, values: 'falsy' }),
|
uuid('place_uuid').optional({ nullable: false, values: 'falsy' }),
|
||||||
uuid('uuidUser').optional({ nullable: false, values: 'falsy' }),
|
uuid('user_uuid').optional({ nullable: false, values: 'falsy' }),
|
||||||
uuid('uuidReportType').optional({ nullable: false, values: 'falsy' }),
|
uuid('report_type_uuid').optional({ nullable: false, values: 'falsy' }),
|
||||||
integerRange('rating', {min: 1, max: 3}).optional({ nullable: false, values: 'falsy' })
|
integerRange('rating', {min: 1, max: 3}).optional({ nullable: false, values: 'falsy' })
|
||||||
],
|
],
|
||||||
(req, res, next) => payloadExpressValidator(req, res, next, config),
|
(req, res, next) => payloadExpressValidator(req, res, next, config),
|
||||||
|
|
@ -1105,9 +1105,9 @@ export default(config) => {
|
||||||
(req, res, next) => authorizePermission('/reports/:uuid')(req, res, next, config),
|
(req, res, next) => authorizePermission('/reports/:uuid')(req, res, next, config),
|
||||||
[
|
[
|
||||||
uuid('uuid'),
|
uuid('uuid'),
|
||||||
uuid('uuidPlace').optional({ nullable: false, values: 'falsy' }),
|
uuid('place_uuid').optional({ nullable: false, values: 'falsy' }),
|
||||||
uuid('uuidUser').optional({ nullable: false, values: 'falsy' }),
|
uuid('user_uuid').optional({ nullable: false, values: 'falsy' }),
|
||||||
uuid('uuidReportType').optional({ nullable: false, values: 'falsy' }),
|
uuid('report_type_uuid').optional({ nullable: false, values: 'falsy' }),
|
||||||
integerRange('rating', {min: 1, max: 3}).optional({ nullable: false, values: 'falsy' })
|
integerRange('rating', {min: 1, max: 3}).optional({ nullable: false, values: 'falsy' })
|
||||||
],
|
],
|
||||||
(req, res, next) => payloadExpressValidator(req, res, next, config),
|
(req, res, next) => payloadExpressValidator(req, res, next, config),
|
||||||
|
|
@ -1139,9 +1139,9 @@ export default(config) => {
|
||||||
(req, res, next) => authenticateToken(req, res, next, config),
|
(req, res, next) => authenticateToken(req, res, next, config),
|
||||||
(req, res, next) => authorizePermission('/reports')(req, res, next, config),
|
(req, res, next) => authorizePermission('/reports')(req, res, next, config),
|
||||||
[
|
[
|
||||||
uuid('uuidPlace'),
|
uuid('place_uuid'),
|
||||||
uuid('uuidUser'),
|
uuid('user_uuid'),
|
||||||
uuid('uuidReportType'),
|
uuid('report_type_uuid').optional({ nullable: false, values: 'falsy' }),
|
||||||
integerRange('rating', {min: 1, max: 3}),
|
integerRange('rating', {min: 1, max: 3}),
|
||||||
varChar('description').optional({ nullable: true, values: 'falsy' }),
|
varChar('description').optional({ nullable: true, values: 'falsy' }),
|
||||||
],
|
],
|
||||||
|
|
@ -1176,9 +1176,9 @@ export default(config) => {
|
||||||
(req, res, next) => authorizePermission('/reports/:uuid')(req, res, next, config),
|
(req, res, next) => authorizePermission('/reports/:uuid')(req, res, next, config),
|
||||||
[
|
[
|
||||||
uuid('uuid'),
|
uuid('uuid'),
|
||||||
uuid('uuidPlace').optional({ nullable: false, values: 'falsy' }),
|
uuid('place_uuid').optional({ nullable: false, values: 'falsy' }),
|
||||||
uuid('uuidUser').optional({ nullable: false, values: 'falsy' }),
|
uuid('user_uuid').optional({ nullable: false, values: 'falsy' }),
|
||||||
uuid('uuidReportType').optional({ nullable: false, values: 'falsy' }),
|
uuid('report_type_uuid').optional({ nullable: false, values: 'falsy' }),
|
||||||
integerRange('rating', {min: 1, max: 3}).optional({ nullable: false, values: 'falsy' }),
|
integerRange('rating', {min: 1, max: 3}).optional({ nullable: false, values: 'falsy' }),
|
||||||
varChar('description').optional({ nullable: true, values: 'falsy' }),
|
varChar('description').optional({ nullable: true, values: 'falsy' }),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue