Delete Object.map

This commit is contained in:
MathMan05
2025-11-25 23:49:03 -06:00
parent 319b420fc0
commit 54540a8b14
5 changed files with 9 additions and 51 deletions
+5 -8
View File
@@ -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();
+3 -3
View File
@@ -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);
}
-13
View File
@@ -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" });
});
});
-25
View File
@@ -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 -2
View File
@@ -1,5 +1,4 @@
export * from "./Array";
export * from "./Math";
export * from "./Url";
export * from "./Object";
export * from "./String";
export * from "./String";