File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
2- "hash" : " ce722f966bbb3c4eabd198291cd5cdc8eebf36391ba8eb0458d107822cfc8037 " ,
2+ "hash" : " 3c5196d98b6096d6dcb28beda5cf923b703ff18e399556d63feff0bbccf7038b " ,
33 "openapi" : " 3.0.0" ,
44 "paths" : {
55 "/hello" : {
23532353 "type" : " string"
23542354 }
23552355 },
2356+ {
2357+ "name" : " key" ,
2358+ "required" : false ,
2359+ "in" : " query" ,
2360+ "schema" : {
2361+ "type" : " string"
2362+ }
2363+ },
23562364 {
23572365 "name" : " _limit" ,
23582366 "required" : false ,
25182526 "type" : " string"
25192527 }
25202528 },
2529+ {
2530+ "name" : " key" ,
2531+ "required" : false ,
2532+ "in" : " query" ,
2533+ "schema" : {
2534+ "type" : " string"
2535+ }
2536+ },
25212537 {
25222538 "name" : " _limit" ,
25232539 "required" : false ,
68076823 "CreateSessionDto" : {
68086824 "type" : " object" ,
68096825 "properties" : {
6826+ "key" : {
6827+ "type" : " string"
6828+ },
68106829 "expireAt" : {
68116830 "format" : " date-time" ,
68126831 "type" : " string" ,
70027021 "remark" : {
70037022 "type" : " string" ,
70047023 "description" : " 备注"
7024+ },
7025+ "key" : {
7026+ "type" : " string"
70057027 }
70067028 }
70077029 },
84288450 "type" : " string" ,
84298451 "description" : " 备注"
84308452 },
8453+ "key" : {
8454+ "type" : " string"
8455+ },
84318456 "_limit" : {
84328457 "type" : " number" ,
84338458 "description" : " 分页大小"
Original file line number Diff line number Diff line change 11import { OmitType } from '@nestjs/swagger' ;
2+ import { IsOptional , IsString } from 'class-validator' ;
23
34import { SessionDoc } from '../entities/session.entity' ;
45
5- export class CreateSessionDto extends OmitType ( SessionDoc , [ 'key' ] as const ) { }
6+ export class CreateSessionDto extends OmitType ( SessionDoc , [ 'key' ] as const ) {
7+ @IsOptional ( )
8+ @IsString ( )
9+ key ?: string ;
10+ }
Original file line number Diff line number Diff line change @@ -16,8 +16,9 @@ export class SessionService {
1616 constructor ( @InjectModel ( Session . name ) private readonly sessionModel : Model < SessionDocument > ) { }
1717
1818 create ( createDto : CreateSessionDto ) : Promise < SessionDocument > {
19- const key = nanoid ( ) ;
20- const session = new this . sessionModel ( { ...createDto , key } ) ;
19+ const { key : customKey , ...rest } = createDto ;
20+ const key = customKey ?? nanoid ( ) ;
21+ const session = new this . sessionModel ( { ...rest , key } ) ;
2122 return session . save ( ) ;
2223 }
2324
You can’t perform that action at this time.
0 commit comments