mirror of
https://github.com/originalmk/skrytka-app.git
synced 2024-11-20 10:28:50 +00:00
Changed the way osp units can be searched
Now parameter name is not locality-prefix, but locality. Provided string is searched at any place of OSP name or locality, not only at the beginning.
This commit is contained in:
parent
00ae400e0d
commit
847513ebdd
8
app.js
8
app.js
@ -84,13 +84,13 @@ app.get('/ping', (req, res) => {
|
|||||||
* e.g. https://skrytka.app/osp-units?prefix=Gda
|
* e.g. https://skrytka.app/osp-units?prefix=Gda
|
||||||
* Returns 3 matching results sorted by locality, name.*/
|
* Returns 3 matching results sorted by locality, name.*/
|
||||||
app.get('/osp-units', async (req, res) => {
|
app.get('/osp-units', async (req, res) => {
|
||||||
const localityPrefix = req.query['locality-prefix'];
|
const locality = req.query['locality'];
|
||||||
|
|
||||||
if(!localityPrefix) {
|
if(!locality) {
|
||||||
res.status(400);
|
res.status(400);
|
||||||
res.json({
|
res.json({
|
||||||
queryErrors: {
|
queryErrors: {
|
||||||
'locality-prefix': ['Nie podano parametru!']
|
'locality': ['Nie podano parametru!']
|
||||||
},
|
},
|
||||||
otherErrors: []
|
otherErrors: []
|
||||||
});
|
});
|
||||||
@ -101,7 +101,7 @@ app.get('/osp-units', async (req, res) => {
|
|||||||
// Also are these database constraints reasonable?
|
// Also are these database constraints reasonable?
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const unitsList = await db.any('SELECT id AS "ID", name, locality FROM get_units_list($1)', [localityPrefix]);
|
const unitsList = await db.any('SELECT id AS "ID", name, locality FROM get_units_list($1)', [locality]);
|
||||||
res.status(200);
|
res.status(200);
|
||||||
res.json(unitsList);
|
res.json(unitsList);
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
@ -6,7 +6,10 @@ DROP FUNCTION IF EXISTS get_units_list;
|
|||||||
CREATE FUNCTION get_units_list(prefix VARCHAR) RETURNS TABLE (id INTEGER, name VARCHAR, locality VARCHAR)
|
CREATE FUNCTION get_units_list(prefix VARCHAR) RETURNS TABLE (id INTEGER, name VARCHAR, locality VARCHAR)
|
||||||
AS
|
AS
|
||||||
$func$
|
$func$
|
||||||
SELECT * FROM units_list WHERE locality LIKE prefix || '%' OR name LIKE prefix || '%' ORDER BY locality, name LIMIT 3;
|
SELECT * FROM units_list
|
||||||
|
WHERE LOWER(locality) LIKE LOWER('%' || prefix || '%')
|
||||||
|
OR LOWER(name) LIKE LOWER('%' || prefix || '%')
|
||||||
|
ORDER BY locality, name LIMIT 3;
|
||||||
$func$
|
$func$
|
||||||
LANGUAGE SQL;
|
LANGUAGE SQL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user