Skip to content

Interactive Tutorial: Macro assignment incorrect success #649

@with-heart

Description

@with-heart

What is the type of issue?

Something else

What is the issue?

When working on the first assignment of the Macro page, the "Enforce Body Schema" task was marked as success even though I haven't actually done what was required:

Image

Here's the full contents of the editor in case it's useful:

import { Elysia, t } from 'elysia'

function isPerfectSquare(x: number) {
    const s = Math.floor(Math.sqrt(x))
    return s * s === x
}

function isFibonacci(n: number) {
    if (n < 0) return false

    return isPerfectSquare(5 * n * n + 4) || isPerfectSquare(5 * n * n - 4)
}

new Elysia()
	.macro('auth', {
		cookie: t.Object({
			session: t.String()
		}),
		beforeHandle({cookie: {session}, status}) {
			if (!session.value) return status(401)
		}
	})
	.macro('isBodyNumber', {
		beforeHandle({body}) {
			if (!Number.isInteger(body)) return 
		}
	})
	.post('/', ({ body }) => body, {auth: true})
	.listen(3000)

Where did you find it?

https://elysiajs.com/tutorial/patterns/macro/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions