style: run prettier
This commit is contained in:
@ -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";
|
||||
|
||||
@Entity()
|
||||
@ -17,7 +23,10 @@ export class Follow extends BaseEntity {
|
||||
}
|
||||
|
||||
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[]> {
|
||||
|
||||
76
src/main.ts
76
src/main.ts
@ -124,14 +124,14 @@ app.get("/api/user/me", async (c) => {
|
||||
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
id: uid
|
||||
id: uid,
|
||||
},
|
||||
relations: {
|
||||
reviews: true,
|
||||
hazards: true,
|
||||
followers: true,
|
||||
following: true,
|
||||
}
|
||||
},
|
||||
});
|
||||
if (!user) {
|
||||
return c.json({ error: "Invalid user ID" }, 400);
|
||||
@ -145,7 +145,7 @@ app.get("/api/user/me", async (c) => {
|
||||
followers: (await user.followers).length,
|
||||
following: (await user.following).length,
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
app.post("/api/user/follow", async (c) => {
|
||||
const { username } = await c.req.json();
|
||||
@ -196,7 +196,7 @@ app.post("/api/user/follow", async (c) => {
|
||||
await follow.save();
|
||||
|
||||
return c.json({ success: true });
|
||||
})
|
||||
});
|
||||
|
||||
app.post("/api/user/unfollow", async (c) => {
|
||||
const { username } = await c.req.json();
|
||||
@ -244,8 +244,8 @@ app.post("/api/user/unfollow", async (c) => {
|
||||
const follow = await Follow.findOne({
|
||||
where: {
|
||||
follower: { id: user.id },
|
||||
following: { id: toUnfollow.id }
|
||||
}
|
||||
following: { id: toUnfollow.id },
|
||||
},
|
||||
});
|
||||
if (follow) {
|
||||
await follow.remove();
|
||||
@ -266,18 +266,20 @@ app.get("/api/user", async (c) => {
|
||||
hazards: true,
|
||||
followers: true,
|
||||
following: true,
|
||||
}
|
||||
},
|
||||
});
|
||||
const mapped = await Promise.all(users.map(async (u) => {
|
||||
return {
|
||||
username: u.username,
|
||||
reviewsCount: u.reviews.length,
|
||||
hazardsCount: u.hazards.length,
|
||||
followers: (await u.followers).length,
|
||||
following: (await u.following).length,
|
||||
createdAt: u.created_at,
|
||||
};
|
||||
}));
|
||||
const mapped = await Promise.all(
|
||||
users.map(async (u) => {
|
||||
return {
|
||||
username: u.username,
|
||||
reviewsCount: u.reviews.length,
|
||||
hazardsCount: u.hazards.length,
|
||||
followers: (await u.followers).length,
|
||||
following: (await u.following).length,
|
||||
createdAt: u.created_at,
|
||||
};
|
||||
}),
|
||||
);
|
||||
return c.json(mapped);
|
||||
});
|
||||
|
||||
@ -422,25 +424,37 @@ if (process.env.HAZARDS_ENABLED) {
|
||||
const nlat = Number(parseFloat(lat).toFixed(4));
|
||||
const nlon = Number(parseFloat(lon).toFixed(4));
|
||||
|
||||
const mapMatched = await fetch((process.env.VALHALLA || "https://valhalla1.openstreetmap.de") + "/locate", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
const mapMatched = await fetch(
|
||||
(process.env.VALHALLA || "https://valhalla1.openstreetmap.de") +
|
||||
"/locate",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
locations: [
|
||||
{
|
||||
lat: nlat,
|
||||
lon: nlon,
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
locations: [
|
||||
{
|
||||
lat: nlat,
|
||||
lon: nlon,
|
||||
}
|
||||
]
|
||||
})
|
||||
}).then(res => res.json()).catch(() => null);
|
||||
)
|
||||
.then((res) => res.json())
|
||||
.catch(() => null);
|
||||
|
||||
let mmlat = nlat;
|
||||
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;
|
||||
mmlon = mapMatched[0].edges[0].correlated_lon;
|
||||
}
|
||||
|
||||
@ -139,7 +139,10 @@ export async function sync(payload: SyncPayload, user: User) {
|
||||
}
|
||||
|
||||
// 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) {
|
||||
if (store.user.id !== user.id && !sharedStoreTypes.includes(store.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) {
|
||||
if (
|
||||
!allStores.find((s) => s.id === clientStore.id) &&
|
||||
(!user.id ||
|
||||
!friends.find((f) => f.id === clientStore.id)) // Not owned by user or their friends
|
||||
(!user.id || !friends.find((f) => f.id === clientStore.id)) // Not owned by user or their friends
|
||||
) {
|
||||
const deletedStore = new Store();
|
||||
deletedStore.id = clientStore.id;
|
||||
|
||||
Reference in New Issue
Block a user