chore: fix ci problem
This commit is contained in:
parent
85a2a598d7
commit
4d15cccd1b
@ -5,6 +5,7 @@ import _ from 'lodash';
|
||||
import { subscribeEventBus } from '../../../ws/shared';
|
||||
import { OpenApiMeta } from 'trpc-openapi';
|
||||
import { OPENAPI_TAG } from '../../../utils/const';
|
||||
import { serializeJSON } from '../../../utils/json';
|
||||
|
||||
export const feedIntegrationRouter = router({
|
||||
github: publicProcedure
|
||||
@ -62,7 +63,11 @@ export const feedIntegrationRouter = router({
|
||||
url,
|
||||
},
|
||||
});
|
||||
subscribeEventBus.emit('onReceiveFeedEvent', workspaceId, event);
|
||||
subscribeEventBus.emit(
|
||||
'onReceiveFeedEvent',
|
||||
workspaceId,
|
||||
serializeJSON(event)
|
||||
);
|
||||
|
||||
return 'ok';
|
||||
} else if (eventType === 'star') {
|
||||
@ -84,7 +89,11 @@ export const feedIntegrationRouter = router({
|
||||
url,
|
||||
},
|
||||
});
|
||||
subscribeEventBus.emit('onReceiveFeedEvent', workspaceId, event);
|
||||
subscribeEventBus.emit(
|
||||
'onReceiveFeedEvent',
|
||||
workspaceId,
|
||||
serializeJSON(event)
|
||||
);
|
||||
|
||||
return 'ok';
|
||||
} else if (eventType === 'issues') {
|
||||
@ -120,7 +129,11 @@ export const feedIntegrationRouter = router({
|
||||
url,
|
||||
},
|
||||
});
|
||||
subscribeEventBus.emit('onReceiveFeedEvent', workspaceId, event);
|
||||
subscribeEventBus.emit(
|
||||
'onReceiveFeedEvent',
|
||||
workspaceId,
|
||||
serializeJSON(event)
|
||||
);
|
||||
|
||||
return 'ok';
|
||||
}
|
||||
|
50
src/server/utils/json.ts
Normal file
50
src/server/utils/json.ts
Normal file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* serialize object
|
||||
* make data easy to transfer
|
||||
*/
|
||||
export function serializeJSON<T extends {}>(input: T) {
|
||||
return serializeDate(input);
|
||||
}
|
||||
|
||||
type ConvertDateToString<T> = T extends Date
|
||||
? string
|
||||
: T extends Date | null
|
||||
? string | null
|
||||
: T extends Date | undefined
|
||||
? string | undefined
|
||||
: T extends Date | null | undefined
|
||||
? string | null | undefined
|
||||
: T;
|
||||
|
||||
export type DateToString<T> = {
|
||||
[P in keyof T]: T[P] extends Date | null | undefined
|
||||
? ConvertDateToString<T[P]>
|
||||
: DateToString<T[P]>;
|
||||
};
|
||||
|
||||
function serializeDate<T extends {}>(obj: T): DateToString<T> {
|
||||
function stripDates(_obj: unknown): any {
|
||||
if (!_obj || typeof _obj !== 'object') {
|
||||
return _obj;
|
||||
}
|
||||
|
||||
if (_obj instanceof Date) {
|
||||
return _obj.toISOString();
|
||||
}
|
||||
|
||||
if (Array.isArray(_obj)) {
|
||||
return _obj.map(stripDates);
|
||||
}
|
||||
|
||||
return Object.keys(_obj).reduce(
|
||||
(acc, key) => {
|
||||
const value = (_obj as any)[key];
|
||||
acc[key] = stripDates(value); // Recursive to handle nested objects
|
||||
return acc;
|
||||
},
|
||||
{} as { [key: string]: any }
|
||||
);
|
||||
}
|
||||
|
||||
return stripDates(obj);
|
||||
}
|
Loading…
Reference in New Issue
Block a user