altered users has places to better resemble API RESTful structure
This commit is contained in:
parent
1faf6b95a9
commit
372278e669
|
|
@ -15,7 +15,7 @@ const getUserHasPlacesListController = (req, res, next, config) => {
|
||||||
const conn = mysql.start(config)
|
const conn = mysql.start(config)
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
getUserHasPlacesListModel({...req.query, conn}),
|
getUserHasPlacesListModel({...req.query, ...req.body, ...req.params, conn}),
|
||||||
countUserHasPlacesListModel({...req.query, conn})
|
countUserHasPlacesListModel({...req.query, conn})
|
||||||
])
|
])
|
||||||
.then(([getResults, countResults]) => {
|
.then(([getResults, countResults]) => {
|
||||||
|
|
@ -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: uuid_user_has_places, conn })
|
getUserHasPlacesListModel({ uuid: uuid_user_has_places, ...req.params, ...req.body, conn })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (noResults(response)) {
|
if (noResults(response)) {
|
||||||
const err = error404()
|
const err = error404()
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,8 @@ const insertUserHasPlacesQuery = ({ user_uuid, place_uuid, description, createdB
|
||||||
const place_uuidCondition = place_uuid ? '(SELECT id FROM dbmaster.places WHERE uuid = :place_uuid)' : 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 descriptionCondition = description ? 'description = :description' : null;
|
const descriptionCondition = description ? 'description = :description' : null;
|
||||||
const reportTypeCondition = report_type_uuid ? '(SELECT id FROM dbmaster.report_types WHERE uuid = :reportType)' : null;
|
const reportTypeCondition = report_type_uuid ? `(SELECT id FROM dbmaster.report_types WHERE uuid = :report_type_uuid)` : null;
|
||||||
|
|
||||||
|
|
||||||
return `
|
return `
|
||||||
INSERT INTO dbmaster.users_has_places (
|
INSERT INTO dbmaster.users_has_places (
|
||||||
|
|
|
||||||
|
|
@ -1116,6 +1116,89 @@ export default(config) => {
|
||||||
(result, req, res, _) => sendOkResponse(result, req, res)
|
(result, req, res, _) => sendOkResponse(result, req, res)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name GET/users/:user_uuid/reports
|
||||||
|
* @function
|
||||||
|
* @inner
|
||||||
|
* @memberof placeRouter
|
||||||
|
* @route GET /users/:user_uuid/reports
|
||||||
|
* @group Reports - Operations about reports
|
||||||
|
* @param {string} uuid.path.optional - The unique identifier for the report
|
||||||
|
* @param {string} fk_place.path.optional - The unique identifier for the place
|
||||||
|
* @param {string} fk_user.path.required - The unique identifier for the user
|
||||||
|
* @param {string} fk_report_type.path.optional - The unique identifier for the report type
|
||||||
|
* @param {string} rating.path.optional - The rating of the report
|
||||||
|
* @param {string} description.path.optional - The description of the report
|
||||||
|
* @returns {SuccessResponse} 200 - The report object
|
||||||
|
* @returns {ErrorResponse} 404 - Report not found
|
||||||
|
* @returns {ErrorResponse} 422 - Unprocessable entity
|
||||||
|
* @returns {ErrorResponse} 500 - Internal server error
|
||||||
|
* @returns {ErrorResponse} 403 - Forbidden
|
||||||
|
* @returns {ErrorResponse} 401 - Unauthorized
|
||||||
|
*/
|
||||||
|
routes.get(
|
||||||
|
'/users/:user_uuid/reports',
|
||||||
|
(req, res, next) => authenticateToken(req, res, next, config),
|
||||||
|
(req, res, next) => authorizePermission('/users/:user_uuid/reports')(req, res, next, config),
|
||||||
|
[
|
||||||
|
uuid('user_uuid'),
|
||||||
|
uuid('uuid').optional({ nullable: false, values: 'falsy' }),
|
||||||
|
uuid('place_uuid').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' }),
|
||||||
|
varChar('description').optional({ nullable: true, values: 'falsy' })
|
||||||
|
],
|
||||||
|
(req, res, next) => payloadExpressValidator(req, res, next, config),
|
||||||
|
(req, res, next) => getUserHasPlacesListController(req, res, next, config),
|
||||||
|
(result, req, res, next) => addLinks(result, req, res, next, hasAddLinks, linkRoutes),
|
||||||
|
(result, req, res) => sendOkResponse(result, req, res)
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name GET/places/:place_uuid/reports
|
||||||
|
* @function
|
||||||
|
* @inner
|
||||||
|
* @memberof placeRouter
|
||||||
|
* @route GET /places/:place_uuid/reports
|
||||||
|
* @group Reports - Operations about reports
|
||||||
|
* @param {string} uuid.path.optional - The unique identifier for the report
|
||||||
|
* @param {string} fk_place.path.required - The unique identifier for the place
|
||||||
|
* @param {string} fk_user.path.optional - The unique identifier for the user
|
||||||
|
* @param {string} fk_report_type.path.optional - The unique identifier for the report type
|
||||||
|
* @param {string} rating.path.optional - The rating of the report
|
||||||
|
* @param {string} description.path.optional - The description of the report
|
||||||
|
* @returns {SuccessResponse} 200 - The report object
|
||||||
|
* @returns {ErrorResponse} 404 - Report not found
|
||||||
|
* @returns {ErrorResponse} 422 - Unprocessable entity
|
||||||
|
* @returns {ErrorResponse} 500 - Internal server error
|
||||||
|
* @returns {ErrorResponse} 403 - Forbidden
|
||||||
|
* @returns {ErrorResponse} 401 - Unauthorized
|
||||||
|
* @returns {ErrorResponse} 400 - Bad request
|
||||||
|
*/
|
||||||
|
routes.get(
|
||||||
|
'/places/:place_uuid/reports',
|
||||||
|
(req, res, next) => authenticateToken(req, res, next, config),
|
||||||
|
(req, res, next) => authorizePermission('/places/:place_uuid/reports')(req, res, next, config),
|
||||||
|
[
|
||||||
|
uuid('uuid').optional({ nullable: false, values: 'falsy' }),
|
||||||
|
uuid('place_uuid'),
|
||||||
|
uuid('user_uuid').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' }),
|
||||||
|
varChar('description').optional({ nullable: true, values: 'falsy' })
|
||||||
|
],
|
||||||
|
(req, res, next) => payloadExpressValidator(req, res, next, config),
|
||||||
|
// Interceptamos el parámetro y lo pasamos como query para reutilizar el mismo controlador
|
||||||
|
(req, res, next) => {
|
||||||
|
req.query.place_uuid = req.params.place_uuid;
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
(req, res, next) => getUserHasPlacesListController(req, res, next, config),
|
||||||
|
(result, req, res, next) => addLinks(result, req, res, next, hasAddLinks, linkRoutes),
|
||||||
|
(result, req, res) => sendOkResponse(result, req, res)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name POST/reports
|
* @name POST/reports
|
||||||
* @function
|
* @function
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue