Update path variables

This commit is contained in:
Rory& 2025-10-11 03:58:37 +02:00
parent 2e955f6b63
commit e8c5c988bb
14 changed files with 39 additions and 39 deletions

Binary file not shown.

View File

@ -46,7 +46,7 @@ router.post(
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const app = await Application.findOneOrFail({ const app = await Application.findOneOrFail({
where: { id: req.params.id }, where: { id: req.params.application_id },
relations: ["owner"], relations: ["owner"],
}); });
@ -74,7 +74,7 @@ router.post(
}, },
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const bot = await User.findOneOrFail({ where: { id: req.params.id } }); const bot = await User.findOneOrFail({ where: { id: req.params.application_id } });
const owner = await User.findOneOrFail({ where: { id: req.user_id } }); const owner = await User.findOneOrFail({ where: { id: req.user_id } });
if (owner.id != req.user_id) if (owner.id != req.user_id)
@ -114,7 +114,7 @@ router.patch(
if (!body.avatar?.trim()) delete body.avatar; if (!body.avatar?.trim()) delete body.avatar;
const app = await Application.findOneOrFail({ const app = await Application.findOneOrFail({
where: { id: req.params.id }, where: { id: req.params.application_id },
relations: ["bot", "owner"], relations: ["bot", "owner"],
}); });

View File

@ -44,7 +44,7 @@ router.get(
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const app = await Application.findOneOrFail({ const app = await Application.findOneOrFail({
where: { id: req.params.id }, where: { id: req.params.application_id },
relations: ["owner", "bot"], relations: ["owner", "bot"],
}); });
if (app.owner.id != req.user_id) if (app.owner.id != req.user_id)
@ -71,7 +71,7 @@ router.patch(
const body = req.body as ApplicationModifySchema; const body = req.body as ApplicationModifySchema;
const app = await Application.findOneOrFail({ const app = await Application.findOneOrFail({
where: { id: req.params.id }, where: { id: req.params.application_id },
relations: ["owner", "bot"], relations: ["owner", "bot"],
}); });
@ -135,7 +135,7 @@ router.post(
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const app = await Application.findOneOrFail({ const app = await Application.findOneOrFail({
where: { id: req.params.id }, where: { id: req.params.application_id },
relations: ["bot", "owner"], relations: ["bot", "owner"],
}); });
if (app.owner.id != req.user_id) if (app.owner.id != req.user_id)

View File

@ -25,7 +25,7 @@ import { HTTPError } from "lambert-server";
const router: Router = Router({ mergeParams: true }); const router: Router = Router({ mergeParams: true });
router.get( router.get(
"/:code", "/:template_code",
route({ route({
responses: { responses: {
200: { 200: {
@ -40,16 +40,16 @@ router.get(
}, },
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const { code } = req.params; const { template_code } = req.params;
const template = await getTemplate(code); const template = await getTemplate(template_code);
res.json(template); res.json(template);
}, },
); );
router.post("/:code", route({ requestBody: "GuildTemplateCreateSchema" }), async (req: Request, res: Response) => { router.post("/:template_code", route({ requestBody: "GuildTemplateCreateSchema" }), async (req: Request, res: Response) => {
const { code } = req.params; const { template_code } = req.params;
const body = req.body as GuildTemplateCreateSchema; const body = req.body as GuildTemplateCreateSchema;
const { maxGuilds } = Config.get().limits.user; const { maxGuilds } = Config.get().limits.user;
@ -57,7 +57,7 @@ router.post("/:code", route({ requestBody: "GuildTemplateCreateSchema" }), async
const guild_count = await Member.count({ where: { id: req.user_id } }); const guild_count = await Member.count({ where: { id: req.user_id } });
if (guild_count >= maxGuilds) throw DiscordApiErrors.MAXIMUM_GUILDS.withParams(maxGuilds); if (guild_count >= maxGuilds) throw DiscordApiErrors.MAXIMUM_GUILDS.withParams(maxGuilds);
const template = await getTemplate(code) as Template; const template = await getTemplate(template_code) as Template;
const guild = await Guild.createGuild({ const guild = await Guild.createGuild({
...template.serialized_source_guild, ...template.serialized_source_guild,

View File

@ -33,7 +33,7 @@ import { HTTPError } from "lambert-server";
const router: Router = Router({ mergeParams: true }); const router: Router = Router({ mergeParams: true });
router.get( router.get(
"/:code", "/:invite_code",
route({ route({
responses: { responses: {
"200": { "200": {
@ -45,10 +45,10 @@ router.get(
}, },
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const { code } = req.params; const { invite_code } = req.params;
const invite = await Invite.findOneOrFail({ const invite = await Invite.findOneOrFail({
where: { code }, where: { code: invite_code },
relations: PublicInviteRelation, relations: PublicInviteRelation,
}); });
@ -57,7 +57,7 @@ router.get(
); );
router.post( router.post(
"/:code", "/:invite_code",
route({ route({
right: "USE_MASS_INVITES", right: "USE_MASS_INVITES",
responses: { responses: {
@ -78,9 +78,9 @@ router.post(
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
if (req.user_bot) throw DiscordApiErrors.BOT_PROHIBITED_ENDPOINT; if (req.user_bot) throw DiscordApiErrors.BOT_PROHIBITED_ENDPOINT;
const { code } = req.params; const { invite_code } = req.params;
const { guild_id } = await Invite.findOneOrFail({ const { guild_id } = await Invite.findOneOrFail({
where: { code: code }, where: { code: invite_code },
}); });
const { features } = await Guild.findOneOrFail({ const { features } = await Guild.findOneOrFail({
where: { id: guild_id }, where: { id: guild_id },
@ -100,7 +100,7 @@ router.post(
if (features.includes("INVITES_DISABLED")) if (features.includes("INVITES_DISABLED"))
throw new HTTPError("Sorry, this guild has joins closed.", 403); throw new HTTPError("Sorry, this guild has joins closed.", 403);
const invite = await Invite.joinGuild(req.user_id, code); const invite = await Invite.joinGuild(req.user_id, invite_code);
res.json(invite); res.json(invite);
}, },
@ -108,7 +108,7 @@ router.post(
// * cant use permission of route() function because path doesn't have guild_id/channel_id // * cant use permission of route() function because path doesn't have guild_id/channel_id
router.delete( router.delete(
"/:code", "/:invite_code",
route({ route({
responses: { responses: {
"200": { "200": {
@ -123,8 +123,8 @@ router.delete(
}, },
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const { code } = req.params; const { invite_code } = req.params;
const invite = await Invite.findOneOrFail({ where: { code } }); const invite = await Invite.findOneOrFail({ where: { code: invite_code } });
const { guild_id, channel_id } = invite; const { guild_id, channel_id } = invite;
const permission = await getPermission( const permission = await getPermission(
@ -143,14 +143,14 @@ router.delete(
); );
await Promise.all([ await Promise.all([
Invite.delete({ code }), Invite.delete({ code: invite_code }),
emitEvent({ emitEvent({
event: "INVITE_DELETE", event: "INVITE_DELETE",
guild_id: guild_id, guild_id: guild_id,
data: { data: {
channel_id: channel_id, channel_id: channel_id,
guild_id: guild_id, guild_id: guild_id,
code: code, code: invite_code,
}, },
} as InviteDeleteEvent), } as InviteDeleteEvent),
]); ]);

View File

@ -21,7 +21,7 @@ import { route } from "@spacebar/api";
const router: Router = Router({ mergeParams: true }); const router: Router = Router({ mergeParams: true });
router.get("/:id", route({}), async (req: Request, res: Response) => { router.get("/:application_id", route({}), async (req: Request, res: Response) => {
//TODO //TODO
// const id = req.params.id; // const id = req.params.id;
res.json({ res.json({

View File

@ -21,7 +21,7 @@ import { route } from "@spacebar/api";
const router: Router = Router({ mergeParams: true }); const router: Router = Router({ mergeParams: true });
router.get("/:id", route({}), async (req: Request, res: Response) => { router.get("/:sku_id", route({}), async (req: Request, res: Response) => {
//TODO //TODO
// const id = req.params.id; // const id = req.params.id;
res.json({ res.json({

View File

@ -44,19 +44,19 @@ router.post(
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
await User.findOneOrFail({ await User.findOneOrFail({
where: { id: req.params.id }, where: { id: req.params.user_id },
select: [...PrivateUserProjection, "data"], select: [...PrivateUserProjection, "data"],
}); });
await Promise.all([ await Promise.all([
Member.delete({ id: req.params.id }), Member.delete({ id: req.params.user_id }),
User.delete({ id: req.params.id }), User.delete({ id: req.params.user_id }),
]); ]);
// TODO: respect intents as USER_DELETE has potential to cause privacy issues // TODO: respect intents as USER_DELETE has potential to cause privacy issues
await emitEvent({ await emitEvent({
event: "USER_DELETE", event: "USER_DELETE",
user_id: req.user_id, user_id: req.user_id,
data: { user_id: req.params.id }, data: { user_id: req.params.user_id },
} as UserDeleteEvent); } as UserDeleteEvent);
res.sendStatus(204); res.sendStatus(204);

View File

@ -32,9 +32,9 @@ router.get(
}, },
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const { id } = req.params; const { user_id } = req.params;
res.json(await User.getPublicUser(id)); res.json(await User.getPublicUser(user_id));
}, },
); );

View File

@ -34,7 +34,7 @@ router.get(
}, },
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const user = await User.findOneOrFail({ where: { id: req.params.id } }); const user = await User.findOneOrFail({ where: { id: req.params.user_id } });
const channel = await user.getDmChannelWith(req.user_id); const channel = await user.getDmChannelWith(req.user_id);
const messages = ( const messages = (

View File

@ -39,11 +39,11 @@ import { In } from "typeorm";
const router: Router = Router({ mergeParams: true }); const router: Router = Router({ mergeParams: true });
router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }), async (req: Request, res: Response) => { router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }), async (req: Request, res: Response) => {
if (req.params.id === "@me") req.params.id = req.user_id; if (req.params.user_id === "@me") req.params.user_id = req.user_id;
const { guild_id, with_mutual_guilds, with_mutual_friends, with_mutual_friends_count } = req.query; const { guild_id, with_mutual_guilds, with_mutual_friends, with_mutual_friends_count } = req.query;
const user = await User.getPublicUser(req.params.id, { const user = await User.getPublicUser(req.params.user_id, {
relations: ["connected_accounts"], relations: ["connected_accounts"],
}); });
@ -52,7 +52,7 @@ router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }),
if (with_mutual_guilds == "true") { if (with_mutual_guilds == "true") {
const requested_member = await Member.find({ const requested_member = await Member.find({
where: { id: req.params.id }, where: { id: req.params.user_id },
}); });
const self_member = await Member.find({ const self_member = await Member.find({
where: { id: req.user_id }, where: { id: req.user_id },
@ -82,7 +82,7 @@ router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }),
const guild_member = const guild_member =
guild_id && typeof guild_id == "string" guild_id && typeof guild_id == "string"
? await Member.findOneOrFail({ ? await Member.findOneOrFail({
where: { id: req.params.id, guild_id: guild_id }, where: { id: req.params.user_id, guild_id: guild_id },
relations: ["roles"], relations: ["roles"],
}) })
: undefined; : undefined;
@ -111,7 +111,7 @@ router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }),
if (with_mutual_friends == "true" || with_mutual_friends_count == "true") { if (with_mutual_friends == "true" || with_mutual_friends_count == "true") {
const relationshipsSelf = await Relationship.find({ where: { from_id: req.user_id, type: RelationshipType.friends } }); const relationshipsSelf = await Relationship.find({ where: { from_id: req.user_id, type: RelationshipType.friends } });
const relationshipsUser = await Relationship.find({ where: { from_id: req.params.id, type: RelationshipType.friends } }); const relationshipsUser = await Relationship.find({ where: { from_id: req.params.user_id, type: RelationshipType.friends } });
const relationshipsIntersection = relationshipsSelf.filter((r1) => relationshipsUser.some((r2) => r2.to_id === r1.to_id)); 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_count) mutual_friends_count = relationshipsIntersection.length;
if (with_mutual_friends) { if (with_mutual_friends) {

View File

@ -36,7 +36,7 @@ router.get(
const mutual_relations: UserRelationsResponse = []; const mutual_relations: UserRelationsResponse = [];
const requested_relations = await User.findOneOrFail({ const requested_relations = await User.findOneOrFail({
where: { id: req.params.id }, where: { id: req.params.user_id },
relations: ["relationships"], relations: ["relationships"],
}); });
const self_relations = await User.findOneOrFail({ const self_relations = await User.findOneOrFail({