style: run prettier
All checks were successful
TrafficCue Server CI / check (push) Successful in 54s
TrafficCue Server CD / build (push) Successful in 1m52s

This commit is contained in:
2025-10-03 19:54:13 +02:00
parent 3de797ec1b
commit 35a1447164
3 changed files with 61 additions and 36 deletions

View File

@ -1,4 +1,10 @@
import { BaseEntity, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; import {
BaseEntity,
CreateDateColumn,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
} from "typeorm";
import type { User } from "./User"; import type { User } from "./User";
@Entity() @Entity()
@ -17,7 +23,10 @@ export class Follow extends BaseEntity {
} }
export async function isFriends(user: User, other: User) { export async function isFriends(user: User, other: User) {
return (await user.following).some((u) => u.following.id === other.id) && (await other.following).some((u) => u.following.id === user.id); return (
(await user.following).some((u) => u.following.id === other.id) &&
(await other.following).some((u) => u.following.id === user.id)
);
} }
export async function getFriends(user: User): Promise<User[]> { export async function getFriends(user: User): Promise<User[]> {

View File

@ -124,14 +124,14 @@ app.get("/api/user/me", async (c) => {
const user = await User.findOne({ const user = await User.findOne({
where: { where: {
id: uid id: uid,
}, },
relations: { relations: {
reviews: true, reviews: true,
hazards: true, hazards: true,
followers: true, followers: true,
following: true, following: true,
} },
}); });
if (!user) { if (!user) {
return c.json({ error: "Invalid user ID" }, 400); return c.json({ error: "Invalid user ID" }, 400);
@ -145,7 +145,7 @@ app.get("/api/user/me", async (c) => {
followers: (await user.followers).length, followers: (await user.followers).length,
following: (await user.following).length, following: (await user.following).length,
}); });
}) });
app.post("/api/user/follow", async (c) => { app.post("/api/user/follow", async (c) => {
const { username } = await c.req.json(); const { username } = await c.req.json();
@ -196,7 +196,7 @@ app.post("/api/user/follow", async (c) => {
await follow.save(); await follow.save();
return c.json({ success: true }); return c.json({ success: true });
}) });
app.post("/api/user/unfollow", async (c) => { app.post("/api/user/unfollow", async (c) => {
const { username } = await c.req.json(); const { username } = await c.req.json();
@ -244,8 +244,8 @@ app.post("/api/user/unfollow", async (c) => {
const follow = await Follow.findOne({ const follow = await Follow.findOne({
where: { where: {
follower: { id: user.id }, follower: { id: user.id },
following: { id: toUnfollow.id } following: { id: toUnfollow.id },
} },
}); });
if (follow) { if (follow) {
await follow.remove(); await follow.remove();
@ -266,18 +266,20 @@ app.get("/api/user", async (c) => {
hazards: true, hazards: true,
followers: true, followers: true,
following: true, following: true,
} },
}); });
const mapped = await Promise.all(users.map(async (u) => { const mapped = await Promise.all(
return { users.map(async (u) => {
username: u.username, return {
reviewsCount: u.reviews.length, username: u.username,
hazardsCount: u.hazards.length, reviewsCount: u.reviews.length,
followers: (await u.followers).length, hazardsCount: u.hazards.length,
following: (await u.following).length, followers: (await u.followers).length,
createdAt: u.created_at, following: (await u.following).length,
}; createdAt: u.created_at,
})); };
}),
);
return c.json(mapped); return c.json(mapped);
}); });
@ -422,25 +424,37 @@ if (process.env.HAZARDS_ENABLED) {
const nlat = Number(parseFloat(lat).toFixed(4)); const nlat = Number(parseFloat(lat).toFixed(4));
const nlon = Number(parseFloat(lon).toFixed(4)); const nlon = Number(parseFloat(lon).toFixed(4));
const mapMatched = await fetch((process.env.VALHALLA || "https://valhalla1.openstreetmap.de") + "/locate", { const mapMatched = await fetch(
method: "POST", (process.env.VALHALLA || "https://valhalla1.openstreetmap.de") +
headers: { "/locate",
"Content-Type": "application/json", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
locations: [
{
lat: nlat,
lon: nlon,
},
],
}),
}, },
body: JSON.stringify({ )
locations: [ .then((res) => res.json())
{ .catch(() => null);
lat: nlat,
lon: nlon,
}
]
})
}).then(res => res.json()).catch(() => null);
let mmlat = nlat; let mmlat = nlat;
let mmlon = nlon; let mmlon = nlon;
if(mapMatched && Array.isArray(mapMatched) && mapMatched[0] && mapMatched[0].edges && mapMatched[0].edges[0]) { if (
mapMatched &&
Array.isArray(mapMatched) &&
mapMatched[0] &&
mapMatched[0].edges &&
mapMatched[0].edges[0]
) {
mmlat = mapMatched[0].edges[0].correlated_lat; mmlat = mapMatched[0].edges[0].correlated_lat;
mmlon = mapMatched[0].edges[0].correlated_lon; mmlon = mapMatched[0].edges[0].correlated_lon;
} }

View File

@ -139,7 +139,10 @@ export async function sync(payload: SyncPayload, user: User) {
} }
// Find stores that are out of date on the client // Find stores that are out of date on the client
const allStores = await Store.find({ where: { user: selector }, relations: { user: true } }); // TODO: use SQL query to only get modified stores const allStores = await Store.find({
where: { user: selector },
relations: { user: true },
}); // TODO: use SQL query to only get modified stores
for (const store of allStores) { for (const store of allStores) {
if (store.user.id !== user.id && !sharedStoreTypes.includes(store.type)) { if (store.user.id !== user.id && !sharedStoreTypes.includes(store.type)) {
// Not the owner of this store and not a shared type // Not the owner of this store and not a shared type
@ -156,8 +159,7 @@ export async function sync(payload: SyncPayload, user: User) {
for (const clientStore of payload.stores) { for (const clientStore of payload.stores) {
if ( if (
!allStores.find((s) => s.id === clientStore.id) && !allStores.find((s) => s.id === clientStore.id) &&
(!user.id || (!user.id || !friends.find((f) => f.id === clientStore.id)) // Not owned by user or their friends
!friends.find((f) => f.id === clientStore.id)) // Not owned by user or their friends
) { ) {
const deletedStore = new Store(); const deletedStore = new Store();
deletedStore.id = clientStore.id; deletedStore.id = clientStore.id;