touchups after refactor
This commit is contained in:
@@ -1,120 +0,0 @@
|
|||||||
package migrations
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/pocketbase/dbx"
|
|
||||||
"github.com/pocketbase/pocketbase/daos"
|
|
||||||
m "github.com/pocketbase/pocketbase/migrations"
|
|
||||||
"github.com/pocketbase/pocketbase/models"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
m.Register(func(db dbx.Builder) error {
|
|
||||||
jsonData := `{
|
|
||||||
"id": "khrcci2uqknny8h",
|
|
||||||
"created": "2024-12-20 17:33:49.887Z",
|
|
||||||
"updated": "2024-12-20 17:33:49.887Z",
|
|
||||||
"name": "notifications",
|
|
||||||
"type": "base",
|
|
||||||
"system": false,
|
|
||||||
"schema": [
|
|
||||||
{
|
|
||||||
"system": false,
|
|
||||||
"id": "b57prsbu",
|
|
||||||
"name": "type",
|
|
||||||
"type": "select",
|
|
||||||
"required": true,
|
|
||||||
"presentable": false,
|
|
||||||
"unique": false,
|
|
||||||
"options": {
|
|
||||||
"maxSelect": 1,
|
|
||||||
"values": [
|
|
||||||
"trail_create",
|
|
||||||
"list_create",
|
|
||||||
"new_follower",
|
|
||||||
"trail_comment"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"system": false,
|
|
||||||
"id": "1i2ycgle",
|
|
||||||
"name": "metadata",
|
|
||||||
"type": "json",
|
|
||||||
"required": false,
|
|
||||||
"presentable": false,
|
|
||||||
"unique": false,
|
|
||||||
"options": {
|
|
||||||
"maxSize": 2000000
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"system": false,
|
|
||||||
"id": "pyimxu85",
|
|
||||||
"name": "seen",
|
|
||||||
"type": "bool",
|
|
||||||
"required": false,
|
|
||||||
"presentable": false,
|
|
||||||
"unique": false,
|
|
||||||
"options": {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"system": false,
|
|
||||||
"id": "tmghd4vo",
|
|
||||||
"name": "recipient",
|
|
||||||
"type": "relation",
|
|
||||||
"required": true,
|
|
||||||
"presentable": false,
|
|
||||||
"unique": false,
|
|
||||||
"options": {
|
|
||||||
"collectionId": "_pb_users_auth_",
|
|
||||||
"cascadeDelete": false,
|
|
||||||
"minSelect": null,
|
|
||||||
"maxSelect": 1,
|
|
||||||
"displayFields": null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"system": false,
|
|
||||||
"id": "exqo1whj",
|
|
||||||
"name": "author",
|
|
||||||
"type": "relation",
|
|
||||||
"required": true,
|
|
||||||
"presentable": false,
|
|
||||||
"unique": false,
|
|
||||||
"options": {
|
|
||||||
"collectionId": "_pb_users_auth_",
|
|
||||||
"cascadeDelete": false,
|
|
||||||
"minSelect": null,
|
|
||||||
"maxSelect": 1,
|
|
||||||
"displayFields": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"indexes": [],
|
|
||||||
"listRule": null,
|
|
||||||
"viewRule": null,
|
|
||||||
"createRule": null,
|
|
||||||
"updateRule": null,
|
|
||||||
"deleteRule": null,
|
|
||||||
"options": {}
|
|
||||||
}`
|
|
||||||
|
|
||||||
collection := &models.Collection{}
|
|
||||||
if err := json.Unmarshal([]byte(jsonData), &collection); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return daos.New(db).SaveCollection(collection)
|
|
||||||
}, func(db dbx.Builder) error {
|
|
||||||
dao := daos.New(db);
|
|
||||||
|
|
||||||
collection, err := dao.FindCollectionByNameOrId("khrcci2uqknny8h")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return dao.DeleteCollection(collection)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
34
db/migrations/1735901837_updated_notifications.go
Normal file
34
db/migrations/1735901837_updated_notifications.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pocketbase/dbx"
|
||||||
|
"github.com/pocketbase/pocketbase/daos"
|
||||||
|
m "github.com/pocketbase/pocketbase/migrations"
|
||||||
|
"github.com/pocketbase/pocketbase/tools/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
m.Register(func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("khrcci2uqknny8h")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.UpdateRule = types.Pointer("@request.auth.id = recipient && (@request.data.type = null||@request.data.type = type) && (@request.data.metadata = null||@request.data.metadata = metadata) && (@request.data.recipient = null||@request.data.recipient = recipient) && (@request.data.author = null||@request.data.author = author) && @request.data.seen = true")
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
}, func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("khrcci2uqknny8h")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.UpdateRule = types.Pointer("@request.auth.id = recipient && @request.data.type = type && @request.data.metadata = metadata && @request.data.recipient = recipient && @request.data.author = author && @request.data.seen = true")
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -130,7 +130,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
{/if}
|
{/if}
|
||||||
{#if showAuthor && log.expand.author}
|
{#if showAuthor && log.expand?.author}
|
||||||
<td>
|
<td>
|
||||||
<p
|
<p
|
||||||
class="tooltip flex justify-center"
|
class="tooltip flex justify-center"
|
||||||
@@ -162,7 +162,7 @@
|
|||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
{/if}
|
{/if}
|
||||||
{#if showRoute && log.expand.gpx_data}
|
{#if showRoute && log.expand?.gpx_data}
|
||||||
<td>
|
<td>
|
||||||
<button on:click={openRoute} class="btn-icon">
|
<button on:click={openRoute} class="btn-icon">
|
||||||
<i class="fa fa-map-location-dot px-[3px] text-xl"></i></button
|
<i class="fa fa-map-location-dot px-[3px] text-xl"></i></button
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ const SummitLogCreateSchema = z.object({
|
|||||||
elevation_loss: z.number().nonnegative().optional(),
|
elevation_loss: z.number().nonnegative().optional(),
|
||||||
duration: z.number().nonnegative().optional(),
|
duration: z.number().nonnegative().optional(),
|
||||||
author: z.string().length(15),
|
author: z.string().length(15),
|
||||||
photos: z.array(z.string())
|
photos: z.array(z.string()).default([])
|
||||||
}) satisfies ZodType<SummitLog>
|
}) satisfies ZodType<Partial<SummitLog>>
|
||||||
|
|
||||||
const SummitLogUpdateSchema = z.object({
|
const SummitLogUpdateSchema = z.object({
|
||||||
date: z.string().date().refine((val) => !val || !isNaN(Date.parse(val)), "invalid-date").optional(),
|
date: z.string().date().refine((val) => !val || !isNaN(Date.parse(val)), "invalid-date").optional(),
|
||||||
|
|||||||
@@ -10,21 +10,21 @@ const TrailCreateSchema = z.object({
|
|||||||
date: z.string().optional().refine((val) => !val || !isNaN(Date.parse(val)), "invalid-date"),
|
date: z.string().optional().refine((val) => !val || !isNaN(Date.parse(val)), "invalid-date"),
|
||||||
public: z.boolean(),
|
public: z.boolean(),
|
||||||
difficulty: z.enum(["easy", "moderate", "difficult"]).optional(),
|
difficulty: z.enum(["easy", "moderate", "difficult"]).optional(),
|
||||||
lat: z.number().optional(),
|
lat: z.number().min(-90).max(90).optional(),
|
||||||
lon: z.number().optional(),
|
lon: z.number().min(-180).max(180).optional(),
|
||||||
distance: z.number({coerce: true}).nonnegative().optional(),
|
distance: z.number({coerce: true}).nonnegative().optional(),
|
||||||
elevation_gain: z.number({coerce: true}).nonnegative().optional(),
|
elevation_gain: z.number({coerce: true}).nonnegative().optional(),
|
||||||
elevation_loss: z.number({coerce: true}).nonnegative().optional(),
|
elevation_loss: z.number({coerce: true}).nonnegative().optional(),
|
||||||
duration: z.number({coerce: true}).nonnegative().optional(),
|
duration: z.number({coerce: true}).nonnegative().optional(),
|
||||||
photos: z.array(z.string()),
|
photos: z.array(z.string()).default([]),
|
||||||
thumbnail: z.number().int().nonnegative().optional(),
|
thumbnail: z.number().int().nonnegative().optional(),
|
||||||
waypoints: z.array(z.string()),
|
waypoints: z.array(z.string()).default([]),
|
||||||
summit_logs: z.array(z.string()),
|
summit_logs: z.array(z.string()).default([]),
|
||||||
category: z.string().optional(),
|
category: z.string().length(15).optional(),
|
||||||
gpx: z.string().optional(),
|
gpx: z.string().optional(),
|
||||||
author: z.string().length(15),
|
author: z.string().length(15),
|
||||||
|
|
||||||
}) satisfies ZodType<Trail>
|
}) satisfies ZodType<Partial<Trail>>
|
||||||
|
|
||||||
const TrailUpdateSchema = z.object({
|
const TrailUpdateSchema = z.object({
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
@@ -33,13 +33,15 @@ const TrailUpdateSchema = z.object({
|
|||||||
date: z.string().optional().refine((val) => !val || !isNaN(Date.parse(val)), "invalid-date"),
|
date: z.string().optional().refine((val) => !val || !isNaN(Date.parse(val)), "invalid-date"),
|
||||||
public: z.boolean().optional(),
|
public: z.boolean().optional(),
|
||||||
difficulty: z.enum(["easy", "moderate", "difficult"]).optional(),
|
difficulty: z.enum(["easy", "moderate", "difficult"]).optional(),
|
||||||
lat: z.number().optional(),
|
lat: z.number().min(-90).max(90).optional(),
|
||||||
lon: z.number().optional(),
|
lon: z.number().min(-180).max(180).optional(),
|
||||||
distance: z.number({coerce: true}).nonnegative().optional(),
|
distance: z.number({coerce: true}).nonnegative().optional(),
|
||||||
elevation_gain: z.number({coerce: true}).nonnegative().optional(),
|
elevation_gain: z.number({coerce: true}).nonnegative().optional(),
|
||||||
elevation_loss: z.number({coerce: true}).nonnegative().optional(),
|
elevation_loss: z.number({coerce: true}).nonnegative().optional(),
|
||||||
duration: z.number({coerce: true}).nonnegative().optional(),
|
duration: z.number({coerce: true}).nonnegative().optional(),
|
||||||
photos: z.array(z.string()).optional(),
|
photos: z.array(z.string()).optional(),
|
||||||
|
"photos-": z.string().optional(),
|
||||||
|
"photos+": z.string().optional(),
|
||||||
thumbnail: z.number().int().nonnegative().optional(),
|
thumbnail: z.number().int().nonnegative().optional(),
|
||||||
waypoints: z.array(z.string()).optional(),
|
waypoints: z.array(z.string()).optional(),
|
||||||
summit_logs: z.array(z.string()).optional(),
|
summit_logs: z.array(z.string()).optional(),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const UserCreateSchema = (z.object({
|
|||||||
password: z.string().min(8, "must-be-at-least-n-characters-long"),
|
password: z.string().min(8, "must-be-at-least-n-characters-long"),
|
||||||
passwordConfirm: z.string().optional()
|
passwordConfirm: z.string().optional()
|
||||||
|
|
||||||
}) satisfies ZodType<User>).refine((data) => data.password === data.passwordConfirm, {
|
}) satisfies ZodType<Partial<User>>).refine((data) => data.password === data.passwordConfirm, {
|
||||||
message: "passwords-must-match",
|
message: "passwords-must-match",
|
||||||
path: ["passwordConfirm"],
|
path: ["passwordConfirm"],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,22 +5,20 @@ const WaypointCreateSchema = z.object({
|
|||||||
id: z.string().length(15).optional(),
|
id: z.string().length(15).optional(),
|
||||||
name: z.string().optional(),
|
name: z.string().optional(),
|
||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
text: z.string().optional(),
|
lat: z.number({coerce: true}).min(-90).max(90),
|
||||||
lat: z.number(),
|
lon: z.number({coerce: true}).min(-180).max(180),
|
||||||
lon: z.number(),
|
|
||||||
icon: z.string().optional(),
|
icon: z.string().optional(),
|
||||||
author: z.string().length(15),
|
author: z.string().length(15),
|
||||||
photos: z.array(z.string()),
|
photos: z.array(z.string()).default([]),
|
||||||
}) satisfies ZodType<Waypoint>
|
}) satisfies ZodType<Partial<Waypoint>>
|
||||||
|
|
||||||
const WaypointUpdateSchema = z.object({
|
const WaypointUpdateSchema = z.object({
|
||||||
name: z.string().optional(),
|
name: z.string().optional(),
|
||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
text: z.string().optional(),
|
lat: z.number({coerce: true}).min(-90).max(90).optional(),
|
||||||
lat: z.number({coerce: true}).optional(),
|
lon: z.number({coerce: true}).min(-180).max(180).optional(),
|
||||||
lon: z.number({coerce: true}).optional(),
|
|
||||||
icon: z.string().optional(),
|
icon: z.string().optional(),
|
||||||
photos: z.array(z.string()),
|
photos: z.array(z.string()).optional(),
|
||||||
"photos-": z.string().optional(),
|
"photos-": z.string().optional(),
|
||||||
"photos+": z.string().optional(),
|
"photos+": z.string().optional(),
|
||||||
}) satisfies ZodType<Partial<Waypoint>>
|
}) satisfies ZodType<Partial<Waypoint>>
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { SummitLogCreateSchema } from '$lib/models/api/summit_log_schema';
|
import { SummitLogCreateSchema } from '$lib/models/api/summit_log_schema';
|
||||||
import type { SummitLog } from '$lib/models/summit_log';
|
import type { SummitLog } from '$lib/models/summit_log';
|
||||||
import { pb } from '$lib/pocketbase';
|
import { pb } from '$lib/pocketbase';
|
||||||
import { create, handleError } from '$lib/util/api_util';
|
import { Collection, create, handleError, list } from '$lib/util/api_util';
|
||||||
import { Collection, list } from '$lib/util/api_util';
|
import { json, type RequestEvent } from '@sveltejs/kit';
|
||||||
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
|
||||||
|
|
||||||
export async function GET(event: RequestEvent) {
|
export async function GET(event: RequestEvent) {
|
||||||
try {
|
try {
|
||||||
@@ -29,6 +28,6 @@ export async function PUT(event: RequestEvent) {
|
|||||||
const r = await create<SummitLog>(event, SummitLogCreateSchema, Collection.summit_logs)
|
const r = await create<SummitLog>(event, SummitLogCreateSchema, Collection.summit_logs)
|
||||||
return json(r);
|
return json(r);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
throw error(e.status, e)
|
throw handleError(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user