fixes notifications & trail recommendations
This commit is contained in:
@@ -80,7 +80,7 @@ func SendNotification(app core.App, notification Notification, recipient string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if permissions.Email {
|
if permissions.Email {
|
||||||
recipientUser, err := app.FindAuthRecordByEmail("users", recipient)
|
recipientUser, err := app.FindRecordById("users", recipient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@
|
|||||||
<div class="dropdown relative">
|
<div class="dropdown relative">
|
||||||
{#if unreadCount > 0}
|
{#if unreadCount > 0}
|
||||||
<div
|
<div
|
||||||
class="absolute pointer-events-none -top-1 left-4 text-sm rounded-full bg-content text-content-inverse px-1 text-center"
|
class="absolute pointer-events-none -top-[2px] left-5 text-xs rounded-full bg-content text-content-inverse px-1 text-center"
|
||||||
>
|
>
|
||||||
{unreadCount}{unreadCount >= 10 ? "+" : ""}
|
{unreadCount}{unreadCount >= 10 ? "+" : ""}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { Settings } from "./settings";
|
import type { Settings } from "./settings";
|
||||||
|
import { type AuthRecord } from "pocketbase";
|
||||||
|
|
||||||
export type User = {
|
export type User = AuthRecord & {
|
||||||
id: string,
|
id: string,
|
||||||
username?: string,
|
username?: string,
|
||||||
email?: string,
|
email?: string,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ let notifications: Notification[] = [];
|
|||||||
|
|
||||||
export async function notifications_index(data: { recipient: string, seen?: boolean }, page: number = 1, perPage: number = 10, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
export async function notifications_index(data: { recipient: string, seen?: boolean }, page: number = 1, perPage: number = 10, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||||
const r = await f('/api/v1/notification?' + new URLSearchParams({
|
const r = await f('/api/v1/notification?' + new URLSearchParams({
|
||||||
filter: `created>=@month&&recipient='${data.recipient}'` + (data.seen !== undefined ? `&&seen=${data.seen}` : ''),
|
filter: `created<=@month&&recipient='${data.recipient}'` + (data.seen !== undefined ? `&&seen=${data.seen}` : ''),
|
||||||
sort: '+seen,-created',
|
sort: '+seen,-created',
|
||||||
page: page.toString(),
|
page: page.toString(),
|
||||||
"perPage": perPage.toString()
|
"perPage": perPage.toString()
|
||||||
|
|||||||
@@ -2,25 +2,20 @@ import { TrailRecommendSchema } from '$lib/models/api/trail_schema';
|
|||||||
import type { Trail } from '$lib/models/trail';
|
import type { Trail } from '$lib/models/trail';
|
||||||
import { pb } from '$lib/pocketbase';
|
import { pb } from '$lib/pocketbase';
|
||||||
import { handleError } from '$lib/util/api_util';
|
import { handleError } from '$lib/util/api_util';
|
||||||
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
import { json, type RequestEvent } from '@sveltejs/kit';
|
||||||
import { ClientResponseError } from 'pocketbase';
|
|
||||||
|
|
||||||
export async function GET(event: RequestEvent) {
|
export async function GET(event: RequestEvent) {
|
||||||
try {
|
try {
|
||||||
const searchParams = Object.fromEntries(event.url.searchParams);
|
const searchParams = Object.fromEntries(event.url.searchParams);
|
||||||
const safeSearchParams = TrailRecommendSchema.parse(searchParams);
|
const safeSearchParams = TrailRecommendSchema.parse(searchParams);
|
||||||
|
|
||||||
const r = await event.fetch(pb.buildURL("/trail/recommend?" + new URLSearchParams({
|
const r = await pb.send("/trail/recommend?" + new URLSearchParams({
|
||||||
size: safeSearchParams.size?.toString() ?? ""
|
size: safeSearchParams.size?.toString() ?? ""
|
||||||
})));
|
}), {
|
||||||
|
method: "GET",
|
||||||
|
});
|
||||||
|
|
||||||
if (!r.ok) {
|
const result: Trail[] = r;
|
||||||
const response = await r.json()
|
|
||||||
console.error(response)
|
|
||||||
throw new ClientResponseError({ status: response.code, response })
|
|
||||||
}
|
|
||||||
|
|
||||||
const result: Trail[] = await r.json();
|
|
||||||
|
|
||||||
for (const t of result) {
|
for (const t of result) {
|
||||||
if (!t.author || !pb.authStore.record) {
|
if (!t.author || !pb.authStore.record) {
|
||||||
|
|||||||
Reference in New Issue
Block a user