Skip to content

Commit

Permalink
API fix for link command
Browse files Browse the repository at this point in the history
  • Loading branch information
Moonded committed Aug 27, 2024
1 parent b849b0e commit ec024db
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 81 deletions.
85 changes: 42 additions & 43 deletions src/api/bot/commands/user.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
import express from "express";
import { prisma } from "utils";
import { prisma, log } from "utils";

const router = express.Router();

router.put("/", async (req, res) => {
router.post("/", async (req, res) => {
try {
const data = req.body as {
user: string;
id: string;
nexusmods: string;
github: string;
theme: string;
description: string;
style: string;
timezone: string;
country: string;
User: string;
Id: string;
NexusMods: string;
Github: string;
Theme: string;
Description: string;
Style: string;
Timezone: string;
Country: string;
};

try {
const user = await prisma.user.upsert({
where: {
userid: data.id,
},
update: {
userid: data.id,
user: data.user,
nexusmods: data.nexusmods,
github: data.github,
theme: data.theme,
description: data.description,
style: data.style,
timezone: data.timezone,
country: data.country,
},
create: {
userid: data.id,
user: data.user,
nexusmods: data.nexusmods,
github: data.github,
theme: data.theme,
description: data.description,
style: data.style,
timezone: data.timezone,
country: data.country,
},
});
return res.send(user);
} catch (e) {
return res.sendStatus(500);
}
console.log(data);

const user = await prisma.user.upsert({
where: {
userid: data.Id,
},
update: {
userid: data.Id,
user: data.User,
nexusmods: data.NexusMods,
github: data.Github,
theme: data.Theme,
description: data.Description,
style: data.Style,
timezone: data.Timezone,
country: data.Country,
},
create: {
userid: data.Id,
user: data.User,
nexusmods: data.NexusMods,
github: data.Github,
theme: data.Theme,
description: data.Description,
style: data.Style,
timezone: data.Timezone,
country: data.Country,
},
});
return res.send(user);
} catch (e) {
log(e)
return res.sendStatus(500);
}
});
Expand Down
72 changes: 34 additions & 38 deletions src/api/discord/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ import express from "express";
import { prisma, log, client } from "utils";
const router = express.Router();

type acc = {
Username: string;
Nickname: string | null;
Image: string;
ID: string;
Bot: boolean;
Roles: {
Role: string;
ID: string;
Icon: string | null;
Position: number;
}[];
CustomData: {} | null;
}[];

router.get("/", async (req, res) => {
try {
if (!req.query.q || typeof req.query.q !== "string") {
Expand All @@ -14,44 +29,25 @@ router.get("/", async (req, res) => {

const Users = await prisma.user.findMany();

const data = Members?.reduce(
(
acc: {
Username: string;
Nickname: string | null;
Image: string;
ID: string;
Bot: boolean;
Roles: {
Role: string;
ID: string;
Icon: string | null;
Position: number;
}[];
CustomData: {} | null;
}[],
member
) => {
acc.push({
Username: member.user.username,
Nickname: member.nickname,
Image: member.user.displayAvatarURL(),
ID: member.user.id,
Bot: member.user.bot,
Roles: member.roles.cache.map((role) => {
return {
Role: role.name,
ID: role.id,
Icon: role.iconURL(),
Position: role.position,
};
}),
CustomData: Users.find((a) => a.userid === member.user.id) || null,
});
return acc;
},
[]
);
const data = Members?.reduce((acc: acc, member) => {
acc.push({
Username: member.user.username,
Nickname: member.nickname,
Image: member.user.displayAvatarURL(),
ID: member.user.id,
Bot: member.user.bot,
Roles: member.roles.cache.map((role) => {
return {
Role: role.name,
ID: role.id,
Icon: role.iconURL(),
Position: role.position,
};
}),
CustomData: Users.find((a) => a.userid === member.user.id) || null,
});
return acc;
}, []);

log("Experimental Roles sent");
return res.send(data);
Expand Down

0 comments on commit ec024db

Please sign in to comment.