diff --git a/openapi.json b/openapi.json index 43c1eac..584f982 100644 --- a/openapi.json +++ b/openapi.json @@ -1,5 +1,5 @@ { - "hash": "ce722f966bbb3c4eabd198291cd5cdc8eebf36391ba8eb0458d107822cfc8037", + "hash": "3c5196d98b6096d6dcb28beda5cf923b703ff18e399556d63feff0bbccf7038b", "openapi": "3.0.0", "paths": { "/hello": { @@ -2353,6 +2353,14 @@ "type": "string" } }, + { + "name": "key", + "required": false, + "in": "query", + "schema": { + "type": "string" + } + }, { "name": "_limit", "required": false, @@ -2518,6 +2526,14 @@ "type": "string" } }, + { + "name": "key", + "required": false, + "in": "query", + "schema": { + "type": "string" + } + }, { "name": "_limit", "required": false, @@ -6807,6 +6823,9 @@ "CreateSessionDto": { "type": "object", "properties": { + "key": { + "type": "string" + }, "expireAt": { "format": "date-time", "type": "string", @@ -7002,6 +7021,9 @@ "remark": { "type": "string", "description": "备注" + }, + "key": { + "type": "string" } } }, @@ -8428,6 +8450,9 @@ "type": "string", "description": "备注" }, + "key": { + "type": "string" + }, "_limit": { "type": "number", "description": "分页大小" diff --git a/src/session/dto/create-session.dto.ts b/src/session/dto/create-session.dto.ts index eecc3ab..2d89fd3 100644 --- a/src/session/dto/create-session.dto.ts +++ b/src/session/dto/create-session.dto.ts @@ -1,5 +1,10 @@ import { OmitType } from '@nestjs/swagger'; +import { IsOptional, IsString } from 'class-validator'; import { SessionDoc } from '../entities/session.entity'; -export class CreateSessionDto extends OmitType(SessionDoc, ['key'] as const) {} +export class CreateSessionDto extends OmitType(SessionDoc, ['key'] as const) { + @IsOptional() + @IsString() + key?: string; +} diff --git a/src/session/session.service.ts b/src/session/session.service.ts index 70451f6..501520d 100644 --- a/src/session/session.service.ts +++ b/src/session/session.service.ts @@ -16,8 +16,9 @@ export class SessionService { constructor(@InjectModel(Session.name) private readonly sessionModel: Model) {} create(createDto: CreateSessionDto): Promise { - const key = nanoid(); - const session = new this.sessionModel({ ...createDto, key }); + const { key: customKey, ...rest } = createDto; + const key = customKey ?? nanoid(); + const session = new this.sessionModel({ ...rest, key }); return session.save(); }