feat: add notification microservices and transactional outbox
هذا الالتزام موجود في:
34
libs/events/src/follow-request-approved.event.ts
Normal file
34
libs/events/src/follow-request-approved.event.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
export const FOLLOW_REQUEST_APPROVED_EVENT = 'follow.request.approved' as const;
|
||||
|
||||
export interface FollowRequestApprovedEvent {
|
||||
eventId: string;
|
||||
eventType: typeof FOLLOW_REQUEST_APPROVED_EVENT;
|
||||
occurredAt: string;
|
||||
payload: {
|
||||
requestId: string;
|
||||
actorId: string;
|
||||
recipientId: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isFollowRequestApprovedEvent(value: unknown): value is FollowRequestApprovedEvent {
|
||||
if (!value || typeof value !== 'object') return false;
|
||||
const event = value as Partial<FollowRequestApprovedEvent>;
|
||||
const payload = event.payload as Partial<FollowRequestApprovedEvent['payload']> | undefined;
|
||||
return event.eventType === FOLLOW_REQUEST_APPROVED_EVENT
|
||||
&& isNonEmptyString(event.eventId)
|
||||
&& isIsoDateString(event.occurredAt)
|
||||
&& isNonEmptyString(payload?.requestId)
|
||||
&& isNonEmptyString(payload.actorId)
|
||||
&& isNonEmptyString(payload.recipientId);
|
||||
}
|
||||
|
||||
const isNonEmptyString = (value: unknown): value is string =>
|
||||
typeof value === 'string' && value.trim().length > 0;
|
||||
|
||||
const isIsoDateString = (value: unknown): value is string => {
|
||||
if (typeof value !== 'string') return false;
|
||||
const timestamp = Date.parse(value);
|
||||
if (Number.isNaN(timestamp)) return false;
|
||||
return new Date(timestamp).toISOString() === value;
|
||||
};
|
||||
1
libs/events/src/index.ts
Normal file
1
libs/events/src/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './follow-request-approved.event';
|
||||
5
libs/events/tsconfig.lib.json
Normal file
5
libs/events/tsconfig.lib.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": { "declaration": true, "outDir": "../../dist/libs/events" },
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
المرجع في مشكلة جديدة
حظر مستخدم