fixed insert and modify queries and parsing
This commit is contained in:
parent
82d85ac864
commit
145f482d2f
|
|
@ -26,7 +26,7 @@ const insertUserHasPlacesModel = ({conn, ...params}) => {
|
||||||
const uuid = uuidv4()
|
const uuid = uuidv4()
|
||||||
return mysql
|
return mysql
|
||||||
.execute(insertUserHasPlacesQuery({...params, uuid, now}), conn, {...params, uuid, now})
|
.execute(insertUserHasPlacesQuery({...params, uuid, now}), conn, {...params, uuid, now})
|
||||||
.then(queryResult => queryResult[1].map(({id, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
.then(queryResult => queryResult[2].map(({id, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
||||||
}
|
}
|
||||||
|
|
||||||
const modifyUserHasPlacesModel = ({conn, ...params}) => {
|
const modifyUserHasPlacesModel = ({conn, ...params}) => {
|
||||||
|
|
@ -39,7 +39,7 @@ const modifyUserHasPlacesModel = ({conn, ...params}) => {
|
||||||
if (deletedItem) {
|
if (deletedItem) {
|
||||||
throw error404()
|
throw error404()
|
||||||
}
|
}
|
||||||
return queryResult[1].map(({id, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered)
|
return queryResult[2].map(({id, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,15 @@ const insertUserHasPlacesQuery = ({ user_uuid, place_uuid, description, createdB
|
||||||
const modifyUserHasPlacesQuery = ({user_uuid, place_uuid, report_type_uuid, rating, images, description}) => {
|
const modifyUserHasPlacesQuery = ({user_uuid, place_uuid, report_type_uuid, rating, images, description}) => {
|
||||||
const user_uuidCondition = user_uuid ? 'fk_user = (SELECT id FROM dbmaster.users WHERE uuid = :user_uuid),' : '';
|
const user_uuidCondition = user_uuid ? 'fk_user = (SELECT id FROM dbmaster.users WHERE uuid = :user_uuid),' : '';
|
||||||
const place_uuidCondition = place_uuid ? 'fk_place = (SELECT id FROM dbmaster.places WHERE uuid = :place_uuid),' : '';
|
const place_uuidCondition = place_uuid ? 'fk_place = (SELECT id FROM dbmaster.places WHERE uuid = :place_uuid),' : '';
|
||||||
const report_type_uuidCondition = report_type_uuid ? `DELETE FROM dbmaster.report_report_type WHERE report_uuid = :uuid; ${report_type_uuid.map(rt => `INSERT INTO dbmaster.report_report_type (report_uuid, report_type_uuid) VALUES (:uuid, '${rt}');`).join(' ')}` : '';
|
const report_type_uuidCondition = report_type_uuid !== undefined
|
||||||
|
? `DELETE FROM dbmaster.report_report_type WHERE report_uuid = :uuid;${
|
||||||
|
Array.isArray(report_type_uuid) && report_type_uuid.length > 0
|
||||||
|
? ' ' + report_type_uuid.map(rt =>
|
||||||
|
`INSERT INTO dbmaster.report_report_type (report_uuid, report_type_uuid) VALUES (:uuid, '${rt}');`
|
||||||
|
).join(' ')
|
||||||
|
: ''
|
||||||
|
}`
|
||||||
|
: '';
|
||||||
const ratingCondition = rating ? 'rating = :rating,' : '';
|
const ratingCondition = rating ? 'rating = :rating,' : '';
|
||||||
const imagesCondition = images ? 'images = :images,' : '';
|
const imagesCondition = images ? 'images = :images,' : '';
|
||||||
const descriptionCondition = description ? 'description = :description,' : '';
|
const descriptionCondition = description ? 'description = :description,' : '';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue