set order of city locations
authorxangelo <git@xangelo.ca>
Fri, 16 Jun 2023 14:55:43 +0000 (10:55 -0400)
committerxangelo <git@xangelo.ca>
Fri, 16 Jun 2023 14:55:43 +0000 (10:55 -0400)
You can set the display order for each type of location in a city

migrations/20230616144901_location-order.ts [new file with mode: 0644]
seeds/cities.ts
src/server/map.ts
src/shared/map.ts

diff --git a/migrations/20230616144901_location-order.ts b/migrations/20230616144901_location-order.ts
new file mode 100644 (file)
index 0000000..ff3b9e7
--- /dev/null
@@ -0,0 +1,16 @@
+import { Knex } from "knex";
+
+
+export async function up(knex: Knex): Promise<void> {
+  return knex.schema.alterTable('locations', function(table) {
+    table.integer('display_order').notNullable().defaultTo(1);
+  });
+}
+
+
+export async function down(knex: Knex): Promise<void> {
+  return knex.schema.alterTable('locations', function(table) {
+    table.dropColumn('display_order');
+  })
+}
+
index dd8a5a01f27b8447a259ebaaaed7755c2f55a514..341bce1ea07cc90295b22d9f63ce5f95f497ce7d 100644 (file)
@@ -70,9 +70,10 @@ export async function createLocations(): Promise<void> {
           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(() => {
index e52fccfeaa366f4e192b219eb6b49245a7554732..51af071949a912f39313f3cdf428762ff7796239 100644 (file)
@@ -2,9 +2,11 @@ import { City, Location, Path } from "../shared/map";
 import { db } from './lib/db';
 
 export async function getAllServices(city_id: string): Promise<Location[]> {
-
-  return db.select('*').from<Location>('locations').where({city_id});
-
+  return db.select('*')
+            .from<Location>('locations')
+            .where({city_id})
+            .orderBy('type')
+            .orderBy('display_order');
 }
 
 export async function getAllPaths(city_id: string): Promise<Path[]> {
index ea2ed1fe798c5f946537810fcee379be2cd6b926..d5a95c93ff79028a771249f9238b03ff0696812d 100644 (file)
@@ -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 = {