refactor messaging jobs (#19626)
Cleans up the code quality by migrating from Raw SQL to TypeORM entities. The previous implementation was necessary to do cross‑schema table joins but since we've migrated to the core schema we don't need it anymore. - Also extracted `toIsoStringOrNull` to a utility it was duplicated several times - Moved `isThrottled` logic from job handler to cron enqueuer
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { toIsoStringOrNull } from 'src/utils/date/toIsoStringOrNull';
|
||||
|
||||
describe('toIsoStringOrNull', () => {
|
||||
it('should return null for null or undefined', () => {
|
||||
expect(toIsoStringOrNull(null)).toBeNull();
|
||||
expect(toIsoStringOrNull(undefined)).toBeNull();
|
||||
});
|
||||
|
||||
it('should convert Date to ISO string', () => {
|
||||
const date = new Date('2024-01-15T10:30:00.000Z');
|
||||
|
||||
expect(toIsoStringOrNull(date)).toBe('2024-01-15T10:30:00.000Z');
|
||||
});
|
||||
|
||||
it('should pass through strings unchanged', () => {
|
||||
expect(toIsoStringOrNull('2024-01-15T10:30:00.000Z')).toBe(
|
||||
'2024-01-15T10:30:00.000Z',
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw on invalid Date', () => {
|
||||
expect(() => toIsoStringOrNull(new Date('invalid'))).toThrow(RangeError);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
export const toIsoStringOrNull = (
|
||||
value: string | Date | null | undefined,
|
||||
): string | null => {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return value instanceof Date ? value.toISOString() : value;
|
||||
};
|
||||
Reference in New Issue
Block a user