Partial usersetting update schema
This commit is contained in:
parent
e46ba34a66
commit
4b5db1c2f4
Binary file not shown.
Binary file not shown.
@ -19,7 +19,7 @@
|
|||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
import { User, UserSettings } from "@spacebar/util";
|
import { User, UserSettings } from "@spacebar/util";
|
||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { UserSettingsSchema } from "@spacebar/schemas"
|
import { UserSettingsUpdateSchema, UserSettingsSchema } from "@spacebar/schemas"
|
||||||
|
|
||||||
const router = Router({ mergeParams: true });
|
const router = Router({ mergeParams: true });
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ router.get(
|
|||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
requestBody: "UserSettingsSchema",
|
requestBody: "UserSettingsUpdateSchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
body: "UserSettings",
|
body: "UserSettings",
|
||||||
@ -58,7 +58,8 @@ router.patch(
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as UserSettingsSchema;
|
const body = req.body as UserSettingsUpdateSchema;
|
||||||
|
if (!body) return res.status(400).json({ code: 400, message: "Invalid request body" });
|
||||||
if (body.locale === "en") body.locale = "en-US"; // fix discord client crash on unknown locale
|
if (body.locale === "en") body.locale = "en-US"; // fix discord client crash on unknown locale
|
||||||
|
|
||||||
const user = await User.findOneOrFail({
|
const user = await User.findOneOrFail({
|
||||||
@ -67,7 +68,7 @@ router.patch(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!user.settings)
|
if (!user.settings)
|
||||||
user.settings = UserSettings.create(body as Partial<UserSettings>);
|
user.settings = UserSettings.create(body as UserSettingsUpdateSchema);
|
||||||
else
|
else
|
||||||
user.settings.assign(body);
|
user.settings.assign(body);
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,8 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
export type UserSettingsUpdateSchema = Partial<UserSettingsSchema>;
|
||||||
|
|
||||||
export interface UserSettingsSchema {
|
export interface UserSettingsSchema {
|
||||||
afk_timeout: number;
|
afk_timeout: number;
|
||||||
allow_accessibility_detection: boolean;
|
allow_accessibility_detection: boolean;
|
||||||
@ -49,7 +51,7 @@ export interface UserSettingsSchema {
|
|||||||
stream_notifications_enabled: boolean;
|
stream_notifications_enabled: boolean;
|
||||||
theme: "dark" | "light"; // dark
|
theme: "dark" | "light"; // dark
|
||||||
timezone_offset: number; // e.g -60
|
timezone_offset: number; // e.g -60
|
||||||
view_nsfw_guilds: boolean
|
view_nsfw_guilds: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CustomStatus {
|
export interface CustomStatus {
|
||||||
@ -68,4 +70,4 @@ export interface GuildFolder {
|
|||||||
|
|
||||||
export interface FriendSourceFlags {
|
export interface FriendSourceFlags {
|
||||||
all: boolean;
|
all: boolean;
|
||||||
}
|
}
|
||||||
@ -18,3 +18,4 @@
|
|||||||
export * from "./ConnectedAccount";
|
export * from "./ConnectedAccount";
|
||||||
export * from "./Member";
|
export * from "./Member";
|
||||||
export * from "./User";
|
export * from "./User";
|
||||||
|
export * from "./UserSettings";
|
||||||
@ -82,7 +82,6 @@ export * from "./UserGuildSettingsSchema";
|
|||||||
export * from "./UserModifySchema";
|
export * from "./UserModifySchema";
|
||||||
export * from "./UserNoteUpdateSchema";
|
export * from "./UserNoteUpdateSchema";
|
||||||
export * from "./UserProfileModifySchema";
|
export * from "./UserProfileModifySchema";
|
||||||
export * from "./UserSettingsSchema";
|
|
||||||
export * from "./VanityUrlSchema";
|
export * from "./VanityUrlSchema";
|
||||||
export * from "./VerifyEmailSchema";
|
export * from "./VerifyEmailSchema";
|
||||||
export * from "./VoiceStateUpdateSchema";
|
export * from "./VoiceStateUpdateSchema";
|
||||||
|
|||||||
Reference in New Issue
Block a user