some api routes
This commit is contained in:
parent
6591e0987f
commit
6e58f59274
39 changed files with 324 additions and 21 deletions
43
lib/borders.js
Normal file
43
lib/borders.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { getServerSession } from "next-auth";
|
||||
import { getSession } from "next-auth/react";
|
||||
import prisma from "./prisma";
|
||||
|
||||
export const getUserBorders = async (req) => {
|
||||
const session = await getSession({ req });
|
||||
if (!session) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const accountData = await prisma.account.findFirst({
|
||||
where: {
|
||||
userId: session.user.id,
|
||||
},
|
||||
});
|
||||
|
||||
const userData = await prisma.applicationUserData.findUnique({
|
||||
where: {
|
||||
userId: session.user.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!!userData) {
|
||||
return userData;
|
||||
}
|
||||
|
||||
const result = await prisma.applicationUserData.create({
|
||||
data: {
|
||||
userId: session.user.id,
|
||||
discordId: accountData.providerAccountId,
|
||||
},
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
export const getByDiscordId = async (id) => {
|
||||
const userData = await prisma.applicationUserData.findUnique({
|
||||
where: {
|
||||
discordId: id,
|
||||
},
|
||||
});
|
||||
return userData ? `${userData.borderId}` : undefined;
|
||||
};
|
14
lib/prisma.js
Normal file
14
lib/prisma.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
let prisma;
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
prisma = new PrismaClient();
|
||||
} else {
|
||||
if (!global.prisma) {
|
||||
global.prisma = new PrismaClient();
|
||||
}
|
||||
prisma = global.prisma;
|
||||
}
|
||||
|
||||
export default prisma;
|
Loading…
Add table
Add a link
Reference in a new issue