Skip to content

Commit

Permalink
fix(subscriptions): added parser to Redis to handle Dates
Browse files Browse the repository at this point in the history
  • Loading branch information
David Wennemaring committed Dec 4, 2020
1 parent c634ce4 commit f95bf85
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/pubSub/pubSub.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ import Redis from 'ioredis';
import { ConfigModule } from '../config/config.module';
import { ConfigService } from '../config/config.service';

const dateReviver = (key, value) => {
const isISO8601Z = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/;
if (typeof value === 'string' && isISO8601Z.test(value)) {
const tempDateNumber = Date.parse(value);
if (!Number.isNaN(tempDateNumber)) {
return new Date(tempDateNumber);
}
}
return value;
};

@Module({
imports: [ConfigModule],
providers: [
Expand All @@ -19,6 +30,7 @@ import { ConfigService } from '../config/config.service';
host: configService.get('REDIS_HOST_READ'),
port: configService.get('REDIS_PORT_READ'),
}),
reviver: dateReviver,
}),
},
],
Expand Down

0 comments on commit f95bf85

Please sign in to comment.