repositories updated to include url of images

This commit is contained in:
Pau 2025-05-09 02:12:12 +02:00
parent 8297962644
commit c5fd8c4dc5
3 changed files with 30 additions and 7 deletions

View File

@ -9,16 +9,22 @@ import config from './config/index.js'
import routes from './routes/index.js'
import { error404, errorHandler } from './utils/errors.js'
import { getRoutes } from './utils/links.js'
/*import { fileURLToPath } from 'node:url'
import { fileURLToPath } from 'node:url'
import { dirname } from 'node:path'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)*/
const __dirname = dirname(__filename)
const app = express()
dayjs.extend(utc)
const { NODE_ENV } = process.env
/*//Verify that upload directory exists
const uploadsDir = path.join(__dirname, 'uploads');
if (!file.existsSync(uploadsDir)) {
file.mkdirSync(uploadsDir, { recursive: true });
}*/
/**
* MIDDLEWARE------------------------------------------
*/
@ -36,7 +42,7 @@ app.use(express.urlencoded({extended: false}));
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Methods', 'GET,PATCH,POST,DELETE')
res.header('Access-Control-Allow-Methods', 'GET,PATCH,PUT,POST,DELETE')
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Client-Version')
next()
})
@ -49,6 +55,8 @@ const linkRoutes = { ...links1 }
app.use('/', r1)
app.use('/public', express.static(path.join(__dirname, 'uploads')));
// APPLICATION LAUNCHER ------------------------------------------------------------------
// 404 - Not found
app.use((req, res) => {
@ -66,9 +74,14 @@ app.use((req, res) => {
const port = config.port || 3000
const server = (NODE_ENV === 'development' ? app : https.createServer(httpsOptions(), app)).listen(port, () => {
const server = app.listen(port, () => {
//eslint-disable-next-line no-console
console.log(`Server listening on port ${port}`)
})
/*const server = (NODE_ENV === 'development' ? app : https.createServer(httpsOptions(), app)).listen(port, () => {
//eslint-disable-next-line no-console
console.log(`Server listening on port ${port}`)
})*/
export { app, linkRoutes, server }

View File

@ -15,6 +15,7 @@ const _placeSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, name, de
p.address,
p.latitude,
p.longitude,
p.images
p.created`}
FROM dbmaster.places AS p
WHERE p.deleted IS NULL
@ -37,10 +38,11 @@ const getPlaceListQuery = ({ limit, page, ...rest }) =>
const countPlaceListQuery = rest =>
_placeSelectQuery()({ count: 'COUNT(DISTINCT(p.uuid)) AS count' })(rest);
const insertPlaceQuery = ({ description, address, createdBy }) => {
const insertPlaceQuery = ({ description, address, createdBy, images }) => {
const descriptionCondition = description ? ':description' : null;
const addressCondition = address ? ':address' : null;
const createdByCondition = createdBy ? 'createdBy = :createdBy' : null;
const imagesCondition = images ? ':images' : null;
return `
INSERT INTO dbmaster.places (
uuid,
@ -49,6 +51,7 @@ const insertPlaceQuery = ({ description, address, createdBy }) => {
address,
longitude,
latitude,
images,
createdBy,
created
)
@ -59,6 +62,7 @@ const insertPlaceQuery = ({ description, address, createdBy }) => {
${addressCondition},
:longitude,
:latitude,
${imagesCondition},
${createdByCondition},
:now
);
@ -66,12 +70,13 @@ const insertPlaceQuery = ({ description, address, createdBy }) => {
`;
}
const updatePlaceQuery = ({ name, description, address, latitude, longitude }) => {
const updatePlaceQuery = ({ name, description, address, latitude, longitude, images }) => {
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 imagesCondition = images ? `images = :images,` : '';
return `
UPDATE dbmaster.places AS p
@ -81,6 +86,7 @@ const updatePlaceQuery = ({ name, description, address, latitude, longitude }) =
${addressCondition}
${longitudeCondition}
${latitudeCondition}
${imagesCondition}
uuid = :uuid
WHERE
p.uuid = :uuid

View File

@ -54,7 +54,7 @@ const insertUserHasPlacesQuery = ({ user_uuid, place_uuid, description, createdB
const createdByCondition = createdBy ? ':createdBy' : null;
const descriptionCondition = description ? ':description' : null;
const reportTypeCondition = report_type_uuid ? `(SELECT id FROM dbmaster.report_types WHERE uuid = :report_type_uuid)` : null;
const imagesCondition = images ? ':images' : null;
return `
INSERT INTO dbmaster.users_has_places (
@ -63,6 +63,7 @@ const insertUserHasPlacesQuery = ({ user_uuid, place_uuid, description, createdB
fk_place,
fk_report_type,
rating,
images,
description,
createdBy,
created
@ -73,6 +74,7 @@ const insertUserHasPlacesQuery = ({ user_uuid, place_uuid, description, createdB
${place_uuidCondition},
${reportTypeCondition},
:rating,
${imagesCondition},
${descriptionCondition},
${createdByCondition},
:now
@ -86,6 +88,7 @@ const modifyUserHasPlacesQuery = ({user_uuid, place_uuid, report_type_uuid, rati
const place_uuidCondition = place_uuid ? 'fk_place = (SELECT id FROM dbmaster.places WHERE uuid = :place_uuid),' : ``;
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 imagesCondition = images ? `images = :images,` : '';
return `
UPDATE dbmaster.users_has_places
SET
@ -93,6 +96,7 @@ const modifyUserHasPlacesQuery = ({user_uuid, place_uuid, report_type_uuid, rati
${place_uuidCondition}
${report_type_uuidCondition}
${ratingCondition}
${imagesCondition}
uuid = :uuid
WHERE
users_has_places.uuid = :uuid