From a2c35d933c06079b8ca17c6f325bf2b7e5bcd5f4 Mon Sep 17 00:00:00 2001 From: xangelo Date: Fri, 16 Jun 2023 10:55:43 -0400 Subject: [PATCH] set order of city locations You can set the display order for each type of location in a city --- migrations/20230616144901_location-order.ts | 16 ++++++++++++++++ seeds/cities.ts | 5 +++-- src/server/map.ts | 8 +++++--- src/shared/map.ts | 3 ++- 4 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 migrations/20230616144901_location-order.ts diff --git a/migrations/20230616144901_location-order.ts b/migrations/20230616144901_location-order.ts new file mode 100644 index 0000000..ff3b9e7 --- /dev/null +++ b/migrations/20230616144901_location-order.ts @@ -0,0 +1,16 @@ +import { Knex } from "knex"; + + +export async function up(knex: Knex): Promise { + return knex.schema.alterTable('locations', function(table) { + table.integer('display_order').notNullable().defaultTo(1); + }); +} + + +export async function down(knex: Knex): Promise { + return knex.schema.alterTable('locations', function(table) { + table.dropColumn('display_order'); + }) +} + diff --git a/seeds/cities.ts b/seeds/cities.ts index dd8a5a0..341bce1 100644 --- a/seeds/cities.ts +++ b/seeds/cities.ts @@ -70,9 +70,10 @@ export async function createLocations(): Promise { id: r.fields.id, name: r.fields.name, type: r.fields.Type, - city_id: r.fields.city_id[0] + city_id: r.fields.city_id[0], + display_order: r.fields["Display Order"] } - })).onConflict('id').ignore(); + })).onConflict('id').merge(); next(); }).finally(() => { diff --git a/src/server/map.ts b/src/server/map.ts index e52fccf..51af071 100644 --- a/src/server/map.ts +++ b/src/server/map.ts @@ -2,9 +2,11 @@ import { City, Location, Path } from "../shared/map"; import { db } from './lib/db'; export async function getAllServices(city_id: string): Promise { - - return db.select('*').from('locations').where({city_id}); - + return db.select('*') + .from('locations') + .where({city_id}) + .orderBy('type') + .orderBy('display_order'); } export async function getAllPaths(city_id: string): Promise { diff --git a/src/shared/map.ts b/src/shared/map.ts index ea2ed1f..d5a95c9 100644 --- a/src/shared/map.ts +++ b/src/shared/map.ts @@ -7,7 +7,8 @@ export type Location = { id: string; name: string; city_id: string; - type: 'SERVICES' | 'STORES' | 'EXPLORE' + type: 'SERVICES' | 'STORES' | 'EXPLORE', + display_order: number; } export type Path = { -- 2.25.1