1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Dtoに直接「更新者ID」と「登録者ID」を突っ込むデコレータ

Posted at

import { GqlExecutionContext } from "@nestjs/graphql";
import { createParamDecorator, ExecutionContext } from "@nestjs/common";

export const Dto = createParamDecorator(
  (data: string, context: ExecutionContext) => {
    const ctx = GqlExecutionContext.create(context);
    const args = ctx.getArgs();
    const user = ctx.getContext().req.user;
    // TODO これでぶっ込めるけど、型もあったもんじゃないし
    // updateの時はuseridはいらねーな
    // じゃあ、updateDtoとcreateDtoをつくるか?
    // 本当は@Argsを利用したい
    args[data].createdUserId = user.userId;
    args[data].modifiedUserId = user.userId;
    return args[data];
  },
);
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?