get user by either discord id or custom url

This commit is contained in:
Kalle (Sendou) 2020-10-14 00:04:40 +03:00
parent f7f56a084d
commit f794aebfa9
2 changed files with 14 additions and 4 deletions

View File

@ -1,6 +1,6 @@
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
const prisma = new PrismaClient({log: ["query"]});
export interface Context {
prisma: PrismaClient;

View File

@ -18,10 +18,20 @@ export const Query = queryType({
args: {
identifier: stringArg({required: true})
},
resolve: (_root, {identifier}, ctx) => ctx.prisma.user.findOne({
resolve: (_root, {identifier}, ctx) => ctx.prisma.user.findFirst({
where: {
discordId: identifier
}
// this is ok because the values are mutually exclusive: customUrlPath can't contain only numbers etc.
OR: [
{
discordId: identifier
},
{
profile: {
customUrlPath: identifier.toLowerCase()
}
},
]
},
})
})
}