From 23e234a87b0a269f38d0d2f33bfc814bf7346310 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Sat, 12 Aug 2023 00:43:00 +1000 Subject: [PATCH] update invites endpoints to support latest api --- assets/openapi.json | Bin 571577 -> 571764 bytes assets/schemas.json | Bin 18215840 -> 18227560 bytes .../routes/channels/#channel_id/invites.ts | 18 +++++++++++++----- src/util/entities/Invite.ts | 9 ++++++--- src/util/schemas/InviteCreateSchema.ts | 1 + 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/assets/openapi.json b/assets/openapi.json index 8ec308ba09b3ea84fe151ca6a7667316aa8e3121..19686c591fa5d8c8f8ab92715324cd5a311d8f48 100644 GIT binary patch delta 101 zcmdn_QR&MkrG_nx0)mr7#HT-SWb~Y@u&Hy}eMXtd@q4)@E1UrfvQ2;Q#27N!UGy!fS47C*?^dRdsZKZzZL-RnE1R0M_&*x#}o_@HCQGB|?WM_uT#&ry^?XO1aMD401HXuR0pFUXbDc1awYLRE2^iZZ5EcGMAZh7tzvF#Ad{ z*kaWQ6R2z0NI5~F`)-%KC3JC~6!*%;OoMb4T219T& zoV$bMXnAeU4?W%NqILL-*k zwGsty3hjM5m``RnpUentD5TgTk#}cg3)T}B$+mH15p5iaGRi>fwix4LiZM$40z@!N zMCmcVVsbb*t~eGS+J+ORG0ZYwYYCT^-hjbBJbLj9xaeUK@t*K}aIl7Mq%FUKYGKAmt~gL6g}Du}GTiK@p?EqM|n#nl6_a1IvfRCLnMD1(+{Chv#An@cUh zaFnslDJnRBBmJp|Q5mfIsGp9Wm!%KhN0azXRK|R`x!zruc?i`)_Of;1lb{S+MQavS zv}RkdLFUCjaC3b%DutOh<;m$s-RnbWq;5u5eC{eV0^&Zh(AH($-<$WcfA!>#?tKl_ z;%4j)++R97A1x~mj{ghpgc%>7R$38j>ORJkYD$?TadYD0+VR(oZe#ZQk z(1tni@{LUUbPNNhO4ME42z=^3`Fu%gI#Gk>o(^4U^1)>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i7LoLOr8(r-T&FpET);K`pYF|Ekel@W975lBD}$yOO~RV$Oy5IYcPP!4GUzM3+|N zMq-lHtCw;hT}6&g#C3mwC29Opq#zZCN95Y{nQM?fQ~$9!yN=|p->?McH{9sJmg0^m zy%}@5X>)t?Zdzi6`nUF$1ICyQ{bG+X^rqi~_z}`1GRO>U?L%@ia);vD2bROdV@a{pYqEV-lo)Sz*jkz6WJa?7O4F;#~RKFpj-+7pwbFt!w=QGEA%0drKH<@D3U1lTUf(p@z5Ep%Z7>ntdXcN zp?r*1-X>_`0dlm~Bu%0Nr8+%z4?BU3>#?|bI&?XpHg%0}G!ytW!HOJlx1zx{n+Lm)+&Ok12BK_)rqW*X= diff --git a/src/api/routes/channels/#channel_id/invites.ts b/src/api/routes/channels/#channel_id/invites.ts index b02f65d3..ae32e80d 100644 --- a/src/api/routes/channels/#channel_id/invites.ts +++ b/src/api/routes/channels/#channel_id/invites.ts @@ -22,6 +22,7 @@ import { Guild, Invite, InviteCreateEvent, + InviteCreateSchema, PublicInviteRelation, User, emitEvent, @@ -50,6 +51,7 @@ router.post( }), async (req: Request, res: Response) => { const { user_id } = req; + const body = req.body as InviteCreateSchema; const { channel_id } = req.params; const channel = await Channel.findOneOrFail({ where: { id: channel_id }, @@ -62,22 +64,27 @@ router.post( } const { guild_id } = channel; - const expires_at = new Date(req.body.max_age * 1000 + Date.now()); + const expires_at = + body.max_age == 0 || body.max_age == undefined + ? undefined + : new Date(body.max_age * 1000 + Date.now()); const invite = await Invite.create({ code: random(), - temporary: req.body.temporary || true, + temporary: body.temporary || true, uses: 0, - max_uses: req.body.max_uses, - max_age: req.body.max_age, + max_uses: body.max_uses ? Math.max(0, body.max_uses) : 0, + max_age: body.max_age ? Math.max(0, body.max_age) : 0, expires_at, created_at: new Date(), guild_id, channel_id: channel_id, inviter_id: user_id, + flags: body.flags ?? 0, }).save(); + const data = invite.toJSON(); - data.inviter = await User.getPublicUser(req.user_id); + data.inviter = (await User.getPublicUser(req.user_id)).toPublicUser(); data.guild = await Guild.findOne({ where: { id: guild_id } }); data.channel = channel; @@ -86,6 +93,7 @@ router.post( data, guild_id, } as InviteCreateEvent); + res.status(201).send(data); }, ); diff --git a/src/util/entities/Invite.ts b/src/util/entities/Invite.ts index 3019709f..7970c4f0 100644 --- a/src/util/entities/Invite.ts +++ b/src/util/entities/Invite.ts @@ -17,10 +17,10 @@ */ import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm"; -import { Member } from "./Member"; import { BaseClassWithoutId, PrimaryIdColumn } from "./BaseClass"; import { Channel } from "./Channel"; import { Guild } from "./Guild"; +import { Member } from "./Member"; import { User } from "./User"; export const PublicInviteRelation = ["inviter", "guild", "channel"]; @@ -45,8 +45,8 @@ export class Invite extends BaseClassWithoutId { @Column() created_at: Date; - @Column() - expires_at: Date; + @Column({ nullable: true }) + expires_at?: Date; @Column({ nullable: true }) @RelationId((invite: Invite) => invite.guild) @@ -94,6 +94,9 @@ export class Invite extends BaseClassWithoutId { @Column({ nullable: true }) vanity_url?: boolean; + @Column() + flags: number; + static async joinGuild(user_id: string, code: string) { const invite = await Invite.findOneOrFail({ where: { code } }); if (invite.uses++ >= invite.max_uses && invite.max_uses !== 0) diff --git a/src/util/schemas/InviteCreateSchema.ts b/src/util/schemas/InviteCreateSchema.ts index 6cdc0214..92333e77 100644 --- a/src/util/schemas/InviteCreateSchema.ts +++ b/src/util/schemas/InviteCreateSchema.ts @@ -26,4 +26,5 @@ export interface InviteCreateSchema { unique?: boolean; target_user?: string; target_user_type?: number; + flags?: number; }