event subscriptions
This commit is contained in:
@@ -5,10 +5,6 @@ import type { UserModel } from "../../generated/prisma/models.js";
|
||||
import { Injectable } from "../../infrastructure/di/injectable-decorator.js";
|
||||
|
||||
type ExtendedClient = ReturnType<typeof createExtendedClient>;
|
||||
// type TransactionClient = Omit<
|
||||
// ExtendedClient,
|
||||
// "$connect" | "$disconnect" | "$on" | "$transaction" | "$extends"
|
||||
// >;
|
||||
|
||||
export type SafeClient = Omit<
|
||||
ExtendedClient,
|
||||
@@ -26,28 +22,17 @@ export type SafeClient = Omit<
|
||||
function createExtendedClient(client: PrismaClient) {
|
||||
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}});
|
||||
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
|
||||
}
|
||||
}
|
||||
return user;
|
||||
},
|
||||
},
|
||||
});
|
||||
// .$extends({
|
||||
// name: "testExtension",
|
||||
// model: {
|
||||
// member: {
|
||||
// withFullName(member: Member) {
|
||||
// return {
|
||||
// ...member,
|
||||
// fullName: ` ${member.vorname} ${member.nachname}`,
|
||||
// };
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -69,9 +54,9 @@ export class DatabaseService {
|
||||
command: (prisma: SafeClient) => Promise<T>,
|
||||
request: Request | null,
|
||||
): Promise<T> {
|
||||
const transaction =
|
||||
(request as any | null)?.transaction ??
|
||||
(this.prismaClient as SafeClient);
|
||||
return await command(transaction);
|
||||
const transaction: SafeClient | null = (request as any | null)
|
||||
?.transaction;
|
||||
const effectiveClient = transaction ?? this.prismaClient;
|
||||
return await command(effectiveClient);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user