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";
|
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[]> {
|
||||||
|
|||||||
44
src/main.ts
44
src/main.ts
@ -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,9 +266,10 @@ 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(
|
||||||
|
users.map(async (u) => {
|
||||||
return {
|
return {
|
||||||
username: u.username,
|
username: u.username,
|
||||||
reviewsCount: u.reviews.length,
|
reviewsCount: u.reviews.length,
|
||||||
@ -277,7 +278,8 @@ app.get("/api/user", async (c) => {
|
|||||||
following: (await u.following).length,
|
following: (await u.following).length,
|
||||||
createdAt: u.created_at,
|
createdAt: u.created_at,
|
||||||
};
|
};
|
||||||
}));
|
}),
|
||||||
|
);
|
||||||
return c.json(mapped);
|
return c.json(mapped);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -422,7 +424,10 @@ 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(
|
||||||
|
(process.env.VALHALLA || "https://valhalla1.openstreetmap.de") +
|
||||||
|
"/locate",
|
||||||
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@ -432,15 +437,24 @@ if (process.env.HAZARDS_ENABLED) {
|
|||||||
{
|
{
|
||||||
lat: nlat,
|
lat: nlat,
|
||||||
lon: nlon,
|
lon: nlon,
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
})
|
}),
|
||||||
}).then(res => res.json()).catch(() => null);
|
},
|
||||||
|
)
|
||||||
|
.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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user