apps/api/src/lib/schemas.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
import type { APIEmbed, APIMessageTopLevelComponent } from "@stealth-developers/db";
import { type Static, type TSchema, t } from "elysia";
export const GuildSchema = t.Object({
id: t.Number(),
discordId: t.String(),
name: t.String(),
icon: t.Nullable(t.String()),
createdAt: t.Date(),
updatedAt: t.Date(),
});
export type SanitisedGuild = Static<typeof GuildSchema>;
export const UserSchema = t.Object({
id: t.Number(),
discordId: t.Nullable(t.String()),
username: t.Nullable(t.String()),
displayName: t.Nullable(t.String()),
createdAt: t.Date(),
updatedAt: t.Date(),
});
export type SanitisedUser = Static<typeof UserSchema>;
export const ActorSchema = t.Object({
actorId: t.Number(),
guildId: t.Nullable(t.Number()),
userId: t.Nullable(t.Number()),
discordId: t.Nullable(t.String()),
username: t.Nullable(t.String()),
displayName: t.Nullable(t.String()),
avatar: t.Nullable(t.String()),
createdAt: t.Date(),
updatedAt: t.Date(),
});
export type SanitisedActor = Static<typeof ActorSchema>;
export const ActorWithGuildSchema = t.Object({
...ActorSchema.properties,
guild: t.Nullable(GuildSchema),
});
export type SanitisedActorWithGuild = Static<typeof ActorWithGuildSchema>;
export const TicketSchema = t.Object({
id: t.String(),
guildId: t.Number(),
localId: t.Number(),
status: t.String(),
channelId: t.Nullable(t.String()),
threadId: t.Nullable(t.String()),
closeReason: t.Nullable(t.String()),
privateReason: t.Nullable(t.String()),
openedAt: t.Date(),
closedAt: t.Nullable(t.Date()),
closedBy: t.Nullable(t.Number()),
lastSubjectActivityAt: t.Nullable(t.Date()),
lastClaimantActivityAt: t.Nullable(t.Date()),
openedBy: t.Number(),
openReason: t.Nullable(t.String()),
subject: t.Nullable(t.Number()),
claimedBy: t.Nullable(t.Number()),
claimedAt: t.Nullable(t.Date()),
thankedAt: t.Nullable(t.Date()),
warnedAt: t.Nullable(t.Date()),
lastMessageAt: t.Nullable(t.Date()),
hasModeratorMessage: t.Nullable(t.Boolean()),
hasAuthorMessage: t.Nullable(t.Boolean()),
subjects: t.Object({
participants: t.Array(ActorSchema),
subject: ActorSchema,
opener: ActorSchema,
closedBy: t.Nullable(ActorSchema),
claimedBy: t.Nullable(ActorSchema),
}),
});
export type SanitisedTicket = Static<typeof TicketSchema>;
const APIEmbedSchema = t.Any() as unknown as TSchema & { static: APIEmbed };
const APIMessageComponentSchema = t.Any() as unknown as TSchema & {
static: APIMessageTopLevelComponent;
};
export const TicketMessageSchema = t.Object({
id: t.String(),
messageId: t.Nullable(t.String()),
ticketId: t.String(),
actorId: t.Nullable(t.Number()),
actorRole: t.String(),
isPrivate: t.Boolean(),
content: t.String(),
embeds: t.Array(APIEmbedSchema),
components: t.Array(APIMessageComponentSchema),
createdAt: t.Date(),
editedAt: t.Nullable(t.Date()),
deletedAt: t.Nullable(t.Date()),
actors: t.Object({
author: t.Nullable(ActorSchema),
}),
});
export type SanitisedTicketMessage = Static<typeof TicketMessageSchema>;
export const TicketParticipantSchema = t.Object({
id: t.Number(),
ticketId: t.String(),
actorId: t.Number(),
role: t.String(),
reason: t.Nullable(t.String()),
createdAt: t.Date(),
actors: t.Object({
participant: ActorSchema,
}),
});
export type SanitisedTicketParticipant = Static<typeof TicketParticipantSchema>;
export const TicketCommentSchema = t.Object({
id: t.String(),
ticketId: t.String(),
actorId: t.Number(),
content: t.String(),
createdAt: t.Date(),
updatedAt: t.Date(),
actors: t.Object({
author: ActorSchema,
}),
});
export type SanitisedTicketComment = Static<typeof TicketCommentSchema>;
export const TicketAttachmentSchema = t.Object({
id: t.String(),
messageId: t.Nullable(t.String()),
ticketId: t.String(),
actorId: t.Nullable(t.Number()),
fileName: t.String(),
fileType: t.String(),
fileSize: t.Number(),
key: t.String(),
actors: t.Object({
author: t.Nullable(ActorSchema),
}),
});
export type SanitisedTicketAttachment = Static<typeof TicketAttachmentSchema>;
export const ErrorSchema = t.Object({
message: t.String(),
});
export type ErrorResponse = Static<typeof ErrorSchema>;
export const GuildAccessSchema = t.Object({
id: t.Number(),
discordId: t.String(),
name: t.String(),
icon: t.Nullable(t.String()),
actor: t.Object({
username: t.Nullable(t.String()),
displayName: t.Nullable(t.String()),
avatar: t.Nullable(t.String()),
actorId: t.Number(),
userId: t.Nullable(t.Number()),
discordId: t.Nullable(t.String()),
}),
});
export type GuildAccess = Static<typeof GuildAccessSchema>;
export const TicketsResponseSchema = t.Object({
tickets: t.Array(TicketSchema),
count: t.Number(),
});
export type TicketsResponse = Static<typeof TicketsResponseSchema>;
export const OverallStatsSchema = t.Object({
mean: t.Number(),
median: t.Number(),
totalClosed: t.Number(),
});
export type OverallStats = Static<typeof OverallStatsSchema>;
export const LeaderboardEntrySchema = t.Object({
actor: t.Nullable(ActorSchema),
closedCount: t.Number(),
mean: t.Number(),
median: t.Number(),
});
export type LeaderboardEntry = Static<typeof LeaderboardEntrySchema>;
export const LeaderboardResponseSchema = t.Array(LeaderboardEntrySchema);
export type LeaderboardResponse = Static<typeof LeaderboardResponseSchema>;
|