From: xangelo Date: Fri, 16 Jun 2023 14:55:43 +0000 (-0400) Subject: set order of city locations X-Git-Tag: v0.0.1~35 X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=a2c35d933c06079b8ca17c6f325bf2b7e5bcd5f4;p=risinglegends.git set order of city locations You can set the display order for each type of location in a city --- 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 = {