-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathUserNormalsController.ts
98 lines (90 loc) · 3.09 KB
/
UserNormalsController.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import core from "@nestia/core";
import * as nest from "@nestjs/common";
import typia from "typia";
@nest.Controller("users")
export class UsersController {
/**
* - When namespaced DTO type comes, `@nestia/sdk` had taken a mistake that writing only the deepest type even in the top or middle level namespaced types.
* - When `clone` mode being used in SDK generator, it was not possible to clone recursive DTO type.
*/
@core.TypedException<ErrorCode.NotFound>(404)
@core.TypedRoute.Get(":user_id/oauth")
public async getOauthProfile(
@core.TypedParam("user_id") user_id: string,
@core.TypedQuery() query: IAuthentication,
): Promise<IAuthentication.IProfile> {
user_id;
query;
return typia.random<IAuthentication.IProfile>();
}
/**
* - When namespaced DTO type comes, `@nestia/sdk` had taken a mistake that writing only the deepest type even in the top or middle level namespaced types.
* - When propagation mode being used with `@TypedException<T>()` decorator, target `T` type had not been cloned.
* - When `clone` mode being used in SDK generator, it was not possible to clone recursive DTO type.
* - check optional query DTO
* - when use HttpCode decorator, sdk build fail code
*/
@nest.HttpCode(nest.HttpStatus.ACCEPTED)
@core.TypedException<ErrorCode.NotFound>(404)
@core.TypedRoute.Get(":user_id/user")
public async getUserProfile(
@core.TypedParam("user_id") user_id: string,
@core.TypedQuery() query: IUser.ISearch,
): Promise<IUser> {
user_id;
query;
return typia.random<IUser>();
}
/**
* - check optional, nullable property
*/
@core.TypedRoute.Post(":user_id/user")
public async updateUserProfile(
@core.TypedParam("user_id") user_id: string,
@core.TypedBody() body: IUser.IUpdate,
): Promise<IUser> {
user_id;
body;
return typia.random<IUser>();
}
}
interface IAuthentication {
user_id: string;
oauth_type: IAuthentication.OauthType;
}
namespace IAuthentication {
export type OauthType = "google" | "github" | "kakao";
export interface IProfile {
id: string;
name: string;
/** @format email */
email: string | null;
oauth_type: OauthType;
}
}
interface IUser {
id: string;
name: string;
email: (string & typia.tags.Format<"email">) | null;
optional_attr?: string;
undefindable_attr: string | undefined;
both_optional_and_undefindable?: string | undefined;
nullable_attr: string | null;
optional_and_nullable_attr?: number | null;
user_type: IUser.Type;
}
namespace IUser {
export type Type = "admin" | "default" | "seller";
/**
* this type name expected to 'IUpdate', but cloned dto name is 'PartialPickIUsernameemailnullable_attr'
*/
export type IUpdate = Partial<
Pick<IUser, "name" | "email" | "nullable_attr" | "optional_attr">
>;
export interface ISearch {
user_type?: Type;
}
}
namespace ErrorCode {
export type NotFound = "404 Not Found";
}