mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-18 11:15:20 +00:00
Delete Object.map
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
import { route } from "@spacebar/api";
|
||||
import { User, UserSettings } from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { UserSettingsUpdateSchema, UserSettingsSchema } from "@spacebar/schemas"
|
||||
import { UserSettingsUpdateSchema, UserSettingsSchema } from "@spacebar/schemas";
|
||||
|
||||
const router = Router({ mergeParams: true });
|
||||
|
||||
@@ -36,7 +36,7 @@ router.get(
|
||||
},
|
||||
}),
|
||||
async (req: Request, res: Response) => {
|
||||
const settings = await UserSettings.getOrDefault(req.user_id)
|
||||
const settings = await UserSettings.getOrDefault(req.user_id);
|
||||
return res.json(settings);
|
||||
},
|
||||
);
|
||||
@@ -67,13 +67,10 @@ router.patch(
|
||||
relations: ["settings"],
|
||||
});
|
||||
|
||||
if (!user.settings)
|
||||
user.settings = UserSettings.create(body as UserSettingsUpdateSchema);
|
||||
else
|
||||
user.settings.assign(body);
|
||||
if (!user.settings) user.settings = UserSettings.create<UserSettings>(body);
|
||||
else user.settings.assign(body);
|
||||
|
||||
if (body.guild_folders)
|
||||
user.settings.guild_folders = body.guild_folders;
|
||||
if (body.guild_folders) user.settings.guild_folders = body.guild_folders;
|
||||
|
||||
await user.settings.save();
|
||||
await user.save();
|
||||
|
||||
@@ -31,7 +31,7 @@ export function FieldErrors(fields: Record<string, { code?: string; message: str
|
||||
return new FieldError(
|
||||
50035,
|
||||
"Invalid Form Body",
|
||||
fields.map<ErrorContent, ObjectErrorContent>(({ message, code }) => ({
|
||||
Object.values(fields).map(({ message, code }) => ({
|
||||
_errors: [
|
||||
{
|
||||
message,
|
||||
@@ -39,7 +39,7 @@ export function FieldErrors(fields: Record<string, { code?: string; message: str
|
||||
},
|
||||
],
|
||||
})),
|
||||
errors
|
||||
errors,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export class FieldError extends Error {
|
||||
public code: string | number,
|
||||
public message: string,
|
||||
public errors?: object, // TODO: I don't like this typing.
|
||||
public _ajvErrors?: ErrorObject[]
|
||||
public _ajvErrors?: ErrorObject[],
|
||||
) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import moduleAlias from "module-alias";
|
||||
moduleAlias();
|
||||
import "./Object";
|
||||
import { describe, it } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
describe("Object extensions", () => {
|
||||
it("map", async () => {
|
||||
const obj = { a: 1, b: 2, c: 3 };
|
||||
const result = obj.map((value, key) => `${key}:${value}`);
|
||||
assert.deepEqual(result, { a: "a:1", b: "b:2", c: "c:3" });
|
||||
});
|
||||
});
|
||||
@@ -1,25 +0,0 @@
|
||||
declare global {
|
||||
interface Object {
|
||||
map<SV, TV>(callback: (value: SV, key: string, object: { [index: string]: SV }) => TV): { [index: string]: TV };
|
||||
}
|
||||
}
|
||||
|
||||
export function objectMap<SV, TV>(srcObj: { [index: string]: SV }, callback: (value: SV, key: string, object: { [index: string]: SV }) => TV): { [index: string]: TV } {
|
||||
if (typeof callback !== "function") throw new TypeError(`${callback} is not a function`);
|
||||
const obj: { [index: string]: TV } = {};
|
||||
Object.keys(srcObj).forEach((key) => {
|
||||
obj[key] = callback(srcObj[key], key, srcObj);
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (!Object.prototype.map)
|
||||
Object.defineProperty(Object.prototype, "map", {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-expect-error
|
||||
value: function (cb) {
|
||||
return objectMap(this, cb);
|
||||
},
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
});
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from "./Array";
|
||||
export * from "./Math";
|
||||
export * from "./Url";
|
||||
export * from "./Object";
|
||||
export * from "./String";
|
||||
export * from "./String";
|
||||
|
||||
Reference in New Issue
Block a user