Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 1x 1x 5x 2x 2x 1x 1x 2x | import { CustomScalar, Scalar } from '@nestjs/graphql';
import { ASTNode, Kind } from 'graphql';
@Scalar('Date', () => Date)
export class AppDateScalar implements CustomScalar<number, Date> {
public description = 'Date custom scalar type';
public parseValue(value: number | unknown): Date {
return typeof value === 'number' ? new Date(value) : new Date();
}
public parseLiteral(ast: ASTNode): Date {
if (ast.kind === Kind.INT) {
return new Date(ast.value);
}
return new Date();
}
public serialize(value: Date | unknown): number {
return value instanceof Date ? value.getTime() : 0;
}
}
|