WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Variable BooleanStringSchemaConst

    BooleanStringSchema: ZodEffects<
        ZodOptional<ZodString>,
        undefined | boolean,
        undefined | string,
    > = ...

    Boolean string transformation schema for query parameters

    Specialized validation schema that transforms string-based query parameters into boolean values, handling the common web pattern where boolean flags are passed as string values in URLs. This schema provides flexible boolean interpretation while maintaining type safety and consistent behavior.

    The transformation accepts 'true' and '1' as truthy values, following common web conventions for boolean query parameters. All other values are treated as falsy, providing predictable behavior for client applications and API consumers. The optional nature allows for parameters that may not be present.

    // Query parameter boolean conversion
    const FilterSchema = z.object({
    includeArchived: BooleanStringSchema,
    showPublicOnly: BooleanStringSchema,
    enableNotifications: BooleanStringSchema
    });

    // URL: /api/courses?includeArchived=true&showPublicOnly=1&enableNotifications=false
    // Result: { includeArchived: true, showPublicOnly: true, enableNotifications: false }
    // API endpoint with boolean flags
    router.get('/content', validate({
    query: z.object({
    published: BooleanStringSchema,
    featured: BooleanStringSchema
    })
    }), (req, res) => {
    const { published, featured } = req.query; // Properly typed booleans
    const content = await contentService.find({ published, featured });
    res.json({ content });
    });