mirror of
https://github.com/spacebarchat/server.git
synced 2026-08-29 05:29:15 +00:00
HACKHACK: Migrate to typeorm v1.0.0, still work to do in actually updating all the queries properly
This commit is contained in:
@@ -151,7 +151,7 @@ router.patch(
|
||||
const { channel_id } = req.params as { [key: string]: string };
|
||||
const channel = await Channel.findOneOrFail({
|
||||
where: { id: channel_id },
|
||||
relations: ["available_tags"],
|
||||
relations: { available_tags: true },
|
||||
});
|
||||
|
||||
if (channel.isThread()) {
|
||||
@@ -182,7 +182,7 @@ router.patch(
|
||||
where: {
|
||||
id: channel.parent_id as string,
|
||||
},
|
||||
relations: ["available_tags"],
|
||||
relations: { available_tags: true },
|
||||
});
|
||||
if (!parent.available_tags) throw new Error("shoot, internetal error");
|
||||
const realTags = new Map(parent.available_tags.map((tag) => [tag.id, tag]));
|
||||
|
||||
@@ -111,7 +111,7 @@ router.get(
|
||||
|
||||
const invites = await Invite.find({
|
||||
where: { guild_id, channel_id },
|
||||
relations: PublicInviteRelation,
|
||||
relations: Object.fromEntries(PublicInviteRelation.map((i) => [i, true])), //TODO: cleanup
|
||||
});
|
||||
|
||||
res.status(200).send(invites);
|
||||
|
||||
@@ -161,7 +161,7 @@ router.get(
|
||||
where: {
|
||||
id: In(reaction.user_ids),
|
||||
},
|
||||
select: PublicUserProjection,
|
||||
select: Object.fromEntries(PublicUserProjection.map((i) => [i, true])), //TODO: cleanup
|
||||
take: limit,
|
||||
})
|
||||
).map((user) => user.toPublicUser());
|
||||
|
||||
@@ -44,7 +44,7 @@ router.post(
|
||||
const body = req.body as MessageThreadCreationSchema;
|
||||
const message = await Message.findOneOrFail({
|
||||
where: { id: message_id, channel_id },
|
||||
relations: ["guild"],
|
||||
relations: { guild: true },
|
||||
});
|
||||
const channel = await Channel.findOneOrFail({
|
||||
where: { id: channel_id },
|
||||
|
||||
@@ -65,7 +65,7 @@ router.put(
|
||||
user: (
|
||||
await User.findOneOrFail({
|
||||
where: { id: user_id },
|
||||
select: PublicUserProjection,
|
||||
select: Object.fromEntries(PublicUserProjection.map((i) => [i, true])), //TODO: cleanup
|
||||
})
|
||||
).toPublicUser(),
|
||||
},
|
||||
|
||||
@@ -43,7 +43,7 @@ router.post(
|
||||
|
||||
const channel = await Channel.findOneOrFail({
|
||||
where: { id: channel_id },
|
||||
relations: ["available_tags"],
|
||||
relations: { available_tags: true },
|
||||
});
|
||||
|
||||
if (!channel.isForum()) throw new Error("is not thread only channel");
|
||||
@@ -88,7 +88,7 @@ router.put(
|
||||
|
||||
const channel = await Channel.findOneOrFail({
|
||||
where: { id: channel_id },
|
||||
relations: ["available_tags"],
|
||||
relations: { available_tags: true },
|
||||
});
|
||||
|
||||
if (!channel.isForum()) throw new Error("is not thread only channel");
|
||||
@@ -127,7 +127,7 @@ router.delete(
|
||||
|
||||
const channel = await Channel.findOneOrFail({
|
||||
where: { id: channel_id },
|
||||
relations: ["available_tags"],
|
||||
relations: { available_tags: true },
|
||||
});
|
||||
|
||||
if (!channel.isForum()) throw new Error("is not thread only channel");
|
||||
|
||||
@@ -56,7 +56,7 @@ router.post(
|
||||
|
||||
const channel = await Channel.findOneOrFail({
|
||||
where: { id: channel_id },
|
||||
relations: ["available_tags"],
|
||||
relations: { available_tags: true },
|
||||
});
|
||||
if (!body.applied_tags?.length) {
|
||||
const required = channel.flags & Number(ChannelFlags.FLAGS.REQUIRE_TAG);
|
||||
|
||||
@@ -37,7 +37,7 @@ router.get(
|
||||
|
||||
const invites = await Invite.find({
|
||||
where: { guild_id },
|
||||
relations: PublicInviteRelation,
|
||||
relations: Object.fromEntries(PublicInviteRelation.map((i) => [i, true])), // TODO cleanup
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
|
||||
@@ -60,7 +60,7 @@ router.get(
|
||||
|
||||
const members = await Member.find({
|
||||
where: { guild_id, ...query },
|
||||
select: PublicMemberProjection,
|
||||
select: Object.fromEntries(PublicMemberProjection.map((i) => [i, true])), // TODO: cleanup
|
||||
take: limit,
|
||||
order: { id: "ASC" },
|
||||
});
|
||||
|
||||
@@ -128,7 +128,7 @@ router.get(
|
||||
mentions = mentions instanceof Array ? mentions : mentions ? [mentions] : [];
|
||||
let roleids = [] as string[];
|
||||
if (mentions) {
|
||||
const ms = await Member.find({ where: { id: In(mentions), guild_id: req.params.guild_id as string }, relations: ["roles"] });
|
||||
const ms = await Member.find({ where: { id: In(mentions), guild_id: req.params.guild_id as string }, relations: { roles: true } });
|
||||
const rSet = new Set<string>();
|
||||
ms.forEach((memb) => {
|
||||
memb.roles.forEach(({ id }) => rSet.add(id));
|
||||
|
||||
@@ -86,7 +86,7 @@ router.post(
|
||||
const { guild_id } = req.params as { [key: string]: string };
|
||||
const guild = await Guild.findOneOrFail({
|
||||
where: { id: guild_id },
|
||||
select: TemplateGuildProjection,
|
||||
select: Object.fromEntries(TemplateGuildProjection.map((i) => [i, true])), //TODO: cleanup
|
||||
relations: { roles: true, channels: true },
|
||||
});
|
||||
const exists = await Template.findOne({
|
||||
@@ -142,7 +142,7 @@ router.put(
|
||||
const { code, guild_id } = req.params as { [key: string]: string };
|
||||
const guild = await Guild.findOneOrFail({
|
||||
where: { id: guild_id },
|
||||
select: TemplateGuildProjection,
|
||||
select: Object.fromEntries(TemplateGuildProjection.map((i) => [i, true])), //TODO: cleanup
|
||||
});
|
||||
|
||||
const template = await Template.create({
|
||||
|
||||
@@ -42,7 +42,7 @@ router.get(
|
||||
|
||||
const invite = await Invite.findOneOrFail({
|
||||
where: { code: invite_code },
|
||||
relations: PublicInviteRelation,
|
||||
relations: Object.fromEntries(PublicInviteRelation.map((i) => [i, true])), //TODO: clean up
|
||||
});
|
||||
|
||||
res.status(200).send(invite.toPublicJSON());
|
||||
|
||||
@@ -46,7 +46,7 @@ router.post(
|
||||
const body = req.body as InstanceUserDeleteSchema | undefined;
|
||||
const user = await User.findOneOrFail({
|
||||
where: { id: req.params.user_id as string },
|
||||
select: [...PrivateUserProjection, "data"],
|
||||
select: Object.fromEntries([...PrivateUserProjection, "data"].map((i) => [i, true])), // TODO: clean up
|
||||
});
|
||||
|
||||
if ((body?.persistInstanceBan ?? true) && !(await InstanceBan.findOne({ where: { user_id: user.id } })))
|
||||
|
||||
@@ -120,7 +120,10 @@ router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }),
|
||||
const relationshipsIntersection = relationshipsSelf.filter((r1) => relationshipsUser.some((r2) => r2.to_id === r1.to_id));
|
||||
if (with_mutual_friends_count) mutual_friends_count = relationshipsIntersection.length;
|
||||
if (with_mutual_friends) {
|
||||
const users = await User.find({ where: { id: In(relationshipsIntersection.map((r) => r.to_id)) }, select: PublicUserProjection });
|
||||
const users = await User.find({
|
||||
where: { id: In(relationshipsIntersection.map((r) => r.to_id)) },
|
||||
select: Object.fromEntries(PublicUserProjection.map((i) => [i, true])),
|
||||
}); //TODO: clean up
|
||||
mutual_friends = users.map((u) => u.toPublicUser());
|
||||
}
|
||||
}
|
||||
@@ -169,7 +172,7 @@ router.patch("/", route({ requestBody: "UserProfileModifySchema" }), async (req:
|
||||
if (body.banner) body.banner = await handleFile(`/banners/${req.user_id}`, body.banner as string);
|
||||
const user = await User.findOneOrFail({
|
||||
where: { id: req.user_id },
|
||||
select: [...PrivateUserProjection, "data"],
|
||||
select: Object.fromEntries([...PrivateUserProjection, "data"].map((i) => [i, true])), //TODO: cleanup
|
||||
});
|
||||
|
||||
if (body.bio) {
|
||||
|
||||
@@ -37,7 +37,7 @@ router.get(
|
||||
async (req: Request, res: Response) => {
|
||||
res.json(
|
||||
await User.findOne({
|
||||
select: PrivateUserProjection,
|
||||
select: Object.fromEntries(PrivateUserProjection.map((i) => [i, true])), //TODO: cleanup
|
||||
where: { id: req.user_id },
|
||||
}),
|
||||
);
|
||||
@@ -65,7 +65,7 @@ router.patch(
|
||||
|
||||
const user = await User.findOneOrFail({
|
||||
where: { id: req.user_id },
|
||||
select: [...PrivateUserProjection, "data"],
|
||||
select: Object.fromEntries([...PrivateUserProjection, "data"].map((i) => [i, true])), //TODO: cleanup
|
||||
});
|
||||
|
||||
// Populated on password change
|
||||
|
||||
@@ -72,7 +72,7 @@ router.put(
|
||||
await User.findOneOrFail({
|
||||
where: { id: req.params.user_id as string },
|
||||
relations: { relationships: { to: true } },
|
||||
select: userProjection,
|
||||
select: Object.fromEntries(userProjection.map((i) => [i, true])), // TODO: cleanup
|
||||
}),
|
||||
req.body.type ?? RelationshipType.friends,
|
||||
),
|
||||
@@ -136,7 +136,7 @@ router.post(
|
||||
res,
|
||||
await User.findOneOrFail({
|
||||
relations: { relationships: { to: true } },
|
||||
select: userProjection,
|
||||
select: Object.fromEntries(userProjection.map((i) => [i, true])), // TODO: cleanup
|
||||
where: {
|
||||
discriminator: String(req.body.discriminator).padStart(4, "0"), //Discord send the discriminator as integer, we need to add leading zeroes
|
||||
username: req.body.username,
|
||||
@@ -165,12 +165,12 @@ router.delete(
|
||||
|
||||
const user = await User.findOneOrFail({
|
||||
where: { id: req.user_id },
|
||||
select: userProjection,
|
||||
select: Object.fromEntries(userProjection.map((i) => [i, true])), // TODO: cleanup
|
||||
relations: { relationships: true },
|
||||
});
|
||||
const friend = await User.findOneOrFail({
|
||||
where: { id: user_id },
|
||||
select: userProjection,
|
||||
select: Object.fromEntries(userProjection.map((i) => [i, true])), // TODO: cleanup
|
||||
relations: { relationships: true },
|
||||
});
|
||||
|
||||
@@ -215,8 +215,6 @@ router.delete(
|
||||
},
|
||||
);
|
||||
|
||||
export default router;
|
||||
|
||||
async function updateRelationship(req: Request, res: Response, friend: User, type: RelationshipType) {
|
||||
const id = friend.id;
|
||||
if (id === req.user_id) throw new HTTPError("You can't add yourself as a friend");
|
||||
@@ -224,7 +222,7 @@ async function updateRelationship(req: Request, res: Response, friend: User, typ
|
||||
const user = await User.findOneOrFail({
|
||||
where: { id: req.user_id },
|
||||
relations: { relationships: { to: true } },
|
||||
select: userProjection,
|
||||
select: Object.fromEntries(userProjection.map((i) => [i, true])), //TODO: cleanup
|
||||
});
|
||||
|
||||
let relationship = user.relationships.find((x) => x.to_id === id);
|
||||
@@ -316,3 +314,5 @@ async function updateRelationship(req: Request, res: Response, friend: User, typ
|
||||
|
||||
return res.sendStatus(204);
|
||||
}
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user