feat: add payload for feed event integration and send function
for easy to fetch origin data and debug later
This commit is contained in:
parent
88fa90c2ca
commit
572d96babb
@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "FeedEvent" ADD COLUMN "payload" JSON;
|
@ -567,6 +567,9 @@ model FeedEvent {
|
||||
url String? // url link
|
||||
important Boolean
|
||||
archived Boolean @default(false) @db.Boolean
|
||||
/// [Nullable<PrismaJson.CommonPayload>]
|
||||
/// @zod.custom(imports.CommonPayloadSchema.nullish())
|
||||
payload Json? @db.Json
|
||||
|
||||
channel FeedChannel @relation(fields: [channelId], references: [id], onUpdate: Cascade, onDelete: Cascade)
|
||||
|
||||
|
@ -2,6 +2,12 @@ import * as z from "zod"
|
||||
import * as imports from "./schemas/index.js"
|
||||
import { CompleteFeedChannel, RelatedFeedChannelModelSchema } from "./index.js"
|
||||
|
||||
// Helper schema for JSON fields
|
||||
type Literal = boolean | number | string
|
||||
type Json = Literal | { [key: string]: Json } | Json[]
|
||||
const literalSchema = z.union([z.string(), z.number(), z.boolean()])
|
||||
const jsonSchema: z.ZodSchema<Json> = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]))
|
||||
|
||||
export const FeedEventModelSchema = z.object({
|
||||
id: z.string(),
|
||||
channelId: z.string(),
|
||||
@ -16,6 +22,10 @@ export const FeedEventModelSchema = z.object({
|
||||
url: z.string().nullish(),
|
||||
important: z.boolean(),
|
||||
archived: z.boolean(),
|
||||
/**
|
||||
* [Nullable<PrismaJson.CommonPayload>]
|
||||
*/
|
||||
payload: imports.CommonPayloadSchema.nullish(),
|
||||
})
|
||||
|
||||
export interface CompleteFeedEvent extends z.infer<typeof FeedEventModelSchema> {
|
||||
|
@ -194,6 +194,21 @@ export const feedRouter = router({
|
||||
channelId,
|
||||
archived,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
channelId: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
eventName: true,
|
||||
eventContent: true,
|
||||
tags: true,
|
||||
source: true,
|
||||
senderId: true,
|
||||
senderName: true,
|
||||
url: true,
|
||||
important: true,
|
||||
archived: true,
|
||||
},
|
||||
limit,
|
||||
cursor,
|
||||
});
|
||||
@ -294,6 +309,7 @@ export const feedRouter = router({
|
||||
senderId: true,
|
||||
senderName: true,
|
||||
important: true,
|
||||
payload: true,
|
||||
}).merge(
|
||||
z.object({
|
||||
channelId: z.string(),
|
||||
@ -311,7 +327,7 @@ export const feedRouter = router({
|
||||
},
|
||||
});
|
||||
|
||||
return event;
|
||||
return event as z.infer<typeof FeedEventModelSchema>;
|
||||
}),
|
||||
archiveEvent: workspaceAdminProcedure
|
||||
.meta(
|
||||
|
@ -95,13 +95,14 @@ export const feedIntegrationRouter = router({
|
||||
await createFeedEvent(workspaceId, {
|
||||
channelId: channelId,
|
||||
eventName: eventType,
|
||||
eventContent: `[${pusherName}](mailto:${pusherEmail}) push commit **${commits}** to **${ref}** in [${fullName}](${repoUrl})`,
|
||||
eventContent: `[${pusherName}](mailto:${pusherEmail}) push commit ${commits ? `**${commits}**` : ''} to **${ref}** in [${fullName}](${repoUrl})`,
|
||||
tags: [],
|
||||
source: 'github',
|
||||
senderId,
|
||||
senderName,
|
||||
important: false,
|
||||
url,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
return 'ok';
|
||||
@ -126,6 +127,7 @@ export const feedIntegrationRouter = router({
|
||||
senderName,
|
||||
important: false,
|
||||
url,
|
||||
payload: data,
|
||||
});
|
||||
} else if (action === 'deleted') {
|
||||
await createFeedEvent(workspaceId, {
|
||||
@ -138,6 +140,7 @@ export const feedIntegrationRouter = router({
|
||||
senderName,
|
||||
important: false,
|
||||
url,
|
||||
payload: data,
|
||||
});
|
||||
}
|
||||
|
||||
@ -172,6 +175,7 @@ export const feedIntegrationRouter = router({
|
||||
senderName,
|
||||
important: false,
|
||||
url,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
return 'ok';
|
||||
@ -244,6 +248,7 @@ export const feedIntegrationRouter = router({
|
||||
senderId: alarm.alarmObjInfo.appId,
|
||||
senderName: alarm.alarmPolicyInfo.policyName,
|
||||
important: alarm.alarmStatus === '1',
|
||||
payload: data,
|
||||
});
|
||||
|
||||
return 'ok';
|
||||
@ -265,6 +270,7 @@ export const feedIntegrationRouter = router({
|
||||
senderId: alarm.alarmObjInfo.appId,
|
||||
senderName: alarm.alarmPolicyInfo.policyName,
|
||||
important: alarm.alarmStatus === '1',
|
||||
payload: data,
|
||||
});
|
||||
|
||||
return 'ok';
|
||||
|
1
src/server/types/global.d.ts
vendored
1
src/server/types/global.d.ts
vendored
@ -12,6 +12,7 @@ declare global {
|
||||
|
||||
namespace PrismaJson {
|
||||
type CommonPayload = Record<string, any>;
|
||||
type Nullable<T> = Record<string, any> | null | undefined;
|
||||
type DashboardLayout = {
|
||||
layouts: Record<string, any[]>;
|
||||
items: any[];
|
||||
|
Loading…
Reference in New Issue
Block a user