push service
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { PrismaPg } from "@prisma/adapter-pg";
|
||||
import { type Request } from "express";
|
||||
import { PrismaClient } from "../../generated/prisma/client.js";
|
||||
import type { UserModel } from "../../generated/prisma/models.js";
|
||||
import { Injectable } from "../../infrastructure/di/injectable-decorator.js";
|
||||
|
||||
type ExtendedClient = ReturnType<typeof createExtendedClient>;
|
||||
@@ -23,7 +24,17 @@ export type SafeClient = Omit<
|
||||
>;
|
||||
|
||||
function createExtendedClient(client: PrismaClient) {
|
||||
return client;
|
||||
return client.$extends({
|
||||
client: {
|
||||
async ensureUserKnown(userId: string): Promise<UserModel>{
|
||||
let user = await client.user.findUnique({where: {id: userId}});
|
||||
if(user==null){
|
||||
user = await client.user.create({data:{id: userId}});
|
||||
}
|
||||
return user
|
||||
}
|
||||
}
|
||||
});
|
||||
// .$extends({
|
||||
// name: "testExtension",
|
||||
// model: {
|
||||
|
||||
Reference in New Issue
Block a user