Skip to content

Commit

Permalink
fix: null request.body
Browse files Browse the repository at this point in the history
  • Loading branch information
phamhieu committed Feb 11, 2022
1 parent f646373 commit 6a158b9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/routes/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import Stripe from 'stripe'
export default async function routes(fastify: FastifyInstance) {
fastify.post('/sync', {
handler: async (request, reply) => {
const { created, object } = request.body as {
created?: Stripe.RangeQueryParam
object?: string
}
const { created, object } =
(request.body as {
created?: Stripe.RangeQueryParam
object?: string
}) ?? {}
const params = { created, object } as SyncBackfillParams
const result = await syncBackfill(params)
return reply.send({
Expand Down
2 changes: 1 addition & 1 deletion src/routes/sync/daily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { syncBackfill, SyncBackfillParams } from '../../lib/sync'
export default async function routes(fastify: FastifyInstance) {
fastify.post('/daily', {
handler: async (request, reply) => {
const { object } = request.body as { object?: string }
const { object } = (request.body as { object?: string }) ?? {}
const currentTimeInSeconds = Math.floor(Date.now() / 1000)
const dayAgoTimeInSeconds = currentTimeInSeconds - 60 * 60 * 24
const params = {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/sync/monthly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { syncBackfill, SyncBackfillParams } from '../../lib/sync'
export default async function routes(fastify: FastifyInstance) {
fastify.post('/monthly', {
handler: async (request, reply) => {
const { object } = request.body as { object?: string }
const { object } = (request.body as { object?: string }) ?? {}
const currentTimeInSeconds = Math.floor(Date.now() / 1000)
const monthAgoTimeInSeconds = currentTimeInSeconds - 60 * 60 * 24 * 30
const params = {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/sync/weekly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { syncBackfill, SyncBackfillParams } from '../../lib/sync'
export default async function routes(fastify: FastifyInstance) {
fastify.post('/weekly', {
handler: async (request, reply) => {
const { object } = request.body as { object?: string }
const { object } = (request.body as { object?: string }) ?? {}
const currentTimeInSeconds = Math.floor(Date.now() / 1000)
const weekAgoTimeInSeconds = currentTimeInSeconds - 60 * 60 * 24 * 7
const params = {
Expand Down

0 comments on commit 6a158b9

Please sign in to comment.