Skip to content

Commit 87d4a56

Browse files
authored
Merge pull request #1 from QAura-NV/database-seeding
Database seeding & My orders page
2 parents c55e37b + 9cdd52c commit 87d4a56

File tree

3 files changed

+253
-0
lines changed

3 files changed

+253
-0
lines changed
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/// <reference path="../pb_data/types.d.ts" />
2+
migrate(
3+
(app) => {
4+
// Add superuser
5+
let superusers = app.findCollectionByNameOrId("_superusers");
6+
let record = new Record(superusers, {
7+
email: $os.getenv("POCKETBASE_ADMIN_EMAIL") || "test@example.com",
8+
password: $os.getenv("POCKETBASE_ADMIN_PASSWORD") || "test",
9+
});
10+
app.save(record);
11+
12+
// Add categories
13+
let categoryIds = {};
14+
let categories = app.findCollectionByNameOrId("categories");
15+
for (let name of CATEGORIES) {
16+
let record = new Record(categories, {
17+
name: name,
18+
});
19+
app.save(record);
20+
categoryIds[name] = record.id;
21+
}
22+
23+
// Add Dogs
24+
let pets = app.findCollectionByNameOrId("pets");
25+
for (let dogName of DOG_NAMES) {
26+
let record = new Record(pets, {
27+
name: dogName,
28+
category: categoryIds["Dog"],
29+
status: "available",
30+
});
31+
app.save(record);
32+
}
33+
34+
// Add Cats
35+
for (let catName of CAT_NAMES) {
36+
let record = new Record(pets, {
37+
name: catName,
38+
category: categoryIds["Cat"],
39+
status: "available",
40+
});
41+
app.save(record);
42+
}
43+
},
44+
(app) => {
45+
function constructFilterString(names) {
46+
return names.map((name) => `name = "${name}"`).join(" || ");
47+
}
48+
// Remove cats
49+
let pets = app.findCollectionByNameOrId("pets");
50+
let catRecords = app.findRecordsByFilter(
51+
pets,
52+
constructFilterString(CAT_NAMES)
53+
);
54+
for (let record of catRecords) {
55+
app.delete(record);
56+
}
57+
58+
// Remove dogs
59+
let dogRecords = app.findRecordsByFilter(
60+
pets,
61+
DOG_NAMES.map((name) => `name = "${name}"`).join("||")
62+
);
63+
for (let record of dogRecords) {
64+
app.delete(record);
65+
}
66+
67+
// Remove categories
68+
let categories = app.findCollectionByNameOrId("categories");
69+
let categoryRecords = app.findRecordsByFilter(
70+
categories,
71+
CATEGORIES.map((name) => `name = "${name}"`).join("||")
72+
);
73+
for (let record of categoryRecords) {
74+
app.delete(record);
75+
}
76+
77+
// Remove superuser
78+
let record = app.findAuthRecordByEmail(
79+
"_superusers",
80+
$os.getenv("POCKETBASE_ADMIN_EMAIL") || "test@example.com"
81+
);
82+
app.delete(record);
83+
}
84+
);
85+
86+
const CATEGORIES = [
87+
"Cat",
88+
"Dog",
89+
"Bird",
90+
"Fish",
91+
"Reptile",
92+
"Small Mammal",
93+
"Farm Animal",
94+
];
95+
96+
const DOG_NAMES = [
97+
"Apollo",
98+
"Bandit",
99+
"Bear",
100+
"Bentley",
101+
"Buster",
102+
"Buddy",
103+
"Charlie",
104+
"Cody",
105+
"Cooper",
106+
"Diesel",
107+
"Duke",
108+
"Finn",
109+
"Gunner",
110+
"Gus",
111+
"Hunter",
112+
"Jake",
113+
"Leo",
114+
"Max",
115+
"Milo",
116+
"Murphy",
117+
"Oliver",
118+
"Oscar",
119+
"Rex",
120+
"Riley",
121+
"Rocky",
122+
"Samson",
123+
"Thor",
124+
"Tucker",
125+
"Winston",
126+
"Zeus",
127+
"Ziggy",
128+
"Ace",
129+
"Archie",
130+
"Bailey",
131+
"Beau",
132+
"Blue",
133+
"Bruno",
134+
"Cash",
135+
"Chase",
136+
"Dexter",
137+
"Frankie",
138+
"George",
139+
"Hank",
140+
"Jackson",
141+
"Jasper",
142+
"Joey",
143+
"Louie",
144+
"Lucky",
145+
"Moose",
146+
"Ollie",
147+
];
148+
149+
const CAT_NAMES = [
150+
"Angel",
151+
"Bella",
152+
"Boots",
153+
"Callie",
154+
"Chloe",
155+
"Cleo",
156+
"Coco",
157+
"Daisy",
158+
"Felix",
159+
"Finn",
160+
"Ginger",
161+
"Gracie",
162+
"Jack",
163+
"Jasper",
164+
"Kitty",
165+
"Leo",
166+
"Lily",
167+
"Loki",
168+
"Luna",
169+
"Maggie",
170+
"Max",
171+
"Mia",
172+
"Milo",
173+
"Mimi",
174+
"Missy",
175+
"Misty",
176+
"Mittens",
177+
"Mochi",
178+
"Nala",
179+
"Oliver",
180+
"Oreo",
181+
"Oscar",
182+
"Peanut",
183+
"Pumpkin",
184+
"Rosie",
185+
"Ruby",
186+
"Sadie",
187+
"Salem",
188+
"Sammy",
189+
"Shadow",
190+
"Simba",
191+
"Smokey",
192+
"Socks",
193+
"Sophie",
194+
"Stella",
195+
"Tiger",
196+
"Toby",
197+
"Willow",
198+
"Ziggy",
199+
"Zoe",
200+
];

frontend/src/lib/components/navigation.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
<div class="bg-green-400 px-4 py-2">{name}</div>
2121
<div class="bg-blue-400 px-4 py-2"><a href="/auth/logout">Logout</a></div>
2222
{/if}
23+
{#if authStore.isValid}
24+
<div class="bg-blue-300 px-4 py-2"><a href="/orders">My Orders</a></div>
25+
{/if}
2326
<div class="bg-blue-400 px-4 py-2">
2427
<a href="/order/cart">Cart ({cartStore.cart.length})</a>
2528
</div>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<script lang="ts">
2+
import { getPocketBase } from '$lib/services/pocketbase';
3+
import { getAuthStore } from '$lib/stores/auth.store.svelte';
4+
import { getCartStore } from '$lib/stores/cart.store.svelte';
5+
6+
const authStore = getAuthStore();
7+
const cartStore = getCartStore();
8+
9+
const orders = getPocketBase()
10+
.collection('orders')
11+
.getFullList({
12+
sort: '-created',
13+
filter: `user.id = '${authStore.id}'`
14+
});
15+
</script>
16+
17+
<div class="mb-4 flex items-center justify-between gap-4 bg-gray-100">
18+
<h1 class="px-4 py-2 text-xl">My Orders</h1>
19+
</div>
20+
{#await orders}
21+
<p>Loading orders...</p>
22+
{:then orders}
23+
<div class="grid grid-cols-1 gap-4">
24+
{#each orders as order}
25+
<div class="pb-4">
26+
<div class="items-between flex border-b border-b-gray-200 pb-4">
27+
<div class="flex-grow">
28+
<h2 class="text-lg font-bold">Order ID: {order.id}</h2>
29+
30+
<p>Last updated at {new Date(order.updated).toLocaleString('nl-BE')}</p>
31+
<p>
32+
Order status: {order.status[0].toUpperCase() + order.status.slice(1)}
33+
</p>
34+
<p>
35+
Order complete? {order.complete ? 'Yes' : 'No'}
36+
</p>
37+
{#if order.status === 'delivered' && order.delivered}
38+
<p>Order delivered at: {new Date(order.delivered).toLocaleString('nl-BE')}</p>
39+
{/if}
40+
</div>
41+
<div>
42+
<a href={`/order/${order.id}`} class="ml-auto bg-blue-400 px-4 py-2"> View Order </a>
43+
</div>
44+
</div>
45+
</div>
46+
{/each}
47+
</div>
48+
{:catch error}
49+
<p class="bg-red-400">Error loading orders: {error}</p>
50+
{/await}

0 commit comments

Comments
 (0)