Last active
June 9, 2022 21:55
-
-
Save dsvgit/ae29a0a5b1ab77c2f8e719fdcb586b78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios, { AxiosResponse } from "axios"; | |
import { Prisma } from "generated/client"; | |
const endpoint = "http://localhost:3001/db"; | |
class PrismaRequester { | |
async card<T extends keyof Prisma.CardDelegate<any>>( | |
action: T, | |
args?: Parameters<Prisma.CardDelegate<any>[T]>[0] | |
): Promise<AxiosResponse<Awaited<ReturnType<Prisma.CardDelegate<any>[T]>>>> { | |
return await this.request<Awaited<ReturnType<Prisma.CardDelegate<any>[T]>>>( | |
"card", | |
action, | |
args | |
); | |
} | |
async task<T extends keyof Prisma.TaskDelegate<any>>( | |
action: T, | |
args?: Parameters<Prisma.TaskDelegate<any>[T]>[0] | |
): Promise<AxiosResponse<Awaited<ReturnType<Prisma.TaskDelegate<any>[T]>>>> { | |
return await this.request<Awaited<ReturnType<Prisma.TaskDelegate<any>[T]>>>( | |
"task", | |
action, | |
args | |
); | |
} | |
async tag<T extends keyof Prisma.TagDelegate<any>>( | |
action: T, | |
args?: Parameters<Prisma.TagDelegate<any>[T]>[0] | |
): Promise<AxiosResponse<Awaited<ReturnType<Prisma.TagDelegate<any>[T]>>>> { | |
return await this.request<Awaited<ReturnType<Prisma.TagDelegate<any>[T]>>>( | |
"tag", | |
action, | |
args | |
); | |
} | |
private async request<T>(collectionId: string, action: string, args?: any) { | |
return await axios.post<T>(endpoint, { collectionId, action, args }); | |
} | |
} | |
const prisma = new PrismaRequester(); | |
export default prisma; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment