its called we do a little abstraction

This commit is contained in:
2025-07-06 14:53:48 +00:00
parent e2ce397118
commit cbf6b1d3eb
4 changed files with 205 additions and 171 deletions

41
src/prisma.ts Normal file
View File

@ -0,0 +1,41 @@
import { Notification, OllamaResponse } from "../types.js";
import { trimInputData } from "./util.js";
import { prisma } from "./main.js";
const storePromptData = async (
notification: Notification,
ollamaResponseBody: OllamaResponse
) => {
try {
await prisma.response.updateMany({
where: { pleromaNotificationId: notification.id },
data: {
response: ollamaResponseBody.response,
request: trimInputData(notification.status.content),
to: notification.account.fqn,
isProcessing: false,
},
});
} catch (error: any) {
throw new Error(error.message);
}
};
const storeUserData = async (notification: Notification): Promise<void> => {
try {
await prisma.user.upsert({
where: { userFqn: notification.status.account.fqn },
update: {
lastRespondedTo: new Date(Date.now()),
},
create: {
userFqn: notification.status.account.fqn,
lastRespondedTo: new Date(Date.now()),
},
});
} catch (error: any) {
throw new Error(error.message);
}
};
export { storeUserData, storePromptData };