feat(email): allow dismissing entity suggestions
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 45s
Build and Push Docker Images / build-frontend (push) Successful in 1m16s
Build and Push Docker Images / build-website (push) Successful in 23s
Build and Push Docker Images / build-central-services-api (push) Successful in 21s
Build and Push Docker Images / build-central-services-admin (push) Successful in 21s
Build and Push Docker Images / build-docs (push) Successful in 1m18s
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 45s
Build and Push Docker Images / build-frontend (push) Successful in 1m16s
Build and Push Docker Images / build-website (push) Successful in 23s
Build and Push Docker Images / build-central-services-api (push) Successful in 21s
Build and Push Docker Images / build-central-services-admin (push) Successful in 21s
Build and Push Docker Images / build-docs (push) Successful in 1m18s
This commit is contained in:
@@ -24,6 +24,16 @@ export const suggestionFormat = z.object({
|
||||
})
|
||||
export type EntitySuggestion = z.infer<typeof suggestionFormat>["suggestions"][number]
|
||||
|
||||
export function dismissEntitySuggestion(
|
||||
suggestions: EntitySuggestion[] | null | undefined,
|
||||
entityType: string,
|
||||
entityId: number,
|
||||
) {
|
||||
return (suggestions || []).filter(suggestion =>
|
||||
suggestion.entityType !== entityType || suggestion.entityId !== entityId,
|
||||
)
|
||||
}
|
||||
|
||||
// Only known, tenant-scoped candidates may become actionable suggestions.
|
||||
export function validateSuggestions(value: unknown, candidates: EntityCandidate[]) {
|
||||
const parsed = suggestionFormat.parse(value)
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { suggestEmailEntities, type EntityCandidate, type EntitySuggestion } from "../modules/email/email.entity-suggestions"
|
||||
import {
|
||||
dismissEntitySuggestion,
|
||||
suggestEmailEntities,
|
||||
type EntityCandidate,
|
||||
type EntitySuggestion,
|
||||
} from "../modules/email/email.entity-suggestions"
|
||||
import nodemailer from "nodemailer"
|
||||
import { FastifyInstance } from "fastify"
|
||||
import { and, desc, eq, isNotNull } from "drizzle-orm"
|
||||
@@ -617,6 +622,38 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
||||
}
|
||||
})
|
||||
|
||||
server.delete("/email/messages/:id/entity-suggestions/:entityType/:entityId", async (req, reply) => {
|
||||
if (!req.user?.tenant_id) return reply.code(400).send({ error: "No tenant selected" })
|
||||
try {
|
||||
const { id, entityType, entityId: rawEntityId } = req.params as {
|
||||
id: string
|
||||
entityType: string
|
||||
entityId: string
|
||||
}
|
||||
const entityId = Number(rawEntityId)
|
||||
if (!getEntityDefinition(entityType)) {
|
||||
return reply.code(400).send({ error: "Nicht unterstützter Entitätstyp" })
|
||||
}
|
||||
if (!Number.isSafeInteger(entityId) || entityId <= 0) {
|
||||
return reply.code(400).send({ error: "Ungültige Entitäts-ID" })
|
||||
}
|
||||
|
||||
const message = await emailSync.getMessage(req.user.tenant_id, req.user.user_id, id)
|
||||
if (!message) return reply.code(404).send({ error: "E-Mail nicht gefunden" })
|
||||
|
||||
const suggestions = dismissEntitySuggestion(message.entitySuggestions, entityType, entityId)
|
||||
await server.db.update(emailMessages).set({ entitySuggestions: suggestions }).where(and(
|
||||
eq(emailMessages.id, id),
|
||||
eq(emailMessages.tenantId, req.user.tenant_id),
|
||||
eq(emailMessages.userId, req.user.user_id),
|
||||
))
|
||||
return reply.send({ success: true, suggestions })
|
||||
} catch (err: any) {
|
||||
req.log.error(err)
|
||||
return reply.code(500).send({ error: "Vorschlag konnte nicht ausgeblendet werden." })
|
||||
}
|
||||
})
|
||||
|
||||
server.post("/email/messages/:id/entity-links", async (req, reply) => {
|
||||
try {
|
||||
if (!req.user?.tenant_id) {
|
||||
|
||||
Reference in New Issue
Block a user