小编use*_*180的帖子

如何在 NestJS 中编写嵌套 DTO

我是 NestJS 的初学者,我想为以下结构编写一个 DTO -

{
    something: {
        info: {
            title: string,
            score: number,
            description: string,
            time: string,
            DateOfCreation: string
        },
        Store: {
            item: {
                question: string,
                options: {
                    item: {
                        answer: string,
                        description: string,
                        id: string,
                        key: string,
                        option: string
                    }
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想为该嵌套数据对象编写一个 DTO。我找不到在 NestJS 中编写嵌套 DTO 的可靠示例。我是 NestJS 的初学者,之前从未使用过 DTO。所以请不要假设我知道一些事情。我将它与 Mongoose 一起使用。

javascript dto typescript nestjs

17
推荐指数
1
解决办法
2万
查看次数

如何使用 getStaticProps 进行重定向?

我有一个带有简单用户身份验证的 nextjs 应用程序。这意味着我不希望注销的用户访问一些受保护的路由。该应用程序在开发版本中成功编译并按预期工作。但是当我使用时next build,我收到一条错误消息 -

Error occurred prerendering page "/createNewAdditionalInfo". Read more: https://err.sh/next.js/prerender-error

Error: 'redirect' can not be returned from getStaticProps during prerendering (/createNewAdditionalInfo)

这是代码 -

export async function getStaticProps(ctx) {
    let userObject;
    let id;
    const cookie = parseCookies(ctx);
    if (cookie.auth) {
        userObject = JSON.parse(cookie.auth);
        id = userObject.id;
    }
    if (!id) {
        return {
            redirect: {
                permanent: false,
                destination: '/',
            },
        };
    }

    return {
        props: {},
    };
}
Run Code Online (Sandbox Code Playgroud)

routes reactjs next.js

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

dto ×1

javascript ×1

nestjs ×1

next.js ×1

reactjs ×1

routes ×1

typescript ×1