repositories updated to include url of images
This commit is contained in:
parent
8297962644
commit
c5fd8c4dc5
21
src/index.js
21
src/index.js
|
|
@ -9,16 +9,22 @@ import config from './config/index.js'
|
||||||
import routes from './routes/index.js'
|
import routes from './routes/index.js'
|
||||||
import { error404, errorHandler } from './utils/errors.js'
|
import { error404, errorHandler } from './utils/errors.js'
|
||||||
import { getRoutes } from './utils/links.js'
|
import { getRoutes } from './utils/links.js'
|
||||||
/*import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
import { dirname } from 'node:path'
|
import { dirname } from 'node:path'
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url)
|
const __filename = fileURLToPath(import.meta.url)
|
||||||
const __dirname = dirname(__filename)*/
|
const __dirname = dirname(__filename)
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
const { NODE_ENV } = process.env
|
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------------------------------------------
|
* MIDDLEWARE------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
@ -36,7 +42,7 @@ app.use(express.urlencoded({extended: false}));
|
||||||
|
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
res.header('Access-Control-Allow-Origin', '*')
|
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')
|
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Client-Version')
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
@ -49,6 +55,8 @@ const linkRoutes = { ...links1 }
|
||||||
|
|
||||||
app.use('/', r1)
|
app.use('/', r1)
|
||||||
|
|
||||||
|
app.use('/public', express.static(path.join(__dirname, 'uploads')));
|
||||||
|
|
||||||
// APPLICATION LAUNCHER ------------------------------------------------------------------
|
// APPLICATION LAUNCHER ------------------------------------------------------------------
|
||||||
// 404 - Not found
|
// 404 - Not found
|
||||||
app.use((req, res) => {
|
app.use((req, res) => {
|
||||||
|
|
@ -66,9 +74,14 @@ app.use((req, res) => {
|
||||||
|
|
||||||
const port = config.port || 3000
|
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
|
//eslint-disable-next-line no-console
|
||||||
console.log(`Server listening on port ${port}`)
|
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 }
|
export { app, linkRoutes, server }
|
||||||
|
|
@ -15,6 +15,7 @@ const _placeSelectQuery = (_pagination = '') => ({ count }) => ({ uuid, name, de
|
||||||
p.address,
|
p.address,
|
||||||
p.latitude,
|
p.latitude,
|
||||||
p.longitude,
|
p.longitude,
|
||||||
|
p.images
|
||||||
p.created`}
|
p.created`}
|
||||||
FROM dbmaster.places AS p
|
FROM dbmaster.places AS p
|
||||||
WHERE p.deleted IS NULL
|
WHERE p.deleted IS NULL
|
||||||
|
|
@ -37,10 +38,11 @@ const getPlaceListQuery = ({ limit, page, ...rest }) =>
|
||||||
const countPlaceListQuery = rest =>
|
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, images }) => {
|
||||||
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;
|
||||||
|
const imagesCondition = images ? ':images' : null;
|
||||||
return `
|
return `
|
||||||
INSERT INTO dbmaster.places (
|
INSERT INTO dbmaster.places (
|
||||||
uuid,
|
uuid,
|
||||||
|
|
@ -49,6 +51,7 @@ const insertPlaceQuery = ({ description, address, createdBy }) => {
|
||||||
address,
|
address,
|
||||||
longitude,
|
longitude,
|
||||||
latitude,
|
latitude,
|
||||||
|
images,
|
||||||
createdBy,
|
createdBy,
|
||||||
created
|
created
|
||||||
)
|
)
|
||||||
|
|
@ -59,6 +62,7 @@ const insertPlaceQuery = ({ description, address, createdBy }) => {
|
||||||
${addressCondition},
|
${addressCondition},
|
||||||
:longitude,
|
:longitude,
|
||||||
:latitude,
|
:latitude,
|
||||||
|
${imagesCondition},
|
||||||
${createdByCondition},
|
${createdByCondition},
|
||||||
:now
|
: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 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,' : '';
|
||||||
|
const imagesCondition = images ? `images = :images,` : '';
|
||||||
|
|
||||||
return `
|
return `
|
||||||
UPDATE dbmaster.places AS p
|
UPDATE dbmaster.places AS p
|
||||||
|
|
@ -81,6 +86,7 @@ const updatePlaceQuery = ({ name, description, address, latitude, longitude }) =
|
||||||
${addressCondition}
|
${addressCondition}
|
||||||
${longitudeCondition}
|
${longitudeCondition}
|
||||||
${latitudeCondition}
|
${latitudeCondition}
|
||||||
|
${imagesCondition}
|
||||||
uuid = :uuid
|
uuid = :uuid
|
||||||
WHERE
|
WHERE
|
||||||
p.uuid = :uuid
|
p.uuid = :uuid
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ const insertUserHasPlacesQuery = ({ user_uuid, place_uuid, description, createdB
|
||||||
const createdByCondition = createdBy ? ':createdBy' : null;
|
const createdByCondition = createdBy ? ':createdBy' : null;
|
||||||
const descriptionCondition = description ? ':description' : null;
|
const descriptionCondition = description ? ':description' : null;
|
||||||
const reportTypeCondition = report_type_uuid ? `(SELECT id FROM dbmaster.report_types WHERE uuid = :report_type_uuid)` : null;
|
const reportTypeCondition = report_type_uuid ? `(SELECT id FROM dbmaster.report_types WHERE uuid = :report_type_uuid)` : null;
|
||||||
|
const imagesCondition = images ? ':images' : null;
|
||||||
|
|
||||||
return `
|
return `
|
||||||
INSERT INTO dbmaster.users_has_places (
|
INSERT INTO dbmaster.users_has_places (
|
||||||
|
|
@ -63,6 +63,7 @@ const insertUserHasPlacesQuery = ({ user_uuid, place_uuid, description, createdB
|
||||||
fk_place,
|
fk_place,
|
||||||
fk_report_type,
|
fk_report_type,
|
||||||
rating,
|
rating,
|
||||||
|
images,
|
||||||
description,
|
description,
|
||||||
createdBy,
|
createdBy,
|
||||||
created
|
created
|
||||||
|
|
@ -73,6 +74,7 @@ const insertUserHasPlacesQuery = ({ user_uuid, place_uuid, description, createdB
|
||||||
${place_uuidCondition},
|
${place_uuidCondition},
|
||||||
${reportTypeCondition},
|
${reportTypeCondition},
|
||||||
:rating,
|
:rating,
|
||||||
|
${imagesCondition},
|
||||||
${descriptionCondition},
|
${descriptionCondition},
|
||||||
${createdByCondition},
|
${createdByCondition},
|
||||||
:now
|
: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 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 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,' : ``;
|
||||||
|
const imagesCondition = images ? `images = :images,` : '';
|
||||||
return `
|
return `
|
||||||
UPDATE dbmaster.users_has_places
|
UPDATE dbmaster.users_has_places
|
||||||
SET
|
SET
|
||||||
|
|
@ -93,6 +96,7 @@ const modifyUserHasPlacesQuery = ({user_uuid, place_uuid, report_type_uuid, rati
|
||||||
${place_uuidCondition}
|
${place_uuidCondition}
|
||||||
${report_type_uuidCondition}
|
${report_type_uuidCondition}
|
||||||
${ratingCondition}
|
${ratingCondition}
|
||||||
|
${imagesCondition}
|
||||||
uuid = :uuid
|
uuid = :uuid
|
||||||
WHERE
|
WHERE
|
||||||
users_has_places.uuid = :uuid
|
users_has_places.uuid = :uuid
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue