mirror of
https://github.com/Steffo99/festa.git
synced 2024-12-22 22:54:22 +00:00
Rename the Prisma client to database
This commit is contained in:
parent
06ef64627f
commit
6042e305a3
6 changed files with 11 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
|||
import { client } from "../../../utils/prismaClient";
|
||||
import { database } from "../../../utils/prismaClient";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { ApiResult } from "../../../types/api";
|
||||
import { Model, restInPeace } from "../../../utils/restInPeace";
|
||||
|
@ -31,7 +31,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
|||
}
|
||||
|
||||
await restInPeace(req, res, {
|
||||
model: client.event,
|
||||
model: database.event,
|
||||
retrieve: {which},
|
||||
create: {create},
|
||||
upsert: {which, create, update, before: canEdit},
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { client } from "../../../utils/prismaClient";
|
||||
import { database } from "../../../utils/prismaClient";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { ApiResult } from "../../../types/api";
|
||||
import { restInPeace } from "../../../utils/restInPeace";
|
||||
|
@ -16,7 +16,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
|||
}
|
||||
|
||||
await restInPeace(req, res, {
|
||||
model: client.event,
|
||||
model: database.event,
|
||||
list: {where}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { NextApiRequest, NextApiResponse } from "next"
|
||||
import { client } from "../../../utils/prismaClient"
|
||||
import { database } from "../../../utils/prismaClient"
|
||||
import { TelegramLoginDataClass } from "../../../utils/TelegramLoginDataClass"
|
||||
import { default as cryptoRandomString } from "crypto-random-string"
|
||||
import { ApiResult } from "../../../types/api"
|
||||
|
@ -54,7 +54,7 @@ async function loginTelegram(req: NextApiRequest, res: NextApiResponse<ApiResult
|
|||
return res.status(401).json({ error: "Telegram login data has been tampered" })
|
||||
}
|
||||
|
||||
const accountTelegram = await client.accountTelegram.upsert({
|
||||
const accountTelegram = await database.accountTelegram.upsert({
|
||||
where: {
|
||||
telegramId: userData.id
|
||||
},
|
||||
|
@ -75,7 +75,7 @@ async function loginTelegram(req: NextApiRequest, res: NextApiResponse<ApiResult
|
|||
}
|
||||
})
|
||||
|
||||
const token = await client.token.create({
|
||||
const token = await database.token.create({
|
||||
data: {
|
||||
userId: accountTelegram.userId,
|
||||
token: cryptoRandomString({ length: 16, type: "base64" }),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { client } from "./prismaClient"
|
||||
import { database } from "./prismaClient"
|
||||
import { AccountTelegram, Token, User } from "@prisma/client"
|
||||
import nodecrypto from "crypto"
|
||||
import { TelegramLoginData } from "../types/user"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { User } from "@prisma/client"
|
||||
import { NextApiRequest, NextApiResponse } from "next"
|
||||
import { client } from "./prismaClient"
|
||||
import { database } from "./prismaClient"
|
||||
import { Interrupt } from "./interrupt"
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ export async function authorizeUser(req: NextApiRequest): Promise<User> {
|
|||
throw new Interrupt(401, {error: "Invalid Authorization header" })
|
||||
}
|
||||
|
||||
const dbToken = await client.token.findUnique({where: {token}, include: {user: true}})
|
||||
const dbToken = await database.token.findUnique({where: {token}, include: {user: true}})
|
||||
|
||||
if(!(dbToken)) {
|
||||
throw new Interrupt(401, {error: "No such Authorization token" })
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
export const client = new PrismaClient()
|
||||
export const database = new PrismaClient()
|
||||
|
|
Loading…
Reference in a new issue